Search in sources :

Example 1 with PsiPrimitiveType

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 + " ";
    }
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiPrimitiveType

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);
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiType(com.intellij.psi.PsiType)

Example 3 with PsiPrimitiveType

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());
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiType(com.intellij.psi.PsiType)

Example 4 with PsiPrimitiveType

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());
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType)

Example 5 with PsiPrimitiveType

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);
}
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)

Aggregations

PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)18 PsiType (com.intellij.psi.PsiType)13 PsiClassType (com.intellij.psi.PsiClassType)4 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 PsiArrayType (com.intellij.psi.PsiArrayType)2 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 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