Fix new java nodes
This commit is contained in:
@ -876,7 +876,6 @@ void RecordDeclaration(int modifiers):
|
||||
{
|
||||
Token t;
|
||||
jjtThis.setModifiers(modifiers);
|
||||
checkForRecordType();
|
||||
}
|
||||
{
|
||||
t = <IDENTIFIER> {
|
||||
@ -884,7 +883,7 @@ void RecordDeclaration(int modifiers):
|
||||
throw new ParseException("ERROR: expecting record");
|
||||
}
|
||||
}
|
||||
t=<IDENTIFIER> {checkForBadTypeIdentifierUsage(t.image); jjtThis.setImage(t.image);}
|
||||
t=<IDENTIFIER> {jjtThis.setImage(t.image);}
|
||||
[ TypeParameters() ]
|
||||
RecordComponentList()
|
||||
[ ImplementsList() ]
|
||||
@ -1286,7 +1285,7 @@ void EqualityExpression() #EqualityExpression(>1):
|
||||
void InstanceOfExpression() #InstanceOfExpression(>1):
|
||||
{}
|
||||
{
|
||||
RelationalExpression() [ LOOKAHEAD(2) "instanceof" Type() [ {checkforBadInstanceOfPattern();} VariableDeclaratorId() #TypeTestPattern(2) ] ]
|
||||
RelationalExpression() [ LOOKAHEAD(2) "instanceof" Type() [ VariableDeclaratorId() #TypeTestPattern(2) ] ]
|
||||
}
|
||||
|
||||
void RelationalExpression() #RelationalExpression(>1):
|
||||
|
@ -25,12 +25,13 @@ public final class ASTRecordBody extends AbstractJavaNode {
|
||||
super(id);
|
||||
}
|
||||
|
||||
ASTRecordBody(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
}
|
||||
|
@ -27,15 +27,16 @@ public final class ASTRecordComponent extends AbstractJavaNode {
|
||||
super(id);
|
||||
}
|
||||
|
||||
ASTRecordComponent(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public boolean isVarargs() {
|
||||
return varargs;
|
||||
}
|
||||
|
@ -22,12 +22,13 @@ public final class ASTRecordComponentList extends AbstractJavaNode {
|
||||
super(id);
|
||||
}
|
||||
|
||||
ASTRecordComponentList(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ import net.sourceforge.pmd.annotation.Experimental;
|
||||
*
|
||||
* <pre class="grammar">
|
||||
*
|
||||
* RecordConstructorDeclaration ::= ({@linkplain ASTTypeAnnotation TypeAnnotation})*
|
||||
* {@linkplain ASTModifiers Modifiers}
|
||||
* RecordConstructorDeclaration ::= ({@linkplain ASTAnnotation TypeAnnotation})*
|
||||
* {@linkplain ASTModifierList Modifiers}
|
||||
* {@linkplain ASTTypeParameters TypeParameters}?
|
||||
* <IDENTIFIER>
|
||||
* ( "throws" {@linkplain ASTNameList NameList} )?
|
||||
@ -28,15 +28,16 @@ public final class ASTRecordConstructorDeclaration extends AbstractJavaAccessNod
|
||||
super(id);
|
||||
}
|
||||
|
||||
ASTRecordConstructorDeclaration(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTRecordConstructorDeclaration getDeclarationNode() {
|
||||
return this;
|
||||
|
@ -33,15 +33,16 @@ public final class ASTRecordDeclaration extends AbstractAnyTypeDeclaration {
|
||||
super(id);
|
||||
}
|
||||
|
||||
ASTRecordDeclaration(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKind getTypeKind() {
|
||||
return TypeKind.RECORD;
|
||||
|
@ -24,16 +24,16 @@ public final class ASTTypeTestPattern extends AbstractJavaNode implements ASTPat
|
||||
super(id);
|
||||
}
|
||||
|
||||
ASTTypeTestPattern(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type against which the expression is tested.
|
||||
|
@ -55,7 +55,7 @@ import net.sourceforge.pmd.lang.java.ast.SideEffectingVisitorAdapter;
|
||||
*/
|
||||
public class LanguageLevelChecker<T> {
|
||||
|
||||
private static final Pattern SPACE_ESCAPE_PATTERN = Pattern.compile("(?!\\\\)\\\\s");
|
||||
private static final Pattern SPACE_ESCAPE_PATTERN = Pattern.compile("(?<!\\\\)\\\\s");
|
||||
|
||||
private final int jdkVersion;
|
||||
private final boolean preview;
|
||||
@ -121,8 +121,7 @@ public class LanguageLevelChecker<T> {
|
||||
/** \s */
|
||||
SPACE_STRING_ESCAPES(14, 14, false),
|
||||
RECORD_DECLARATIONS(14, 14, false),
|
||||
TYPE_TEST_PATTERNS_IN_INSTANCEOF(14, 14, false),
|
||||
;
|
||||
TYPE_TEST_PATTERNS_IN_INSTANCEOF(14, 14, false);
|
||||
|
||||
|
||||
private final int minPreviewVersion;
|
||||
@ -148,7 +147,7 @@ public class LanguageLevelChecker<T> {
|
||||
|
||||
String message = StringUtils.capitalize(displayNameLower(name()));
|
||||
if (canBePreview) {
|
||||
message += " is a only a preview feature on JDK " + jdk;
|
||||
message += " is a preview feature of JDK " + jdk;
|
||||
} else if (wasStandardized) {
|
||||
message = message + " was only standardized in Java " + (maxPreviewVersion + 1);
|
||||
} else if (minPreviewVersion == maxPreviewVersion) {
|
||||
@ -166,8 +165,7 @@ public class LanguageLevelChecker<T> {
|
||||
ENUM_AS_AN_IDENTIFIER(5, "enum"),
|
||||
UNDERSCORE_AS_AN_IDENTIFIER(9, "_"),
|
||||
VAR_AS_A_TYPE_NAME(10, "var"),
|
||||
RECORD_AS_A_TYPE_NAME(14, "record") // TODO
|
||||
;
|
||||
RECORD_AS_A_TYPE_NAME(14, "record");
|
||||
|
||||
private final int maxJdkVersion;
|
||||
private final String reserved;
|
||||
@ -280,7 +278,7 @@ public class LanguageLevelChecker<T> {
|
||||
|
||||
@Override
|
||||
public void visit(ASTYieldStatement node, T data) {
|
||||
check(node, PreviewFeature.RECORD_DECLARATIONS, data);
|
||||
check(node, PreviewFeature.YIELD_STATEMENTS, data);
|
||||
visitChildren(node, data);
|
||||
}
|
||||
|
||||
|
@ -292,11 +292,4 @@ public class UselessOverridingMethodRule extends AbstractJavaRule {
|
||||
|| elevatingIntoDifferentPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated this method will be removed. Just use {@link Node#findChildrenOfType(Class)} directly.
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> List<T> findFirstDegreeChaildrenOfType(Node n, Class<T> targetType) {
|
||||
return n.findChildrenOfType(targetType);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.sourceforge.pmd.lang.java.ast
|
||||
|
||||
import io.kotlintest.matchers.string.shouldContain
|
||||
import net.sourceforge.pmd.lang.ast.test.shouldBe
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaVersion.J14__PREVIEW
|
||||
import java.io.IOException
|
||||
@ -8,8 +9,10 @@ class ASTPatternTest : ParserTestSpec({
|
||||
|
||||
parserTest("Test patterns only available on JDK 14 (preview)", javaVersions = !J14__PREVIEW) {
|
||||
|
||||
expectParseException("Cannot use type test patterns in instanceof when running in JDK other than 14-preview") {
|
||||
parseAstExpression("obj instanceof Class c")
|
||||
inContext(ExpressionParsingCtx) {
|
||||
"obj instanceof Class c" should throwParseException {
|
||||
it.message.shouldContain("Type test patterns in instanceof is a preview feature of JDK 14, you should select your language version accordingly")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,9 +8,7 @@ import io.kotlintest.matchers.string.shouldContain
|
||||
import io.kotlintest.shouldThrow
|
||||
import net.sourceforge.pmd.lang.ast.Node
|
||||
import net.sourceforge.pmd.lang.ast.ParseException
|
||||
import net.sourceforge.pmd.lang.ast.test.Assertions
|
||||
import net.sourceforge.pmd.lang.ast.test.NodeSpec
|
||||
import net.sourceforge.pmd.lang.ast.test.matchNode
|
||||
import net.sourceforge.pmd.lang.ast.test.*
|
||||
import net.sourceforge.pmd.lang.ast.test.shouldMatchNode
|
||||
import net.sourceforge.pmd.lang.java.JavaParsingHelper
|
||||
import java.beans.PropertyDescriptor
|
||||
|
Reference in New Issue
Block a user