diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 22f42a123588..9b5485bebe15 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -736,6 +736,7 @@ public class GroovyAnnotator extends GroovyElementVisitor { private static void checkOptionalParametersInAbstractMethod(AnnotationHolder holder, GrMethod method) { if (!method.hasModifierProperty(PsiModifier.ABSTRACT)) return; + if (!(method.getContainingClass() instanceof GrInterfaceDefinition)) return; for (GrParameter parameter : method.getParameters()) { GrExpression initializerGroovy = parameter.getInitializerGroovy(); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy23HighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy23HighlightingTest.groovy index 3df6895053eb..2036e6b13e6e 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy23HighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy23HighlightingTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -82,5 +82,14 @@ def foo() { ''') } + void 'test default parameter in trait methods'() { + testHighlighting '''\ +trait T { + abstract foo(x = 3); + def bar(y = 6) {} +} +''' + } + final InspectionProfileEntry[] customInspections = [new GroovyAssignabilityCheckInspection(), new GrUnresolvedAccessInspection()] } diff --git a/plugins/groovy/testdata/highlighting/DefaultInitializersAreNotAllowedInAbstractMethods.groovy b/plugins/groovy/testdata/highlighting/DefaultInitializersAreNotAllowedInAbstractMethods.groovy index e8b6882001d7..0e7b0aafede6 100644 --- a/plugins/groovy/testdata/highlighting/DefaultInitializersAreNotAllowedInAbstractMethods.groovy +++ b/plugins/groovy/testdata/highlighting/DefaultInitializersAreNotAllowedInAbstractMethods.groovy @@ -3,7 +3,35 @@ interface I { } abstract class A { - abstract foo(int x = 5) + abstract foo(int x = 5) def abr(int x = 5){} } + +enum E { + ONE { + def foo(x) {} + }; + + abstract foo(x = 3) + def bar(y = 12) {} +} + +@interface An { + int foo() + String bar(x = 2) +} + +def a = new Runnable() { + void run() {} + abstract foo(x = 5); +} + +enum EE { + T { + def foo() {} + abstract bar(x = 4); + }; + + def foo() {} +} \ No newline at end of file