Search in sources :

Example 1 with PsiType

use of com.intellij.psi.PsiType 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 PsiType

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

the class ExpandBooleanPredicate method isBooleanAssignment.

public static boolean isBooleanAssignment(GrStatement expression) {
    if (!(expression instanceof GrAssignmentExpression)) {
        return false;
    }
    final GrAssignmentExpression assignment = (GrAssignmentExpression) expression;
    final GrExpression rhs = assignment.getRValue();
    if (rhs == null) {
        return false;
    }
    if (rhs instanceof GrLiteral) {
        return false;
    }
    final PsiType assignmentType = rhs.getType();
    if (assignmentType == null) {
        return false;
    }
    return assignmentType.equals(PsiType.BOOLEAN) || assignmentType.equalsToText("java.lang.Boolean");
}
Also used : GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) PsiType(com.intellij.psi.PsiType)

Example 3 with PsiType

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

the class DynamicTest method testMethod.

public void testMethod() throws Throwable {
    final GrReferenceExpression referenceExpression = doDynamicFix();
    final PsiType[] psiTypes = PsiUtil.getArgumentTypes(referenceExpression, false);
    final String[] methodArgumentsNames = GroovyNamesUtil.getMethodArgumentsNames(getProject(), psiTypes);
    final List<ParamInfo> pairs = QuickfixUtil.swapArgumentsAndTypes(methodArgumentsNames, psiTypes);
    assertNotNull(getDClassElement().getMethod(referenceExpression.getReferenceName(), QuickfixUtil.getArgumentsTypes(pairs)));
}
Also used : GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiType(com.intellij.psi.PsiType) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Example 4 with PsiType

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

the class GroovyIntroduceParameterObjectDelegate method createMergedParameterInfo.

@Override
public GrParameterInfo createMergedParameterInfo(GroovyIntroduceObjectClassDescriptor descriptor, GrMethod method, List<GrParameterInfo> oldMethodParameters) {
    final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(method.getProject());
    PsiType classType = elementFactory.createTypeByFQClassName(StringUtil.getQualifiedName(descriptor.getPackageName(), descriptor.getClassName()));
    return new GrParameterInfo(descriptor.getClassName(), null, null, classType, -1, false) {

        @Nullable
        @Override
        public PsiElement getActualValue(PsiElement callExpression, Object substitutor) {
            final IntroduceParameterObjectDelegate<PsiNamedElement, ParameterInfo, IntroduceParameterObjectClassDescriptor<PsiNamedElement, ParameterInfo>> delegate = findDelegate(callExpression);
            return delegate != null ? delegate.createNewParameterInitializerAtCallSite(callExpression, descriptor, oldMethodParameters, substitutor) : null;
        }
    };
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrParameterInfo(org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo) PsiNamedElement(com.intellij.psi.PsiNamedElement) IntroduceParameterObjectClassDescriptor(com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor) ParameterInfo(com.intellij.refactoring.changeSignature.ParameterInfo) GrParameterInfo(org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 5 with PsiType

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

the class GrSetStrongTypeIntention method getClosureParameterType.

@Nullable
private static PsiType getClosureParameterType(@NotNull PsiParameter parameter) {
    final PsiElement scope = parameter.getDeclarationScope();
    final PsiType type;
    if (scope instanceof GrClosableBlock) {
        type = ClosureParameterEnhancer.inferType((GrClosableBlock) scope, ((GrParameterList) parameter.getParent()).getParameterIndex(parameter));
    } else {
        type = null;
    }
    return type;
}
Also used : GrParameterList(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

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