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$)";
}
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);
});
}
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;
}
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);
}
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);
}
Aggregations