diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/parameters/ParameterDeclaration.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/parameters/ParameterDeclaration.java index 8ffd2bb8dd7b..2d4e4d4f29aa 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/parameters/ParameterDeclaration.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/auxiliary/parameters/ParameterDeclaration.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -32,6 +32,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier; import java.util.HashSet; import java.util.Set; +import static org.jetbrains.plugins.groovy.lang.parser.parsing.statements.typeDefinitions.ReferenceElement.ReferenceElementResult.*; + /** * @author: Dmitry.Krasilschikov, ilyas */ @@ -47,7 +49,7 @@ public class ParameterDeclaration implements GroovyElementTypes { final ReferenceElement.ReferenceElementResult result = TypeSpec.parseStrict(builder, true); - if (result == ReferenceElement.ReferenceElementResult.FAIL && !hasModifiers) { + if (result == FAIL && !hasModifiers) { rb.drop(); pdMarker.rollbackTo(); return false; @@ -90,9 +92,10 @@ public class ParameterDeclaration implements GroovyElementTypes { if (mIDENT.equals(builder.getTokenType()) || (mTRIPLE_DOT.equals(builder.getTokenType()))) { rb.drop(); } - else if (result == ReferenceElement.ReferenceElementResult.REF_WITH_TYPE_PARAMS) { + else if (result == REF_WITH_TYPE_PARAMS || result == PATH_REF) { rb.drop(); - pdMarker.error(GroovyBundle.message("identifier.expected")); + pdMarker.drop(); + builder.error(GroovyBundle.message("identifier.expected")); return true; } else { @@ -135,7 +138,7 @@ public class ParameterDeclaration implements GroovyElementTypes { rb.drop(); rb = builder.mark(); final ReferenceElement.ReferenceElementResult result = TypeSpec.parseStrict(builder, false); - if (result == ReferenceElement.ReferenceElementResult.FAIL && ParserUtils.lookAhead(builder, mBOR)) { + if (result == FAIL && ParserUtils.lookAhead(builder, mBOR)) { builder.error(GroovyBundle.message("type.expected")); } else { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/ReferenceElement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/ReferenceElement.java index 8cea8ecee7fa..3d13f1efd241 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/ReferenceElement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/ReferenceElement.java @@ -91,7 +91,7 @@ public class ReferenceElement implements GroovyElementTypes { } public enum ReferenceElementResult { - IDENTIFIER, PATH_REF, REF_WITH_TYPE_PARAMS, PATH_REF_WITHOUT_NAME_ELEMENT, FAIL + IDENTIFIER, PATH_REF, REF_WITH_TYPE_PARAMS, FAIL } public static ReferenceElementResult parseForImport(@NotNull PsiBuilder builder) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyAutoPopupTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyAutoPopupTest.groovy index 151a779867be..8838e9df50c8 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyAutoPopupTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyAutoPopupTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -139,14 +139,18 @@ class GroovyAutoPopupTest extends CompletionAutoPopupTestCase { myFixture.addClass("class Foo { static class Bar {} }") myFixture.configureByText "a.groovy", "void foo(Foo[] a) { }" type '.' - assert !lookup + assert lookup + type '.' + myFixture.checkResult('void foo(Foo..[] a) { }') } public void testTypingFirstVarargDot2() { myFixture.addClass("class Foo { static class Bar {} }") myFixture.configureByText "a.groovy", "void foo(Foo) { }" type '.' - assert !lookup + assert lookup + type '.' + myFixture.checkResult('void foo(Foo..) { }') } public void testDotDot() { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/TypesParsingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/TypesParsingTest.groovy index a4fc8ad3eff9..ed407b408ba5 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/TypesParsingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/TypesParsingTest.groovy @@ -51,5 +51,9 @@ public class TypesParsingTest extends GroovyParsingTestCase { public void testStaticInitializer() throws Throwable { doTest(); } public void testInterfaceWithGroovyDoc() throws Throwable { doTest(); } + public void testIncorrectParam1() { doTest() } + public void testIncorrectParam2() { doTest() } + public void testIncorrectParam3() { doTest() } + public void testEmptyTypeArgs() {doTest()} } \ No newline at end of file diff --git a/plugins/groovy/testdata/parsing/groovy/types/IncorrectParam2.test b/plugins/groovy/testdata/parsing/groovy/types/IncorrectParam2.test new file mode 100644 index 000000000000..24942afc9944 --- /dev/null +++ b/plugins/groovy/testdata/parsing/groovy/types/IncorrectParam2.test @@ -0,0 +1,38 @@ +def foo(A a, A. b) {} +----- +Groovy script + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + Parameter + Modifiers + + Type element + Reference element + PsiElement(identifier)('A') + PsiWhiteSpace(' ') + PsiElement(identifier)('a') + PsiElement(,)(',') + PsiWhiteSpace(' ') + Modifiers + + Type element + Reference element + Reference element + PsiElement(identifier)('A') + PsiElement(.)('.') + PsiWhiteSpace(' ') + PsiElement(identifier)('b') + PsiErrorElement:Identifier expected + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiElement(})('}') \ No newline at end of file diff --git a/plugins/groovy/testdata/parsing/groovy/types/incorrectParam1.test b/plugins/groovy/testdata/parsing/groovy/types/incorrectParam1.test new file mode 100644 index 000000000000..63fcebc4ed73 --- /dev/null +++ b/plugins/groovy/testdata/parsing/groovy/types/incorrectParam1.test @@ -0,0 +1,28 @@ +def foo(A. B) {} +----- +Groovy script + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + Modifiers + + Type element + Reference element + Reference element + PsiElement(identifier)('A') + PsiElement(.)('.') + PsiWhiteSpace(' ') + PsiElement(identifier)('B') + PsiErrorElement:Identifier expected + + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiElement(})('}') \ No newline at end of file diff --git a/plugins/groovy/testdata/parsing/groovy/types/incorrectParam3.test b/plugins/groovy/testdata/parsing/groovy/types/incorrectParam3.test new file mode 100644 index 000000000000..42a8ed09d08a --- /dev/null +++ b/plugins/groovy/testdata/parsing/groovy/types/incorrectParam3.test @@ -0,0 +1,38 @@ +def foo(A. b, A c) {} +----- +Groovy script + Method + Modifiers + PsiElement(def)('def') + PsiWhiteSpace(' ') + PsiElement(identifier)('foo') + PsiElement(()('(') + Parameter list + Modifiers + + Type element + Reference element + Reference element + PsiElement(identifier)('A') + PsiElement(.)('.') + PsiWhiteSpace(' ') + PsiElement(identifier)('b') + PsiErrorElement:Identifier expected + + PsiElement(,)(',') + PsiWhiteSpace(' ') + Parameter + Modifiers + + Type element + Reference element + PsiElement(identifier)('A') + PsiWhiteSpace(' ') + PsiElement(identifier)('c') + PsiElement())(')') + PsiWhiteSpace(' ') + Throw clause + + Open block + PsiElement({)('{') + PsiElement(})('}') \ No newline at end of file