「新規プラグイン・プロジェクト」ウィザードを使用して、EGL のユーザー作成規則を実装するための Java™ パッケージとクラスを生成します。
このクラスに、カスタム規則で必要とされる分析を実行する独自の Java コードを追加する必要があります。
package com.example;
import java.util.ArrayList;
import java.util.List;
public class EglRule extends com.ibm.etools.egl.codereview.rules.AbstractEglAnalysisRule {
@Override
public List<com.ibm.etools.edt.core.ast.Node> performRule(com.ibm.etools.edt.core.ast.Node baseNode) {
final List<com.ibm.etools.edt.core.ast.Node> tokens = new ArrayList<com.ibm.etools.edt.core.ast.Node>();
// This method will always be invoked and passed the lightweight AST model instead of the bound IR model.
// Use the AST model when less information is needed than what is provided by the IR model.
// If the IR model is wanted, simply return either null or an empty tokens list for this return and
// place the code to analyze the IR model in the IR version of the performRule (see below).
// If you wish to add additional text to the flagged Node's displayed UI message, then you may use a
// List<com.ibm.etools.egl.codereview.NodeStringResult> for token instead. The NodeStringResult class allows
// you to set the Node and set the String that is appended to the flagged location in the displayed message.
baseNode.accept(new com.ibm.etools.egl.codereview.rules.AbstractASTRuleVisitor() {
@Override
public boolean visit(com.ibm.etools.edt.core.ast.AddStatement clause) {
// TODO examine node for rule violations and add violating nodes to tokens list, like this:
tokens.add(clause);
// Return true if you wish to process visits for objects within this one, otherwise return false
return false;
}
});
return tokens;
}
@Override
public List<com.ibm.etools.edt.core.ir.api.Element> performRule(com.ibm.etools.edt.core.ir.api.Element element) {
final List<com.ibm.etools.edt.core.ir.api.Element> tokens = new ArrayList<com.ibm.etools.edt.core.ir.api.Element>();
// In order for this method to be invoked, the analysisParameter "RUN_AS_IR" in the manifest must be set to "true".
// Once set, this class will be called passing the bound IR model in addition to the lightweight AST model.
// Use the IR model when more information is needed than what is provided by the AST model, but be aware
// that IR model usage is not as fast as the AST model.
// If you wish to add additional text to the flagged Element's displayed UI message, then you may use a
// List<com.ibm.etools.egl.codereview.ElementStringResult> for token instead. The ElementStringResult class allows
// you to set the Element and set the String that is appended to the flagged location in the displayed message.
element.accept(new com.ibm.etools.egl.codereview.rules.AbstractIRRuleVisitor() {
@Override
public boolean visit(com.ibm.etools.edt.core.ir.api.AddStatement clause) {
// TODO examine node for rule violations and add violating nodes to tokens list, like this:
tokens.add(clause);
// Return true if you wish to process visits for objects within this one, otherwise return false
return false;
}
});
return tokens;
}
}