mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Parse Java type annotations regardless to language level
This commit is contained in:
@@ -69,36 +69,34 @@ PsiJavaFile:Errors4.java
|
||||
<empty list>
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiDeclarationStatement
|
||||
PsiErrorElement:Identifier expected
|
||||
<empty list>
|
||||
PsiJavaToken:AT('@')
|
||||
PsiDeclarationStatement
|
||||
PsiLocalVariable:List
|
||||
PsiModifierList:
|
||||
<empty list>
|
||||
PsiTypeElement:Deprecated
|
||||
PsiTypeElement:@Deprecated List<Object>
|
||||
PsiAnnotation
|
||||
PsiJavaToken:AT('@')
|
||||
PsiJavaCodeReferenceElement:Deprecated
|
||||
PsiIdentifier:Deprecated('Deprecated')
|
||||
PsiReferenceParameterList
|
||||
<empty list>
|
||||
PsiAnnotationParameterList
|
||||
<empty list>
|
||||
PsiWhiteSpace(' ')
|
||||
PsiIdentifier:List('List')
|
||||
PsiErrorElement:';' expected
|
||||
<empty list>
|
||||
PsiErrorElement:Unexpected token
|
||||
PsiJavaToken:LT('<')
|
||||
PsiExpressionStatement
|
||||
PsiBinaryExpression:Object>()
|
||||
PsiReferenceExpression:Object
|
||||
PsiJavaCodeReferenceElement:List<Object>
|
||||
PsiIdentifier:List('List')
|
||||
PsiReferenceParameterList
|
||||
<empty list>
|
||||
PsiIdentifier:Object('Object')
|
||||
PsiJavaToken:GT('>')
|
||||
PsiParenthesizedExpression:()
|
||||
PsiJavaToken:LPARENTH('(')
|
||||
PsiErrorElement:Expression expected
|
||||
<empty list>
|
||||
PsiJavaToken:RPARENTH(')')
|
||||
PsiJavaToken:LT('<')
|
||||
PsiTypeElement:Object
|
||||
PsiJavaCodeReferenceElement:Object
|
||||
PsiIdentifier:Object('Object')
|
||||
PsiReferenceParameterList
|
||||
<empty list>
|
||||
PsiJavaToken:GT('>')
|
||||
PsiErrorElement:Identifier expected
|
||||
<empty list>
|
||||
PsiExpressionStatement
|
||||
PsiParenthesizedExpression:()
|
||||
PsiJavaToken:LPARENTH('(')
|
||||
PsiErrorElement:Expression expected
|
||||
<empty list>
|
||||
PsiJavaToken:RPARENTH(')')
|
||||
PsiJavaToken:SEMICOLON(';')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiJavaToken:RBRACE('}')
|
||||
|
||||
+32
-23
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -9,30 +24,24 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
@NonNls
|
||||
private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/annotations";
|
||||
|
||||
private void doTest(boolean checkWarnings) throws Exception {
|
||||
private void doTest(boolean checkWarnings) {
|
||||
doTest(BASE_PATH + "/" + getTestName(true) + ".java", checkWarnings, false);
|
||||
}
|
||||
|
||||
public void testNotValueNameOmitted() throws Exception { doTest(false); }
|
||||
public void testCannotFindMethod() throws Exception { doTest(false); }
|
||||
public void testIncompatibleType1() throws Exception { doTest(false); }
|
||||
public void testIncompatibleType2() throws Exception { doTest(false); }
|
||||
public void testIncompatibleType3() throws Exception { doTest(false); }
|
||||
public void testIncompatibleType4() throws Exception { doTest(false); }
|
||||
public void testMissingAttribute() throws Exception { doTest(false); }
|
||||
public void testDuplicateAnnotation() throws Exception { doTest(false); }
|
||||
public void testNonConstantInitializer() throws Exception { doTest(false); }
|
||||
public void testInvalidType() throws Exception { doTest(false); }
|
||||
public void testInapplicable() throws Exception { doTest(false); }
|
||||
public void testDuplicateAttribute() throws Exception { doTest(false); }
|
||||
public void testDuplicateTarget() throws Exception { doTest(false); }
|
||||
public void testTypeAnnotations() throws Exception { doTest(false); }
|
||||
|
||||
public void testInvalidPackageAnnotationTarget() throws Exception {
|
||||
doTest(BASE_PATH + "/" + getTestName(true) + "/package-info.java", false, false);
|
||||
}
|
||||
|
||||
public void testPackageAnnotationNotInPackageInfo() throws Exception {
|
||||
doTest(BASE_PATH + "/" + getTestName(true) + "/notPackageInfo.java", false, false);
|
||||
}
|
||||
public void testNotValueNameOmitted() { doTest(false); }
|
||||
public void testCannotFindMethod() { doTest(false); }
|
||||
public void testIncompatibleType1() { doTest(false); }
|
||||
public void testIncompatibleType2() { doTest(false); }
|
||||
public void testIncompatibleType3() { doTest(false); }
|
||||
public void testIncompatibleType4() { doTest(false); }
|
||||
public void testMissingAttribute() { doTest(false); }
|
||||
public void testDuplicateAnnotation() { doTest(false); }
|
||||
public void testNonConstantInitializer() { doTest(false); }
|
||||
public void testInvalidType() { doTest(false); }
|
||||
public void testInapplicable() { doTest(false); }
|
||||
public void testDuplicateAttribute() { doTest(false); }
|
||||
public void testDuplicateTarget() { doTest(false); }
|
||||
public void testTypeAnnotations() { doTest(false); }
|
||||
public void testInvalidPackageAnnotationTarget() { doTest(BASE_PATH + "/" + getTestName(true) + "/package-info.java", false, false); }
|
||||
public void testPackageAnnotationNotInPackageInfo() { doTest(BASE_PATH + "/" + getTestName(true) + "/notPackageInfo.java", false, false); }
|
||||
}
|
||||
|
||||
@@ -49,17 +49,6 @@ public abstract class JavaParsingTestCase extends ParsingTestCase {
|
||||
IdeaTestCase.initPlatformPrefix();
|
||||
}
|
||||
|
||||
protected void withLevel(final LanguageLevel level, final Runnable r) {
|
||||
LanguageLevel prev = myLanguageLevel;
|
||||
myLanguageLevel = level;
|
||||
try {
|
||||
r.run();
|
||||
}
|
||||
finally {
|
||||
myLanguageLevel = prev;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
+9
-13
@@ -16,7 +16,6 @@
|
||||
package com.intellij.lang.java.parser.annotationParsing;
|
||||
|
||||
import com.intellij.lang.java.parser.JavaParsingTestCase;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor;
|
||||
|
||||
@@ -40,19 +39,16 @@ public class AnnotationParsingTest extends JavaParsingTestCase {
|
||||
public void testParameterizedMethod () { doTest(true); }
|
||||
public void testQualifiedAnnotation() { doTest(true); }
|
||||
public void testEnumSmartTypeCompletion() { doTest(true); }
|
||||
public void testErrors() { doTest(true); }
|
||||
|
||||
public void testTypeAnno() {
|
||||
withLevel(LanguageLevel.JDK_1_8, new Runnable() { @Override public void run() {
|
||||
doTest(true);
|
||||
myFile.accept(new PsiRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitErrorElement(PsiErrorElement element) {
|
||||
fail(element.getErrorDescription());
|
||||
super.visitErrorElement(element);
|
||||
}
|
||||
});
|
||||
}});
|
||||
doTest(true);
|
||||
myFile.accept(new PsiRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitErrorElement(PsiErrorElement element) {
|
||||
fail(element.getErrorDescription());
|
||||
super.visitErrorElement(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testErrors() { doTest(true); }
|
||||
}
|
||||
|
||||
+8
-11
@@ -18,7 +18,6 @@ package com.intellij.lang.java.parser.partial;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.java.parser.JavaParser;
|
||||
import com.intellij.lang.java.parser.JavaParsingTestCase;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
|
||||
public class DeclarationParserTest extends JavaParsingTestCase {
|
||||
public DeclarationParserTest() {
|
||||
@@ -40,16 +39,14 @@ public class DeclarationParserTest extends JavaParsingTestCase {
|
||||
" @Preliminary(a=A.B\n#) public class TimeTravel {}\n" +
|
||||
" @Preliminary(a=A.B\n#, b=c) public class TimeTravel {} }", false, false); }
|
||||
public void testTypeAnno() {
|
||||
withLevel(LanguageLevel.JDK_1_8, new Runnable() { @Override public void run() {
|
||||
doParserTest("{ class C<@D T extends @F Object> extends @F Object {\n" +
|
||||
" @F int @F[] method() @F throws @F Exception {\n" +
|
||||
" a = this instanceof @F C;\n" +
|
||||
" C<@F @G C> c = new @Q C<@F C>();\n" +
|
||||
" c = (@F Object)c;\n" +
|
||||
" Class c = @TA String.class;\n" +
|
||||
" @F C.field++;\n" +
|
||||
" }\n} }", false, false);
|
||||
}});
|
||||
doParserTest("{ class C<@D T extends @F Object> extends @F Object {\n" +
|
||||
" @F int @F[] method() @F throws @F Exception {\n" +
|
||||
" a = this instanceof @F C;\n" +
|
||||
" C<@F @G C> c = new @Q C<@F C>();\n" +
|
||||
" c = (@F Object)c;\n" +
|
||||
" Class c = @TA String.class;\n" +
|
||||
" @F C.field++;\n" +
|
||||
" }\n} }", false, false);
|
||||
}
|
||||
|
||||
public void testEnumBody0() { doParserTest("{ ; }", false, true); }
|
||||
|
||||
+2
-7
@@ -19,7 +19,6 @@ import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.java.parser.JavaParser;
|
||||
import com.intellij.lang.java.parser.JavaParsingTestCase;
|
||||
import com.intellij.lang.java.parser.ReferenceParser;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
|
||||
|
||||
public class ReferenceParserTest extends JavaParsingTestCase {
|
||||
@@ -37,11 +36,7 @@ public class ReferenceParserTest extends JavaParsingTestCase {
|
||||
public void testType3() { doTypeParserTest("int[]["); }
|
||||
public void testType4() { doTypeParserTest("Map<String,List<String>>"); }
|
||||
public void testType5() { doTypeParserTest("Object[]..."); }
|
||||
public void testType6() {
|
||||
withLevel(LanguageLevel.JDK_1_8, new Runnable() { @Override public void run() {
|
||||
doTypeParserTest("@English String @NonEmpty []");
|
||||
}});
|
||||
}
|
||||
public void testType6() { doTypeParserTest("@English String @NonEmpty []"); }
|
||||
public void testType7() { doTypeParserTest("Diamond<>"); }
|
||||
public void testType8() { doTypeParserTest("A|"); }
|
||||
public void testType9() { doTypeParserTest("A|B"); }
|
||||
@@ -68,7 +63,7 @@ public class ReferenceParserTest extends JavaParsingTestCase {
|
||||
|
||||
@Override
|
||||
public void parse(final PsiBuilder builder) {
|
||||
JavaParser.INSTANCE.getReferenceParser().parseJavaCodeReference(builder, myIncomplete, false, false, false, false);
|
||||
JavaParser.INSTANCE.getReferenceParser().parseJavaCodeReference(builder, myIncomplete, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user