Search in sources :

Example 86 with PsiType

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

the class MapSerializer method readValue.

@Override
public String readValue(SerializableValue field, String parcel) {
    final List<PsiType> resolvedGenerics = PsiUtils.getResolvedGenerics(field.getType());
    PsiType keyType = resolvedGenerics.get(1);
    PsiType valueType = resolvedGenerics.get(0);
    String sizeVariableName = field.getSimpleName() + "Size";
    return new StringBuilder().append(String.format("int %s = %s.readInt();", sizeVariableName, parcel)).append(field.getName()).append(String.format(" = new java.util.HashMap<%s, %s>(%s);", keyType.getCanonicalText(), valueType.getCanonicalText(), sizeVariableName)).append(String.format("for(int i = 0; i < %s; i++) {", sizeVariableName)).append(typeSerializerFactory.getSerializer(keyType).readValue(SerializableValue.variable("key", keyType), parcel)).append(typeSerializerFactory.getSerializer(valueType).readValue(SerializableValue.variable("value", valueType), parcel)).append(field.getName()).append(".put(key, value);").append("}").toString();
}
Also used : PsiType(com.intellij.psi.PsiType)

Example 87 with PsiType

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

the class PsiUtils method isTypedClass.

/**
     * Checks that the given type is an implementer of the given canonicalName with the given typed parameters
     *
     * @param type                what we're checking against
     * @param canonicalName       the type must extend/implement this generic
     * @param canonicalParamNames the type that the generic(s) must be (in this order)
     * @return
     */
public static boolean isTypedClass(PsiType type, String canonicalName, String... canonicalParamNames) {
    PsiClass parameterClass = PsiTypesUtil.getPsiClass(type);
    if (parameterClass == null) {
        return false;
    }
    // This is a safe cast, for if parameterClass != null, the type was checked in PsiTypesUtil#getPsiClass(...)
    PsiClassType pct = (PsiClassType) type;
    // Main class name doesn't match; exit early
    if (!canonicalName.equals(parameterClass.getQualifiedName())) {
        return false;
    }
    List<PsiType> psiTypes = new ArrayList<PsiType>(pct.resolveGenerics().getSubstitutor().getSubstitutionMap().values());
    for (int i = 0; i < canonicalParamNames.length; i++) {
        if (!isOfType(psiTypes.get(i), canonicalParamNames[i])) {
            return false;
        }
    }
    // Passed all screenings; must be a match!
    return true;
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) PsiType(com.intellij.psi.PsiType)

Example 88 with PsiType

use of com.intellij.psi.PsiType in project timber by JakeWharton.

the class WrongTimberUsageDetector method isSubclassOf.

private static boolean isSubclassOf(JavaContext context, PsiExpression expression, Class<?> cls) {
    PsiType expressionType = expression.getType();
    if (expressionType instanceof PsiClassType) {
        PsiClassType classType = (PsiClassType) expressionType;
        PsiClass resolvedClass = classType.resolve();
        return context.getEvaluator().extendsClass(resolvedClass, cls.getName(), false);
    }
    return false;
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) PsiType(com.intellij.psi.PsiType)

Example 89 with PsiType

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

the class SmaliMethodReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    PsiClass containingClass = getContainingClass();
    if (containingClass == null) {
        return null;
    }
    SmaliMemberName memberName = getMemberName();
    if (memberName == null) {
        return null;
    }
    LightMethodBuilder pattern = new LightMethodBuilder(getManager(), SmaliLanguage.INSTANCE, memberName.getText());
    for (PsiType type : getParameterTypes()) {
        pattern.addParameter("", type);
    }
    SmaliTypeElement returnTypeElement = getReturnType();
    if (returnTypeElement == null) {
        return null;
    }
    pattern.setMethodReturnType(returnTypeElement.getType());
    // TODO: what about static constructor?
    pattern.setConstructor(memberName.getText().equals("<init>"));
    return containingClass.findMethodBySignature(pattern, true);
}
Also used : LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) PsiClass(com.intellij.psi.PsiClass) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with PsiType

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

the class ParametersMatcher method matchParameters.

private static MatchResult matchParameters(final PsiMethod method, final ChainCompletionContext context, final Set<String> additionalExcludedNames) {
    int matched = 0;
    int unMatched = 0;
    boolean hasTarget = false;
    for (final PsiParameter parameter : method.getParameterList().getParameters()) {
        final PsiType type = parameter.getType();
        final String canonicalText = type.getCanonicalText();
        if (context.contains(canonicalText) || type instanceof PsiPrimitiveType) {
            matched++;
        } else {
            unMatched++;
        }
        if (context.getTarget().getClassQName().equals(canonicalText) || additionalExcludedNames.contains(canonicalText)) {
            hasTarget = true;
        }
    }
    return new MatchResult(matched, unMatched, hasTarget);
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiParameter(com.intellij.psi.PsiParameter) PsiType(com.intellij.psi.PsiType)

Aggregations

PsiType (com.intellij.psi.PsiType)157 PsiElement (com.intellij.psi.PsiElement)34 Nullable (org.jetbrains.annotations.Nullable)24 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)24 NotNull (org.jetbrains.annotations.NotNull)21 PsiClassType (com.intellij.psi.PsiClassType)20 PsiClass (com.intellij.psi.PsiClass)14 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)13 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)12 ArrayList (java.util.ArrayList)9 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)9 PsiArrayType (com.intellij.psi.PsiArrayType)7 PsiExpression (com.intellij.psi.PsiExpression)7 PsiField (com.intellij.psi.PsiField)7 NonNls (org.jetbrains.annotations.NonNls)7 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)7 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)6 PsiMethod (com.intellij.psi.PsiMethod)6 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)6 GrLiteral (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)6