Search in sources :

Example 1 with PsiTypeElement

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

the class SmaliArrayTypeElement method getType.

@NotNull
@Override
public PsiType getType() {
    ASTNode token = findChildByType(SmaliTokens.ARRAY_TYPE_PREFIX);
    assert token != null;
    PsiTypeElement baseType = findChildByClass(PsiTypeElement.class);
    assert baseType != null;
    PsiArrayType arrayType = new PsiArrayType(baseType.getType());
    int dimensions = token.getTextLength() - 1;
    while (dimensions > 0) {
        arrayType = new PsiArrayType(arrayType);
        dimensions--;
    }
    return arrayType;
}
Also used : PsiTypeElement(com.intellij.psi.PsiTypeElement) ASTNode(com.intellij.lang.ASTNode) PsiArrayType(com.intellij.psi.PsiArrayType) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiTypeElement

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

Example 3 with PsiTypeElement

use of com.intellij.psi.PsiTypeElement 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 4 with PsiTypeElement

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

the class ChangeReturnType method fixUsage.

@Override
public void fixUsage() throws IncorrectOperationException {
    PsiTypeElement returnType = myMethod.getReturnTypeElement();
    assert returnType != null : myMethod;
    MutationUtils.replaceType(myType, returnType);
}
Also used : PsiTypeElement(com.intellij.psi.PsiTypeElement)

Example 5 with PsiTypeElement

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

Aggregations

PsiTypeElement (com.intellij.psi.PsiTypeElement)9 PsiField (com.intellij.psi.PsiField)3 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)3 PsiArrayType (com.intellij.psi.PsiArrayType)2 PsiClass (com.intellij.psi.PsiClass)2 PsiElement (com.intellij.psi.PsiElement)2 PsiType (com.intellij.psi.PsiType)2 PsiTypeCastExpression (com.intellij.psi.PsiTypeCastExpression)2 SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)2 SmaliField (org.jf.smalidea.psi.impl.SmaliField)2 SmaliFile (org.jf.smalidea.psi.impl.SmaliFile)2 SmaliModifierList (org.jf.smalidea.psi.impl.SmaliModifierList)2 Nullable (com.android.annotations.Nullable)1 ASTNode (com.intellij.lang.ASTNode)1 CaretModel (com.intellij.openapi.editor.CaretModel)1 PsiArrayInitializerExpression (com.intellij.psi.PsiArrayInitializerExpression)1 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)1 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)1