Search in sources :

Example 1 with PsiModifierListOwner

use of com.intellij.psi.PsiModifierListOwner 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 2 with PsiModifierListOwner

use of com.intellij.psi.PsiModifierListOwner in project smali by JesusFreke.

the class SmaliClassModifierListTest method testNoAnnotation.

public void testNoAnnotation() {
    final SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public final Lmy/pkg/blah;\n" + ".super Ljava/lang/Object;");
    SmaliClass smaliClass = file.getPsiClass();
    SmaliModifierList modifierList = smaliClass.getModifierList();
    // Ensures that the parent of the modifier list is a PsiModifierListOwner
    // e.g. for code like JavaSuppressionUtil.getInspectionIdsSuppressedInAnnotation,
    // which assumes the parent is a PsiModifierListOwner
    Assert.assertTrue(modifierList.getParent() instanceof PsiModifierListOwner);
    Assert.assertEquals(0, modifierList.getAnnotations().length);
    Assert.assertEquals(0, modifierList.getApplicableAnnotations().length);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) SmaliModifierList(org.jf.smalidea.psi.impl.SmaliModifierList)

Example 3 with PsiModifierListOwner

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

the class CompilerIconLayerProvider method getLayerIcon.

@Override
public Icon getLayerIcon(@NotNull Iconable element, boolean isLocked) {
    VirtualFile vFile = null;
    Project project = null;
    if (element instanceof PsiModifierListOwner) {
        project = ((PsiModifierListOwner) element).getProject();
        final PsiFile containingFile = ((PsiModifierListOwner) element).getContainingFile();
        vFile = containingFile == null ? null : containingFile.getVirtualFile();
    } else if (element instanceof PsiDirectory) {
        project = ((PsiDirectory) element).getProject();
        vFile = ((PsiDirectory) element).getVirtualFile();
    }
    if (vFile != null && isExcluded(vFile, project)) {
        return PlatformIcons.EXCLUDED_FROM_COMPILE_ICON;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner)

Example 4 with PsiModifierListOwner

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

the class LiteralExpressionTokenizer method tokenize.

@Override
public void tokenize(@NotNull PsiLiteralExpression element, TokenConsumer consumer) {
    PsiLiteralExpressionImpl literalExpression = (PsiLiteralExpressionImpl) element;
    // not a string literal
    if (literalExpression.getLiteralElementType() != JavaTokenType.STRING_LITERAL)
        return;
    String text = literalExpression.getInnerText();
    if (StringUtil.isEmpty(text) || text.length() <= 2) {
        // optimisation to avoid expensive injection check
        return;
    }
    if (InjectedLanguageUtil.hasInjections(literalExpression))
        return;
    final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
    if (listOwner != null && AnnotationUtil.isAnnotated(listOwner, Collections.singleton(AnnotationUtil.NON_NLS), false, false)) {
        return;
    }
    if (!text.contains("\\")) {
        consumer.consumeToken(element, PlainTextSplitter.getInstance());
    } else {
        processTextWithEscapeSequences(element, text, consumer);
    }
}
Also used : PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiLiteralExpressionImpl(com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl)

Example 5 with PsiModifierListOwner

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

the class SuppressParameterFix method createSuppression.

@Override
protected void createSuppression(@NotNull Project project, @NotNull PsiElement element, @NotNull PsiElement cont) throws IncorrectOperationException {
    PsiModifierListOwner container = (PsiModifierListOwner) cont;
    final PsiModifierList modifierList = container.getModifierList();
    if (modifierList != null) {
        final String id = SuppressFix.getID(container, myAlternativeID);
        JavaSuppressionUtil.addSuppressAnnotation(project, container, container, id != null ? id : myID);
    }
}
Also used : PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiModifierList(com.intellij.psi.PsiModifierList)

Aggregations

PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)12 PsiElement (com.intellij.psi.PsiElement)4 PsiModifierList (com.intellij.psi.PsiModifierList)3 AddAnnotationFix (com.intellij.codeInsight.intention.AddAnnotationFix)2 Project (com.intellij.openapi.project.Project)2 PsiAnnotation (com.intellij.psi.PsiAnnotation)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiDocCommentOwner (com.intellij.psi.PsiDocCommentOwner)1 PsiFile (com.intellij.psi.PsiFile)1 PsiLiteralExpressionImpl (com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl)1 AndroidLintQuickFix (org.jetbrains.android.inspections.lint.AndroidLintQuickFix)1 JavaAnnotationImpl (org.jetbrains.kotlin.load.java.structure.impl.JavaAnnotationImpl)1 JavaModifierListOwnerImpl (org.jetbrains.kotlin.load.java.structure.impl.JavaModifierListOwnerImpl)1 BaseInspectionVisitor (org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor)1 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1