[apex] Expose more information on the nodes
Like variable names, type names, apex version
This commit is contained in:
@ -16,4 +16,15 @@ public class ASTCatchBlockStatement extends AbstractApexNode<CatchBlockStatement
|
||||
public Object jjtAccept(ApexParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public String getExceptionTypeName() {
|
||||
return String.valueOf(node.getTypeRef());
|
||||
}
|
||||
|
||||
public String getVariableName() {
|
||||
if (node.getVariable() != null) {
|
||||
return node.getVariable().getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,10 @@ public class ASTField extends AbstractApexNode<Field> implements CanSuppressWarn
|
||||
|
||||
@Override
|
||||
public String getImage() {
|
||||
return node.getFieldInfo().getName();
|
||||
if (node.getFieldInfo() != null) {
|
||||
return node.getFieldInfo().getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,4 +38,8 @@ public class ASTField extends AbstractApexNode<Field> implements CanSuppressWarn
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getTypeRef() {
|
||||
return String.valueOf(node.getTypeRef());
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,16 @@ public class ASTFieldDeclaration extends AbstractApexNode<FieldDeclaration> {
|
||||
public Object jjtAccept(ApexParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImage() {
|
||||
if (node.getFieldInfo() != null) {
|
||||
return node.getFieldInfo().getName();
|
||||
}
|
||||
ASTVariableExpression variable = getFirstChildOfType(ASTVariableExpression.class);
|
||||
if (variable != null) {
|
||||
return variable.getImage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ public class ASTFormalComment extends AbstractApexNodeBase {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImage() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
@ -24,4 +24,9 @@ public class ASTLiteralExpression extends AbstractApexNode<LiteralExpression> {
|
||||
public LiteralType getLiteralType() {
|
||||
return node.getLiteralType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImage() {
|
||||
return String.valueOf(node.getLiteral());
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import apex.jorje.semantic.ast.modifier.ModifierNode;
|
||||
import apex.jorje.semantic.symbol.type.ModifierTypeInfos;
|
||||
|
||||
public class ASTModifierNode extends AbstractApexNode<ModifierNode> implements AccessNode {
|
||||
|
||||
@ -56,4 +57,36 @@ public class ASTModifierNode extends AbstractApexNode<ModifierNode> implements A
|
||||
public boolean isTransient() {
|
||||
return (node.getModifiers().getJavaModifiers() & TRANSIENT) == TRANSIENT;
|
||||
}
|
||||
|
||||
public boolean isTest() {
|
||||
return node.getModifiers().isTest();
|
||||
}
|
||||
|
||||
public boolean isTestOrTestSetup() {
|
||||
return node.getModifiers().isTestOrTestSetup();
|
||||
}
|
||||
|
||||
public boolean isWithSharing() {
|
||||
return node.getModifiers().has(ModifierTypeInfos.WITH_SHARING);
|
||||
}
|
||||
|
||||
public boolean isWithoutSharing() {
|
||||
return node.getModifiers().has(ModifierTypeInfos.WITHOUT_SHARING);
|
||||
}
|
||||
|
||||
public boolean isInheritedSharing() {
|
||||
return node.getModifiers().has(ModifierTypeInfos.INHERITED_SHARING);
|
||||
}
|
||||
|
||||
public boolean isWebService() {
|
||||
return node.getModifiers().has(ModifierTypeInfos.WEB_SERVICE);
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return node.getModifiers().has(ModifierTypeInfos.GLOBAL);
|
||||
}
|
||||
|
||||
public boolean hasOverride() {
|
||||
return node.getModifiers().has(ModifierTypeInfos.OVERRIDE);
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,11 @@ public class ASTProperty extends AbstractApexNode<Property> {
|
||||
public Object jjtAccept(ApexParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
if (node.getFieldInfo() != null) {
|
||||
return node.getFieldInfo().getType().getApexName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -30,4 +30,12 @@ public class ASTReferenceExpression extends AbstractApexNode<ReferenceExpression
|
||||
public ReferenceType getReferenceType() {
|
||||
return node.getReferenceType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImage() {
|
||||
if (node.getNames() != null && !node.getNames().isEmpty()) {
|
||||
return node.getNames().get(0).getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,8 @@ public class ASTVariableDeclaration extends AbstractApexNode<VariableDeclaration
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return String.valueOf(node.getTypeNameUsed());
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,12 @@ public class ASTVariableExpression extends AbstractApexNode<VariableExpression>
|
||||
public Object jjtAccept(ApexParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImage() {
|
||||
if (node.getIdentifier() != null) {
|
||||
return node.getIdentifier().getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -21,4 +21,8 @@ public abstract class ApexRootNode<T extends AstNode> extends AbstractApexNode<T
|
||||
this.endLine = positioner.getLastLine();
|
||||
this.endColumn = positioner.getLastLineColumn();
|
||||
}
|
||||
|
||||
public double getApexVersion() {
|
||||
return getNode().getDefiningType().getCodeUnitDetails().getVersion().getExternal();
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,6 @@ public class MethodNamingConventionsRule extends AbstractApexRule {
|
||||
|
||||
private boolean isTestMethod(ASTMethod node) {
|
||||
final ASTModifierNode modifierNode = node.getFirstChildOfType(ASTModifierNode.class);
|
||||
return modifierNode != null && modifierNode.getNode().getModifiers().isTest();
|
||||
return modifierNode != null && modifierNode.isTest();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user