IDEA-136310 (parser error on missing constructor name)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 26 Feb 2015 13:04:28 +0000 (14:04 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 26 Feb 2015 13:05:05 +0000 (14:05 +0100)
java/java-psi-impl/src/com/intellij/lang/java/parser/DeclarationParser.java
java/java-tests/testData/psi/parser-partial/declarations/MethodNameOmitted.txt [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/lang/java/parser/partial/DeclarationParserTest.java

index 9ff9da60f09c655c6871435394f1505ae4c8b472..634eda49bcdcd2159c06090af11757c2c4f87802 100644 (file)
@@ -90,6 +90,7 @@ public class DeclarationParser {
     refParser.parseReferenceList(builder, JavaTokenType.EXTENDS_KEYWORD, JavaElementType.EXTENDS_LIST, JavaTokenType.COMMA);
     refParser.parseReferenceList(builder, JavaTokenType.IMPLEMENTS_KEYWORD, JavaElementType.IMPLEMENTS_LIST, JavaTokenType.COMMA);
 
+    //noinspection Duplicates
     if (builder.getTokenType() != JavaTokenType.LBRACE) {
       final PsiBuilder.Marker error = builder.mark();
       while (BEFORE_LBRACE_ELEMENTS_SET.contains(builder.getTokenType())) {
@@ -321,7 +322,12 @@ public class DeclarationParser {
           emptyElement(builder, JavaElementType.TYPE_PARAMETER_LIST);
         }
         parseAnnotations(builder);
-        builder.advanceLexer();
+
+        if (!expect(builder, JavaTokenType.IDENTIFIER)) {
+          PsiBuilder.Marker primitive = builder.mark();
+          builder.advanceLexer();
+          primitive.error(JavaErrorMessages.message("expected.identifier"));
+        }
 
         if (builder.getTokenType() == JavaTokenType.LPARENTH) {
           return parseMethodFromLeftParenth(builder, declaration, false, true);
diff --git a/java/java-tests/testData/psi/parser-partial/declarations/MethodNameOmitted.txt b/java/java-tests/testData/psi/parser-partial/declarations/MethodNameOmitted.txt
new file mode 100644 (file)
index 0000000..b7c7def
--- /dev/null
@@ -0,0 +1,18 @@
+PsiJavaFile:MethodNameOmitted.java
+  PsiJavaToken:LBRACE('{')
+  PsiWhiteSpace(' ')
+  PsiMethod:<unnamed>
+    PsiModifierList:
+      <empty list>
+    PsiTypeParameterList
+      <empty list>
+    PsiErrorElement:Identifier expected
+      PsiKeyword:void('void')
+    PsiParameterList:()
+      PsiJavaToken:LPARENTH('(')
+      PsiJavaToken:RPARENTH(')')
+    PsiReferenceList
+      <empty list>
+    PsiJavaToken:SEMICOLON(';')
+  PsiWhiteSpace(' ')
+  PsiJavaToken:RBRACE('}')
\ No newline at end of file
index 624aea51f565a2032aec0e93e87ea8997857f35e..960417707ddaaa8a4780fb09fcaf5ae8426e4634 100644 (file)
@@ -105,6 +105,7 @@ public class DeclarationParserTest extends JavaParsingTestCase {
   public void testWildcardParsing() { doParserTest("{ List<? extends B> x(Collection<? super B> x); }"); }
   public void testParameterAnnotation() { doParserTest("{ void foo (@Annotation(value=77) int param) {} }"); }
   public void testParameterizedMethod() { doParserTest("{ @Nullable <T> T bar() {} }"); }
+  public void testMethodNameOmitted() { doParserTest("{ void(); }"); }
 
   private void doParserTest(String text) {
     doParserTest(text, false, false);