Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apex] Summit-AST Apex module - Part 6 Passing testsuite #4251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
90aec7a
Fix b/243743042
eklimo Aug 25, 2022
9e5d4d4
Fix b/243747010
eklimo Aug 21, 2022
c6ad8fb
Allow rules with version checks to properly run
eklimo Aug 21, 2022
da9e1ef
Update `TODO` comments
eklimo Aug 26, 2022
1f438e6
Fix b/243977405
eklimo Aug 24, 2022
4fbe0de
Upgrade Summit to 1.1.0 (snapshot).
aaronhurst-google Nov 13, 2022
157558c
Add back ApexTreeBuilder.java.
aaronhurst-google Nov 16, 2022
fb32ba3
Translate `EnumValue` node to `ASTField`.
aaronhurst-google Nov 16, 2022
611d788
Rename former ApexTreeBuilder.java to ApexCommentBuilder.java.
aaronhurst-google Nov 17, 2022
581d4d6
Comments!
aaronhurst-google Nov 17, 2022
701fb53
Comment position fixup
aaronhurst-google Nov 23, 2022
ff9de70
Replicate previous behavior for type names:
aaronhurst-google Nov 28, 2022
914f6a8
Fix test failures related to Boolean cognitive complexity due to (unn…
aaronhurst-google Nov 29, 2022
ecad878
Fix test failure due to incorrect case-sensitive identifier comparison.
aaronhurst-google Nov 29, 2022
0524d66
Update TreeDumper regression test with Summit AST output.
aaronhurst-google Nov 29, 2022
072bb72
Update test to use getOp replacement for deprecated and now retired g…
aaronhurst-google Nov 29, 2022
6897164
Upgrade Summit AST dependency to release version 2.0.0.
aaronhurst-google Nov 29, 2022
19225dc
Update test with Jorje vs. Summit source location and node count diff…
aaronhurst-google Nov 29, 2022
d57d482
Remove pmd-visualforce Jorje dependency.
aaronhurst-google Dec 1, 2022
62080c6
Refactor ASTMethod to support synthetic definitions, and add a synthe…
aaronhurst-google Dec 1, 2022
9fef04f
ASTField: store String type name instead of either typeRef or enumVal…
aaronhurst-google Dec 2, 2022
8734d45
Fix PMD dogfood issues.
aaronhurst-google Dec 1, 2022
16a492f
Fix checkstyle violations.
aaronhurst-google Dec 2, 2022
e9eafdd
Change case normalization of primitive from 'ID' to 'Id' to match exi…
aaronhurst-google Dec 2, 2022
6d35496
Property getter and setter methods default to visibility of property.
aaronhurst-google Dec 2, 2022
1a5c571
Update tested return type name to match Summit, which returns the syn…
aaronhurst-google Dec 2, 2022
626aec5
Move guava to a non-test dependency, due to implicit dependencies tha…
aaronhurst-google Dec 2, 2022
8745d00
Update pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTLi…
aaronhurst-google Jan 3, 2023
60da7bd
Reduce visibility of ApexCommentBuilder. Remove @Deprecated for new c…
aaronhurst-google Jan 3, 2023
656dff9
Remove development Maven repository.
aaronhurst-google Jan 5, 2023
b4b9dd2
Remove ApexRootNode.getApexVersion.
aaronhurst-google Jan 6, 2023
58ca81d
Updated test after removing getApexVersion.
aaronhurst-google Jan 6, 2023
ebb861a
Sort children of ASTUserClass to order ASTField nodes earlier, immedi…
aaronhurst-google Jan 6, 2023
b8ccafa
Fix checkstyle issue.
aaronhurst-google Jan 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pmd-apex/pom.xml
Expand Up @@ -120,7 +120,7 @@
<dependency>
<groupId>com.google.summit</groupId>
<artifactId>summit-ast</artifactId>
<version>1.0.0</version>
<version>2.0.0</version>
</dependency>

<dependency>
Expand Down
Expand Up @@ -4,13 +4,15 @@

package net.sourceforge.pmd.lang.apex;

/*
import java.util.logging.Level;
import java.util.logging.Logger;
*/

// TODO(b/243903752)
public final class ApexJorjeLogging {
// note: that's a static/strong reference in order to avoid that the logger is garbage collected
// private static final Logger APEX_LOGGER = Logger.getLogger(BaseApexLexer.class.getName());
// TODO(b/239648780)

private ApexJorjeLogging() {
// this is a utility class
Expand All @@ -22,6 +24,5 @@ public static void disableLogging() {
// INFORMATION: Deduped array ApexLexer.DFA23_transition. Found 7927114 shorts which is 15MB not
// including array overhead. Removed 7204963 shorts which is 13MB not counting array overhead. Took 18ms.
// APEX_LOGGER.setLevel(Level.WARNING);
// TODO(b/239648780)
}
}
Expand Up @@ -18,7 +18,7 @@ public class ApexLanguageModule extends BaseLanguageModule {
public ApexLanguageModule() {
super(NAME, null, TERSE_NAME, FIRST_EXTENSION, REMAINING_EXTENSIONS);
// addVersion(String.valueOf((int) Version.CURRENT.getExternal()), new ApexHandler(), true);
// TODO(b/239648780)
// TODO(b/243906862)
addVersion("0", new ApexHandler(), true);
}
}
Expand Up @@ -4,15 +4,11 @@

package net.sourceforge.pmd.lang.apex.ast;

import net.sourceforge.pmd.annotation.InternalApi;
import com.google.summit.ast.expression.SoqlOrSoslBinding;

import com.google.summit.ast.Node;
public class ASTBindExpressions extends AbstractApexNode.Single<SoqlOrSoslBinding> {

public class ASTBindExpressions extends AbstractApexNode.Single<Node> {

@Deprecated
@InternalApi
public ASTBindExpressions(Node bindExpressions) {
ASTBindExpressions(SoqlOrSoslBinding bindExpressions) {
super(bindExpressions);
}

Expand Down
Expand Up @@ -18,11 +18,11 @@ public Object jjtAccept(ApexParserVisitor visitor, Object data) {
}

public String getExceptionType() {
return node.getExceptionVariable().getType().asCodeString();
return node.getException().getType().asCodeString();
}

public String getVariableName() {
return node.getExceptionVariable().getId().getString();
return node.getException().getDeclarations().get(0).getId().getString();
}

public ASTBlockStatement getBody() {
Expand Down
Expand Up @@ -12,22 +12,30 @@
import com.google.summit.ast.Identifier;
import com.google.summit.ast.Node;
import com.google.summit.ast.TypeRef;
import com.google.summit.ast.declaration.EnumDeclaration;
import com.google.summit.ast.expression.Expression;
import com.google.summit.ast.expression.LiteralExpression;

public class ASTField extends AbstractApexNode.Many<Node> implements CanSuppressWarnings {

private final TypeRef type;
private final Identifier name;
private final Optional<Expression> value;
private final String typeName;

ASTField(TypeRef type, Identifier name, Optional<Expression> value) {
ASTField(TypeRef typeRef, Identifier name, Optional<Expression> value) {
super(value.isPresent()
? Arrays.asList(type, name, value.get())
: Arrays.asList(type, name));
this.type = type;
? Arrays.asList(typeRef, name, value.get())
: Arrays.asList(typeRef, name));
this.name = name;
this.value = value;
this.typeName = caseNormalizedTypeIfPrimitive(typeRef.asCodeString());
}

ASTField(EnumDeclaration enumType, Identifier name) {
super(Arrays.asList(name));
this.name = name;
this.value = Optional.empty();
this.typeName = enumType.getId().asCodeString();
}

@Override
Expand All @@ -52,8 +60,14 @@ public boolean hasSuppressWarningsAnnotationFor(Rule rule) {
return false;
}

/**
* Returns the type name.
*
* This includes any type arguments. (This is tested.)
* If the type is a primitive, its case will be normalized.
*/
public String getType() {
return type.asCodeString();
return typeName;
}

public ASTModifierNode getModifiers() {
Expand Down
Expand Up @@ -40,8 +40,14 @@ public ASTModifierNode getModifiers() {
return getFirstChildOfType(ASTModifierNode.class);
}

/**
* Returns the type name.
*
* This includes any type arguments.
* If the type is a primitive, its case will be normalized.
*/
public String getTypeName() {
return node.getType().asCodeString();
return caseNormalizedTypeIfPrimitive(node.getType().asCodeString());
}

/*
Expand All @@ -52,9 +58,9 @@ private static String identifiersToString(List<Identifier> identifiers) {
// TODO(b/239648780)

public List<String> getTypeArguments() {
/*
List<String> result = new ArrayList<>();

/*
if (node.getTypeName() != null) {
List<TypeRef> typeArgs = node.getTypeName().getTypeArguments();
for (TypeRef arg : typeArgs) {
Expand All @@ -71,6 +77,6 @@ public List<String> getTypeArguments() {
*/
// TODO(b/239648780)

return result;
return new ArrayList<>();
}
}
Expand Up @@ -4,28 +4,16 @@

package net.sourceforge.pmd.lang.apex.ast;

import org.antlr.runtime.Token;
import org.antlr.v4.runtime.Token;

import com.google.summit.ast.Node;
import net.sourceforge.pmd.lang.ast.SourceCodePositioner;

public class ASTFormalComment extends AbstractApexNode.Empty {

public class ASTFormalComment extends AbstractApexNode.Single<Node> {

private final String image;
private final Token token;

ASTFormalComment(Token token) {
// super(new AstComment(token));
// TODO(b/239648780)
super(null);
this.image = token.getText();
}

@Deprecated
public ASTFormalComment(String token) {
// super(new AstComment(null));
// TODO(b/239648780)
super(null);
image = token;
this.token = token;
}

@Override
Expand All @@ -35,51 +23,29 @@ public Object jjtAccept(ApexParserVisitor visitor, Object data) {

@Override
public String getImage() {
return image;
return token.getText();
}

public String getToken() {
return image;
return token.getText();
}

/*
@Deprecated
@InternalApi
public static final class AstComment implements AstNode {

private final Location loc;

private AstComment(Token token) {
this.loc = token == null
? Locations.NONE
: Locations.loc(token.getLine(), token.getCharPositionInLine() + 1);
}

@Override
public Location getLoc() {
return loc;
}

@Override
public <T extends Scope> void traverse(AstVisitor<T> astVisitor, T t) {
// do nothing
}

@Override
public void validate(SymbolResolver symbolResolver, ValidationScope validationScope) {
// do nothing
}
@Override
void calculateLineNumbers(SourceCodePositioner positioner) {
this.beginLine = positioner.lineNumberFromOffset(token.getStartIndex());
this.beginColumn = positioner.columnFromOffset(this.beginLine, token.getStartIndex());
this.endLine = positioner.lineNumberFromOffset(token.getStopIndex());
this.endColumn = positioner.columnFromOffset(this.endLine, token.getStopIndex());
}

@Override
public void emit(Emitter emitter) {
// do nothing
}
@Override
public boolean hasRealLoc() {
return true;
}

@Override
public TypeInfo getDefiningType() {
return TypeInfos.VOID;
}
@Override
public String getLocation() {
return String.format("[%d:%d,%d:%d]", this.beginLine, this.beginColumn,
this.endLine, this.endColumn);
}
*/
// TODO(b/239648780)
}
Expand Up @@ -41,8 +41,10 @@ public LiteralType getLiteralType() {
return LiteralType.DOUBLE;
} else if (node instanceof LiteralExpression.LongVal) {
return LiteralType.LONG;
} else if (false) { // TODO(b/239648780)
/* TODO(b/239648780): the parser must distinguish decimal vs. double
} else if (node instanceof LiteralExpression.DecimalVal) {
return LiteralType.DECIMAL;
*/
} else if (node instanceof LiteralExpression.NullVal) {
return LiteralType.NULL;
} else {
Expand Down
Expand Up @@ -23,4 +23,9 @@ public class ASTMapEntryNode extends AbstractApexNode.Many<Expression> {
public Object jjtAccept(ApexParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}

@Override
public String getImage() {
return String.format("%s: %s", key, value);
}
}