Search in sources :

Example 6 with PsiPrimitiveType

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

the class OptionalPostfixTemplate method getTemplateString.

@Nullable
@Override
public String getTemplateString(@NotNull PsiElement element) {
    String className = "Optional";
    String methodName = "ofNullable";
    if (element instanceof PsiExpression) {
        PsiType type = ((PsiExpression) element).getType();
        if (type instanceof PsiPrimitiveType) {
            if (PsiType.INT.equals(type)) {
                className = "OptionalInt";
            } else if (PsiType.DOUBLE.equals(type)) {
                className = "OptionalDouble";
            } else if (PsiType.LONG.equals(type)) {
                className = "OptionalLong";
            }
            methodName = "of";
        }
    }
    return "java.util." + className + "." + methodName + "($expr$)";
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiExpression(com.intellij.psi.PsiExpression) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PsiPrimitiveType

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

the class NullityInference method inferNullity.

public static Nullness inferNullity(PsiMethodImpl method) {
    if (!InferenceFromSourceUtil.shouldInferFromSource(method)) {
        return Nullness.UNKNOWN;
    }
    PsiType type = method.getReturnType();
    if (type == null || type instanceof PsiPrimitiveType) {
        return Nullness.UNKNOWN;
    }
    return CachedValuesManager.getCachedValue(method, () -> {
        MethodData data = ContractInferenceIndexKt.getIndexedData(method);
        NullityInferenceResult result = data == null ? null : data.getNullity();
        Nullness nullness = result == null ? null : RecursionManager.doPreventingRecursion(method, true, () -> result.getNullness(method, data.methodBody(method)));
        if (nullness == null)
            nullness = Nullness.UNKNOWN;
        return CachedValueProvider.Result.create(nullness, method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    });
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiType(com.intellij.psi.PsiType)

Example 8 with PsiPrimitiveType

use of com.intellij.psi.PsiPrimitiveType in project intellij-plugins by JetBrains.

the class CfmlExpressionTypeCalculator method checkAndReturnNumeric.

@Nullable
private static PsiType checkAndReturnNumeric(@NotNull CfmlExpression leftOperand, @NotNull CfmlExpression rightOperand) {
    PsiType rightType = rightOperand.getPsiType();
    if (rightType == null) {
        return null;
    }
    PsiType leftType = leftOperand.getPsiType();
    if (leftType == null) {
        return null;
    }
    if (isNumericType(leftType) && isNumericType(rightType)) {
        PsiClassType boxedType = ((PsiPrimitiveType) unboxAndBalanceTypes(leftType, rightType)).getBoxedType(leftOperand.getManager(), leftOperand.getResolveScope());
        return boxedType;
    }
    return null;
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PsiPrimitiveType

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

the class SmaliFieldTest method testFieldAnnotations.

public void testFieldAnnotations() {
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", ".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" + ".field public myField:I");
    SmaliClass smaliClass = file.getPsiClass();
    Assert.assertEquals("my.pkg.blah", smaliClass.getQualifiedName());
    SmaliField[] fields = smaliClass.getFields();
    Assert.assertEquals(1, fields.length);
    Assert.assertEquals("myField", fields[0].getName());
    Assert.assertTrue(fields[0].getType() instanceof PsiPrimitiveType);
    Assert.assertEquals("int", fields[0].getType().getCanonicalText());
    PsiTypeElement typeElement = fields[0].getTypeElement();
    Assert.assertNotNull("I", typeElement);
    Assert.assertEquals("I", typeElement.getText());
    SmaliModifierList modifierList = fields[0].getModifierList();
    Assert.assertNotNull(modifierList);
    Assert.assertEquals(AccessFlags.PUBLIC.getValue(), modifierList.getAccessFlags());
    Assert.assertTrue(modifierList.hasExplicitModifier("public"));
    Assert.assertTrue(modifierList.hasModifierProperty("public"));
    Assert.assertTrue(fields[0].hasModifierProperty("public"));
    PsiField[] psifields = smaliClass.getAllFields();
    Assert.assertEquals(1, psifields.length);
    Assert.assertEquals("myField", psifields[0].getName());
    PsiField field = smaliClass.findFieldByName("myField", true);
    Assert.assertNotNull(field);
    Assert.assertEquals("myField", field.getName());
    field = smaliClass.findFieldByName("nonExistantField", true);
    Assert.assertNull(field);
    field = smaliClass.findFieldByName("nonExistantField", false);
    Assert.assertNull(field);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiTypeElement(com.intellij.psi.PsiTypeElement) PsiField(com.intellij.psi.PsiField) SmaliField(org.jf.smalidea.psi.impl.SmaliField) SmaliModifierList(org.jf.smalidea.psi.impl.SmaliModifierList)

Example 10 with PsiPrimitiveType

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

PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)17 PsiType (com.intellij.psi.PsiType)12 PsiClassType (com.intellij.psi.PsiClassType)3 PsiElement (com.intellij.psi.PsiElement)3 PsiField (com.intellij.psi.PsiField)3 PsiTypeElement (com.intellij.psi.PsiTypeElement)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiClass (com.intellij.psi.PsiClass)2 PsiExpression (com.intellij.psi.PsiExpression)2 PsiParameter (com.intellij.psi.PsiParameter)2 Nullable (com.android.annotations.Nullable)1 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 PsiArrayInitializerExpression (com.intellij.psi.PsiArrayInitializerExpression)1 PsiArrayType (com.intellij.psi.PsiArrayType)1 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)1 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)1 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)1 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)1 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)1