diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java index abff53174f68..7a5d11ca2ffd 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiAnnotationMethodImpl.java @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.source; -import com.intellij.ide.highlighter.JavaFileType; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -62,10 +61,7 @@ public class PsiAnnotationMethodImpl extends PsiMethodImpl implements PsiAnnotat return value; } - @NonNls final String annoText = "@interface _Dummy_ { " + getReturnType() + " " + getName() + "() default " + text + "; }"; - final PsiFileFactory factory = PsiFileFactory.getInstance(getProject()); - final PsiJavaFile file = (PsiJavaFile)factory.createFileFromText("a.java", JavaFileType.INSTANCE, annoText); - value = ((PsiAnnotationMethod)file.getClasses()[0].getMethods()[0]).getDefaultValue(); + value = JavaPsiFacade.getElementFactory(getProject()).createAnnotationFromText("@Foo(" + text + ")", this).findAttributeValue(null); myCachedDefaultValue = new SoftReference(value); return value; } diff --git a/java/java-tests/testSrc/com/intellij/psi/JavaStubsTest.groovy b/java/java-tests/testSrc/com/intellij/psi/JavaStubsTest.groovy new file mode 100644 index 000000000000..67b49be08603 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/psi/JavaStubsTest.groovy @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2015 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.psi + +import com.intellij.psi.impl.source.PsiFileImpl +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase + +class JavaStubsTest extends LightCodeInsightFixtureTestCase { + + public void "test resolve from annotation method defaule"() { + def cls = myFixture.addClass(""" +public @interface BrokenAnnotation { + + public enum Foo { + DEFAULT, + OTHER + } + + Foo value() default Foo.DEFAULT; +} +""") + + def file = cls.containingFile as PsiFileImpl + assert file.stub + + def ref = (cls.methods[0] as PsiAnnotationMethod).defaultValue + assert file.stub + + assert ref instanceof PsiReferenceExpression + assert ref.resolve() == cls.innerClasses[0].fields[0] + assert file.stub + } + +}