Search in sources :

Example 11 with PsiClassType

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

the class AsTypeTransformation method couldApply.

@Override
protected boolean couldApply(@NotNull GrSafeCastExpression expression) {
    GrTypeElement typeElement = expression.getCastTypeElement();
    if (typeElement == null)
        return false;
    PsiType type = typeElement.getType();
    return type instanceof PsiClassType && ((PsiClassType) type).getParameterCount() == 0;
}
Also used : GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) PsiClassType(com.intellij.psi.PsiClassType) PsiType(com.intellij.psi.PsiType)

Example 12 with PsiClassType

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

the class GroovyUntypedAccessInspection method buildVisitor.

@Override
@NotNull
protected BaseInspectionVisitor buildVisitor() {
    return new BaseInspectionVisitor() {

        @Override
        public void visitReferenceExpression(@NotNull GrReferenceExpression refExpr) {
            super.visitReferenceExpression(refExpr);
            if (PsiUtil.isThisOrSuperRef(refExpr))
                return;
            GroovyResolveResult resolveResult = refExpr.advancedResolve();
            PsiElement resolved = resolveResult.getElement();
            if (resolved != null) {
                if (GrHighlightUtil.isDeclarationAssignment(refExpr) || resolved instanceof PsiPackage)
                    return;
            } else {
                GrExpression qualifier = refExpr.getQualifierExpression();
                if (qualifier == null && GrHighlightUtil.isDeclarationAssignment(refExpr))
                    return;
            }
            final PsiType refExprType = refExpr.getType();
            if (refExprType == null) {
                if (resolved != null) {
                    registerError(refExpr);
                }
            } else if (refExprType instanceof PsiClassType && ((PsiClassType) refExprType).resolve() == null) {
                registerError(refExpr);
            }
        }
    };
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) BaseInspectionVisitor(org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor) PsiPackage(com.intellij.psi.PsiPackage) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with PsiClassType

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

the class GrExpressionCategory method getClassType.

@Nullable
public static PsiClass getClassType(GrExpression expr) {
    final PsiType type = expr.getType();
    if (type instanceof PsiClassType) {
        PsiClassType classType = (PsiClassType) type;
        return classType.resolve();
    } else {
        final String text = type.getPresentableText();
        final Project project = expr.getProject();
        final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
        return facade.findClass(text, GlobalSearchScope.allScope(project));
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiClassType(com.intellij.psi.PsiClassType) Project(com.intellij.openapi.project.Project) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with PsiClassType

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

the class GdslType method getName.

public String getName() {
    PsiType type = psiType;
    if (type instanceof PsiWildcardType) {
        type = ((PsiWildcardType) type).getBound();
    }
    if (type instanceof PsiClassType) {
        final PsiClass resolve = ((PsiClassType) type).resolve();
        if (resolve != null) {
            return resolve.getName();
        }
        final String canonicalText = type.getCanonicalText();
        final int i = canonicalText.indexOf('<');
        if (i < 0)
            return canonicalText;
        return canonicalText.substring(0, i);
    }
    if (type == null) {
        return "";
    }
    return type.getCanonicalText();
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) PsiWildcardType(com.intellij.psi.PsiWildcardType) PsiType(com.intellij.psi.PsiType)

Example 15 with PsiClassType

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

the class GroovyMethodReturnNamedArgumentProvider method getNamedArguments.

@Override
public void getNamedArguments(@NotNull GrCall call, @NotNull GroovyResolveResult resolveResult, @Nullable String argumentName, boolean forCompletion, @NotNull Map<String, NamedArgumentDescriptor> result) {
    PsiElement resolve = resolveResult.getElement();
    if (!forCompletion || !(resolve instanceof PsiMethod))
        return;
    PsiType returnType = ((PsiMethod) resolve).getReturnType();
    if (!(returnType instanceof PsiClassType))
        return;
    Map<String, NamedArgumentDescriptor> map = new HashMap<>();
    GroovyConstructorNamedArgumentProvider.processClass(call, (PsiClassType) returnType, argumentName, map);
    for (String name : map.keySet()) {
        result.put(name, NamedArgumentDescriptor.SIMPLE_UNLIKELY);
    }
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) PsiMethod(com.intellij.psi.PsiMethod) HashMap(java.util.HashMap) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

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