Search in sources :

Example 1 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project kotlin by JetBrains.

the class LightClassAnnotationsTest method doTest.

private void doTest(@NotNull String fqName) {
    PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
    if (!(psiClass instanceof KtLightClass)) {
        throw new IllegalStateException("Not a light class: " + psiClass + " (" + fqName + ")");
    }
    PsiModifierList modifierList = psiClass.getModifierList();
    assert modifierList != null : "No modifier list for " + psiClass.getText();
    StringBuilder sb = new StringBuilder();
    for (PsiAnnotation annotation : modifierList.getAnnotations()) {
        sb.append(annotation.getText()).append("\n");
    }
    KotlinTestUtils.assertEqualsToFile(new File(testDir, getTestName(false) + ".annotations.txt"), sb.toString());
}
Also used : PsiClass(com.intellij.psi.PsiClass) KtLightClass(org.jetbrains.kotlin.asJava.classes.KtLightClass) PsiAnnotation(com.intellij.psi.PsiAnnotation) File(java.io.File) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 2 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project kotlin by JetBrains.

the class PsiBasedExternalAnnotationResolver method findExternalAnnotation.

@Nullable
@Override
public JavaAnnotation findExternalAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) {
    if (owner instanceof JavaModifierListOwnerImpl) {
        PsiModifierListOwner psiOwner = ((JavaModifierListOwnerImpl) owner).getPsi();
        PsiAnnotation psiAnnotation = ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotation(psiOwner, fqName.asString());
        return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
    }
    return null;
}
Also used : JavaModifierListOwnerImpl(org.jetbrains.kotlin.load.java.structure.impl.JavaModifierListOwnerImpl) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiAnnotation(com.intellij.psi.PsiAnnotation) JavaAnnotationImpl(org.jetbrains.kotlin.load.java.structure.impl.JavaAnnotationImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.

the class NullityAnnotationModifier method modifyLowerBoundAnnotations.

@Nullable
@Override
public TypeAnnotationProvider modifyLowerBoundAnnotations(@NotNull PsiType lowerBound, @NotNull PsiType upperBound) {
    PsiAnnotation[] lowerAnnotations = lowerBound.getAnnotations();
    PsiAnnotation nullable = findNullable(lowerAnnotations);
    if (nullable != null && findNullable(upperBound.getAnnotations()) == null) {
        return removeAnnotation(lowerAnnotations, nullable);
    }
    return null;
}
Also used : PsiAnnotation(com.intellij.psi.PsiAnnotation) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.

the class PsiAnnotationStubImpl method getPsiElement.

@Override
public PsiAnnotation getPsiElement() {
    PsiAnnotation annotation = SoftReference.dereference(myParsedFromRepository);
    if (annotation != null)
        return annotation;
    String text = getText();
    try {
        PsiJavaParserFacade facade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
        annotation = facade.createAnnotationFromText(text, getPsi());
        myParsedFromRepository = new SoftReference<>(annotation);
        return annotation;
    } catch (IncorrectOperationException e) {
        LOG.error("Bad annotation in repository!", e);
        return null;
    }
}
Also used : PsiJavaParserFacade(com.intellij.psi.PsiJavaParserFacade) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 5 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project android by JetBrains.

the class ResolveTypedIntegerCommand method action.

@Override
public void action() {
    // TODO: see if it is possible to cache this evaluation
    // if (myIsEvaluated) return;
    DebugProcess debugProcess = myEvaluationContext.getDebugProcess();
    if (!(debugProcess instanceof DebugProcessImpl)) {
        return;
    }
    final DebuggerContextImpl debuggerContext = ((DebugProcessImpl) debugProcess).getDebuggerContext();
    PsiAnnotation annotation = ApplicationManager.getApplication().runReadAction(new Computable<PsiAnnotation>() {

        @Override
        public PsiAnnotation compute() {
            try {
                return getAnnotation(debuggerContext);
            } catch (IndexNotReadyException e) {
                return null;
            }
        }
    });
    if (annotation != null) {
        ResourceIdResolver resolver = ServiceManager.getService(myEvaluationContext.getProject(), ResourceIdResolver.class);
        DynamicResourceIdResolver resolver1 = new DynamicResourceIdResolver(myEvaluationContext, resolver);
        myResult = AnnotationsRenderer.render(resolver1, annotation, ((IntegerValue) myValue).value());
    }
    evaluationResult("");
}
Also used : DebugProcess(com.intellij.debugger.engine.DebugProcess) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) IntegerValue(com.sun.jdi.IntegerValue) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Aggregations

PsiAnnotation (com.intellij.psi.PsiAnnotation)61 PsiModifierList (com.intellij.psi.PsiModifierList)18 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)14 PsiMethod (com.intellij.psi.PsiMethod)14 NotNull (org.jetbrains.annotations.NotNull)13 Project (com.intellij.openapi.project.Project)12 PsiClass (com.intellij.psi.PsiClass)11 PsiElement (com.intellij.psi.PsiElement)9 MockProblemDescriptor (com.intellij.testFramework.MockProblemDescriptor)6 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)5 PsiParameter (com.intellij.psi.PsiParameter)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5 Nullable (org.jetbrains.annotations.Nullable)5 PsiParameterList (com.intellij.psi.PsiParameterList)4 TestSize (com.google.idea.blaze.base.dependencies.TestSize)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 PsiNameValuePair (com.intellij.psi.PsiNameValuePair)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Nullable (javax.annotation.Nullable)3