Search in sources :

Example 96 with PsiType

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

the class ExpectedTypesGetter method extractTypes.

@NotNull
public static PsiType[] extractTypes(ExpectedTypeInfo[] infos, boolean defaultTypes) {
    Set<PsiType> result = new THashSet<>(infos.length);
    for (ExpectedTypeInfo info : infos) {
        final PsiType type = info.getType();
        final PsiType defaultType = info.getDefaultType();
        if (!defaultTypes && !defaultType.equals(type)) {
            result.add(type);
        }
        result.add(defaultType);
    }
    return result.toArray(PsiType.createArray(result.size()));
}
Also used : ExpectedTypeInfo(com.intellij.codeInsight.ExpectedTypeInfo) THashSet(gnu.trove.THashSet) PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with PsiType

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

the class PsiAugmentProvider method getInferredType.

@Nullable
public static PsiType getInferredType(@NotNull final PsiTypeElement typeElement) {
    final Ref<PsiType> result = Ref.create();
    forEach(typeElement.getProject(), provider -> {
        PsiType type = provider.inferType(typeElement);
        if (type != null) {
            result.set(type);
            return false;
        } else {
            return true;
        }
    });
    return result.get();
}
Also used : PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 98 with PsiType

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

the class GenericsHighlightingTest method testLeastUpperBoundWithRecursiveTypes.

public void testLeastUpperBoundWithRecursiveTypes() throws Exception {
    final PsiManager manager = getPsiManager();
    final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
    final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(PsiType.INT.getBoxedType(manager, scope), PsiType.LONG.getBoxedType(manager, scope), manager);
    assertNotNull(leastUpperBound);
    assertEquals("Number & Comparable<? extends Number & Comparable<?>>", leastUpperBound.getPresentableText());
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiManager(com.intellij.psi.PsiManager) PsiType(com.intellij.psi.PsiType)

Example 99 with PsiType

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

the class FunctionalInterfaceTest method testIntersectionTypeWithSameBaseInterfaceInConjuncts.

public void testIntersectionTypeWithSameBaseInterfaceInConjuncts() throws Exception {
    String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
    configureByFile(filePath);
    final PsiTypeCastExpression castExpression = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiTypeCastExpression.class);
    assertNotNull(castExpression);
    final PsiTypeElement castTypeElement = castExpression.getCastType();
    assertNotNull(castTypeElement);
    final PsiType type = castTypeElement.getType();
    final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional(type);
    assertEquals(null, errorMessage);
}
Also used : PsiTypeElement(com.intellij.psi.PsiTypeElement) PsiTypeCastExpression(com.intellij.psi.PsiTypeCastExpression) PsiType(com.intellij.psi.PsiType)

Example 100 with PsiType

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

the class FilterPattern method methodMatches.

public boolean methodMatches(@NotNull PsiMethod method) {
    final String methodName = method.getName();
    final Pattern methodNamePattern = getMethodNamePattern();
    if ((methodNamePattern != null) && methodNamePattern.matcher(methodName).matches()) {
        return true;
    }
    final PsiType returnType = method.getReturnType();
    if (returnType == null) {
        return false;
    }
    final Pattern patternTypePattern = getMethodTypePattern();
    final String methodType = returnType.getCanonicalText();
    return (patternTypePattern != null) && methodTypePattern.matcher(methodType).matches();
}
Also used : Pattern(java.util.regex.Pattern) 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