Search in sources :

Example 31 with PsiClassType

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

the class LiteralConstructorSearcher method isCorrectReference.

private boolean isCorrectReference(LiteralConstructorReference reference) {
    if (reference.isReferenceTo(myConstructor)) {
        return true;
    }
    if (!myIncludeOverloads) {
        return false;
    }
    PsiClassType constructedClassType = reference.getConstructedClassType();
    if (constructedClassType == null)
        return false;
    final PsiClass psiClass = constructedClassType.resolve();
    return myConstructor.getManager().areElementsEquivalent(myConstructor.getContainingClass(), psiClass);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass)

Example 32 with PsiClassType

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

the class GrHighlightOverridingMethodsHandler method getTargets.

@Override
public List<PsiClass> getTargets() {
    GrReferenceList list = GroovyTokenTypes.kEXTENDS == myTarget.getNode().getElementType() ? myClass.getExtendsClause() : myClass.getImplementsClause();
    if (list == null)
        return Collections.emptyList();
    final PsiClassType[] classTypes = list.getReferencedTypes();
    return ChooseClassAndDoHighlightRunnable.resolveClasses(classTypes);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) GrReferenceList(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList)

Example 33 with PsiClassType

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

the class GrMemberInfoStorage method buildSubClassesMapForList.

private void buildSubClassesMapForList(final PsiClassType[] classesList, GrTypeDefinition aClass) {
    for (int i = 0; i < classesList.length; i++) {
        PsiClassType element = classesList[i];
        PsiClass resolved = element.resolve();
        if (resolved instanceof GrTypeDefinition) {
            GrTypeDefinition superClass = (GrTypeDefinition) resolved;
            getSubclasses(superClass).add(aClass);
            buildSubClassesMap(superClass);
        }
    }
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass)

Example 34 with PsiClassType

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

the class HandlerDetector method checkClass.

@Override
public void checkClass(@NonNull JavaContext context, @NonNull UClass declaration) {
    // Only consider static inner classes
    if (context.getEvaluator().isStatic(declaration)) {
        return;
    }
    boolean isAnonymous = declaration instanceof UAnonymousClass;
    if (declaration.getContainingClass() == null && !isAnonymous) {
        return;
    }
    //// Only flag handlers using the default looper
    //noinspection unchecked
    UCallExpression invocation = UastUtils.getParentOfType(declaration, UObjectLiteralExpression.class, true, UMethod.class);
    if (invocation != null) {
        if (isAnonymous && invocation.getValueArgumentCount() > 0) {
            for (UExpression expression : invocation.getValueArguments()) {
                PsiType type = expression.getExpressionType();
                if (type instanceof PsiClassType && LOOPER_CLS.equals(type.getCanonicalText())) {
                    return;
                }
            }
        }
    } else if (hasLooperConstructorParameter(declaration)) {
        // possibly used correctly from elsewhere
        return;
    }
    Location location = context.getUastNameLocation(declaration);
    String name;
    if (isAnonymous) {
        name = "anonymous " + ((UAnonymousClass) declaration).getBaseClassReference().getQualifiedName();
    } else {
        name = declaration.getQualifiedName();
    }
    //noinspection VariableNotUsedInsideIf
    context.reportUast(ISSUE, declaration, location, String.format("This Handler class should be static or leaks might occur (%1$s)", name));
}
Also used : UExpression(org.jetbrains.uast.UExpression) PsiClassType(com.intellij.psi.PsiClassType) UAnonymousClass(org.jetbrains.uast.UAnonymousClass) UCallExpression(org.jetbrains.uast.UCallExpression) PsiType(com.intellij.psi.PsiType) Location(com.android.tools.klint.detector.api.Location)

Example 35 with PsiClassType

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

the class JavaScriptInterfaceDetector method visitMethod.

@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
    if (context.getMainProject().getTargetSdk() < 17) {
        return;
    }
    List<UExpression> arguments = call.getValueArguments();
    if (arguments.size() != 2) {
        return;
    }
    JavaEvaluator evaluator = context.getEvaluator();
    if (!JavaEvaluator.isMemberInClass(method, WEB_VIEW_CLS)) {
        return;
    }
    UExpression first = arguments.get(0);
    PsiType evaluated = TypeEvaluator.evaluate(context, first);
    if (evaluated instanceof PsiClassType) {
        PsiClassType classType = (PsiClassType) evaluated;
        PsiClass cls = classType.resolve();
        if (cls == null) {
            return;
        }
        if (isJavaScriptAnnotated(cls)) {
            return;
        }
        Location location = context.getUastNameLocation(call);
        String message = String.format("None of the methods in the added interface (%1$s) have been annotated " + "with `@android.webkit.JavascriptInterface`; they will not " + "be visible in API 17", cls.getName());
        context.report(ISSUE, call, location, message);
    }
}
Also used : UExpression(org.jetbrains.uast.UExpression) PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) JavaEvaluator(com.android.tools.klint.client.api.JavaEvaluator) PsiType(com.intellij.psi.PsiType) Location(com.android.tools.klint.detector.api.Location)

Aggregations

PsiClassType (com.intellij.psi.PsiClassType)39 PsiType (com.intellij.psi.PsiType)20 PsiClass (com.intellij.psi.PsiClass)16 PsiElement (com.intellij.psi.PsiElement)10 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)4 UExpression (org.jetbrains.uast.UExpression)4 Location (com.android.tools.klint.detector.api.Location)3 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)3 ArrayList (java.util.ArrayList)3 AbstractResourceRepository (com.android.ide.common.res2.AbstractResourceRepository)2 ResourceItem (com.android.ide.common.res2.ResourceItem)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2 PsiCFGClass (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)2 PsiCFGMethod (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)2 JavaEvaluator (com.android.tools.klint.client.api.JavaEvaluator)2 LintClient (com.android.tools.klint.client.api.LintClient)2 Project (com.intellij.openapi.project.Project)2 PsiArrayType (com.intellij.psi.PsiArrayType)2 PsiField (com.intellij.psi.PsiField)2