Search in sources :

Example 1 with PsiClassType

use of com.intellij.psi.PsiClassType in project android-parcelable-intellij-plugin by mcharmas.

the class PsiUtils method getResolvedGenerics.

/**
     * Resolves generics on the given type and returns them (if any) or null if there are none
     *
     * @param type
     * @return
     */
public static List<PsiType> getResolvedGenerics(PsiType type) {
    List<PsiType> psiTypes = null;
    if (type instanceof PsiClassType) {
        PsiClassType pct = (PsiClassType) type;
        psiTypes = new ArrayList<PsiType>(pct.resolveGenerics().getSubstitutor().getSubstitutionMap().values());
    }
    return psiTypes;
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiType(com.intellij.psi.PsiType)

Example 2 with PsiClassType

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

the class GrSetStrongTypeIntention method getOrCreateTypeElement.

@NotNull
private static TypeInfo getOrCreateTypeElement(@NotNull PsiElement parent, @NotNull PsiElement elementToBuildTemplateOn) {
    GrModifierList modifierList = getModifierList(parent);
    if (modifierList != null && modifierList.hasModifierProperty(GrModifier.DEF) && modifierList.getModifiers().length == 1) {
        PsiElement modifier = modifierList.getModifier(GrModifier.DEF);
        LOG.assertTrue(modifier != null);
        int modifierOffset = modifier.getTextRange().getEndOffset() - elementToBuildTemplateOn.getTextRange().getStartOffset();
        return new TypeInfo(modifier, modifierOffset);
    } else {
        int nameElementOffset;
        final PsiClassType typeToUse = TypesUtil.createType("Abc", parent);
        if (elementToBuildTemplateOn instanceof GrVariableDeclaration) {
            GrVariableDeclaration decl = (GrVariableDeclaration) elementToBuildTemplateOn;
            decl.setType(typeToUse);
            nameElementOffset = decl.getModifierList().getTextRange().getEndOffset() - elementToBuildTemplateOn.getTextRange().getStartOffset();
        } else {
            GrVariable var = (GrVariable) parent;
            var.setType(typeToUse);
            nameElementOffset = var.getNameIdentifierGroovy().getTextRange().getStartOffset() - elementToBuildTemplateOn.getTextRange().getStartOffset();
        }
        return new TypeInfo(getTypeElement(parent), nameElementOffset);
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) PsiClassType(com.intellij.psi.PsiClassType) GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) PsiElement(com.intellij.psi.PsiElement) SupertypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SupertypeConstraint) TypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PsiClassType

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

the class ExtractClosureHelperImpl method getSelectedType.

@Override
public PsiType getSelectedType() {
    if (myForceDef)
        return null;
    if (myType == null) {
        final GrClosableBlock closure = ExtractClosureProcessorBase.generateClosure(this);
        PsiType type = closure.getType();
        if (type instanceof PsiClassType) {
            final PsiType[] parameters = ((PsiClassType) type).getParameters();
            if (parameters.length == 1 && parameters[0] != null) {
                if (parameters[0].equalsToText(PsiType.VOID.getBoxedTypeName())) {
                    type = ((PsiClassType) type).rawType();
                }
            }
        }
        myType = type;
    }
    return myType;
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) PsiType(com.intellij.psi.PsiType)

Example 4 with PsiClassType

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

the class TargetType method create.

@Nullable
public static TargetType create(final PsiClassType classType) {
    final PsiClassType.ClassResolveResult resolvedGenerics = classType.resolveGenerics();
    final PsiClass resolvedClass = resolvedGenerics.getElement();
    if (resolvedClass == null) {
        return null;
    }
    final String classQName = resolvedClass.getQualifiedName();
    if (classQName == null) {
        return null;
    }
    if (resolvedClass.hasTypeParameters()) {
        return null;
    }
    return new TargetType(classQName, false, classType);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PsiClassType

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

the class TargetType method create.

@Nullable
public static TargetType create(final PsiArrayType arrayType) {
    PsiType currentComponentType = arrayType.getComponentType();
    while (currentComponentType instanceof PsiArrayType) {
        currentComponentType = ((PsiArrayType) currentComponentType).getComponentType();
    }
    if (!(currentComponentType instanceof PsiClassType)) {
        return null;
    }
    final String targetQName = arrayType.getCanonicalText();
    return new TargetType(targetQName, true, arrayType);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiArrayType(com.intellij.psi.PsiArrayType) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

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