use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class ExtractUtil method getTypeString.
@NotNull
public static String getTypeString(@NotNull ExtractMethodInfoHelper helper, boolean forPresentation, @NotNull String modifier) {
if (!helper.specifyType()) {
return modifier.isEmpty() ? "def " : "";
}
PsiType type = helper.getOutputType();
final PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(type);
if (unboxed != null)
type = unboxed;
final String returnType = StringUtil.notNullize(forPresentation ? type.getPresentableText() : type.getCanonicalText());
if (StringUtil.isEmptyOrSpaces(returnType) || "null".equals(returnType)) {
return modifier.isEmpty() ? "def " : "";
} else {
return returnType + " ";
}
}
use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class ExtractUtil method getParameterString.
public static String[] getParameterString(ExtractInfoHelper helper, boolean useCanonicalText) {
int i = 0;
ParameterInfo[] infos = helper.getParameterInfos();
int number = 0;
for (ParameterInfo info : infos) {
if (info.passAsParameter)
number++;
}
ArrayList<String> params = new ArrayList<>();
for (ParameterInfo info : infos) {
if (info.passAsParameter) {
PsiType paramType = info.type;
final PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(paramType);
if (unboxed != null)
paramType = unboxed;
String paramTypeText;
if (paramType == null || paramType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) || paramType.equals(PsiType.NULL)) {
paramTypeText = "";
} else {
paramTypeText = (useCanonicalText ? paramType.getCanonicalText() : paramType.getPresentableText()) + " ";
}
params.add(paramTypeText + info.getName() + (i < number - 1 ? ", " : ""));
i++;
}
}
return ArrayUtil.toStringArray(params);
}
use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class ExtractUtil method createMethod.
public static GrMethod createMethod(ExtractMethodInfoHelper helper) {
StringBuilder buffer = new StringBuilder();
//Add signature
PsiType type = helper.getOutputType();
final PsiPrimitiveType outUnboxed = PsiPrimitiveType.getUnboxedType(type);
if (outUnboxed != null)
type = outUnboxed;
String modifier = getModifierString(helper);
String typeText = getTypeString(helper, false, modifier);
buffer.append(modifier);
buffer.append(typeText);
appendName(buffer, helper.getName());
buffer.append("(");
for (String param : getParameterString(helper, true)) {
buffer.append(param);
}
buffer.append(") { \n");
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(helper.getProject());
generateBody(helper, PsiType.VOID.equals(type), buffer, helper.isForceReturn());
buffer.append("\n}");
String methodText = buffer.toString();
return factory.createMethodFromText(methodText, helper.getContext());
}
use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class BoxingEvaluator method evaluate.
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
final Object result = myOperand.evaluate(context);
if (result == null || result instanceof ObjectReference) {
return result;
}
if (result instanceof PrimitiveValue) {
PrimitiveValue primitiveValue = (PrimitiveValue) result;
PsiPrimitiveType primitiveType = PsiJavaParserFacadeImpl.getPrimitiveType(primitiveValue.type().name());
if (primitiveType != null) {
return convertToWrapper(context, primitiveValue, primitiveType.getBoxedTypeName());
}
}
throw new EvaluateException("Cannot perform boxing conversion for a value of type " + ((Value) result).type().name());
}
use of com.intellij.psi.PsiPrimitiveType in project smali by JesusFreke.
the class SmaliFieldTest method testBasicField.
public void testBasicField() {
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);
}
Aggregations