Search in sources :

Example 81 with PsiField

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

the class SimpleFieldChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final DefaultListModel model = new DefaultListModel();
    for (PsiField member : myFields) {
        model.addElement(member);
    }
    myList = new JBList(model);
    myList.setCellRenderer(new MyListCellRenderer());
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (myList.getSelectedValues().length > 0) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myList);
    myList.setPreferredSize(JBUI.size(300, 400));
    return myList;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) PsiField(com.intellij.psi.PsiField) JBList(com.intellij.ui.components.JBList)

Example 82 with PsiField

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

the class CreateFieldFromParameterDialog method doOKAction.

@Override
protected void doOKAction() {
    if (myCbFinal.isEnabled()) {
        PropertiesComponent.getInstance().setValue(PROPERTY_NAME, myCbFinal.isSelected());
    }
    final PsiField[] fields = myTargetClass.getFields();
    for (PsiField field : fields) {
        if (field.getName().equals(getEnteredName())) {
            int result = Messages.showOkCancelDialog(getContentPane(), CodeInsightBundle.message("dialog.create.field.from.parameter.already.exists.text", getEnteredName()), CodeInsightBundle.message("dialog.create.field.from.parameter.already.exists.title"), Messages.getQuestionIcon());
            if (result == Messages.OK) {
                close(OK_EXIT_CODE);
            } else {
                return;
            }
        }
    }
    close(OK_EXIT_CODE);
}
Also used : PsiField(com.intellij.psi.PsiField)

Example 83 with PsiField

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

the class CanBeFinalTest method testfieldImplicitWrite.

public void testfieldImplicitWrite() throws Exception {
    PlatformTestUtil.registerExtension(ImplicitUsageProvider.EP_NAME, new ImplicitUsageProvider() {

        @Override
        public boolean isImplicitUsage(PsiElement element) {
            return isImplicitWrite(element);
        }

        @Override
        public boolean isImplicitRead(PsiElement element) {
            return false;
        }

        @Override
        public boolean isImplicitWrite(PsiElement element) {
            return element instanceof PsiField && "implicitWrite".equals(((PsiNamedElement) element).getName());
        }
    }, getTestRootDisposable());
    doTest();
}
Also used : PsiField(com.intellij.psi.PsiField) ImplicitUsageProvider(com.intellij.codeInsight.daemon.ImplicitUsageProvider) PsiElement(com.intellij.psi.PsiElement)

Example 84 with PsiField

use of com.intellij.psi.PsiField in project kotlin by JetBrains.

the class ResourceEvaluator method getResourceConstant.

/** Returns a resource URL based on the field reference in the code */
@Nullable
public static ResourceUrl getResourceConstant(@NonNull PsiElement node) {
    // R.type.name
    if (node instanceof PsiReferenceExpression) {
        PsiReferenceExpression expression = (PsiReferenceExpression) node;
        if (expression.getQualifier() instanceof PsiReferenceExpression) {
            PsiReferenceExpression select = (PsiReferenceExpression) expression.getQualifier();
            if (select.getQualifier() instanceof PsiReferenceExpression) {
                PsiReferenceExpression reference = (PsiReferenceExpression) select.getQualifier();
                if (R_CLASS.equals(reference.getReferenceName())) {
                    String typeName = select.getReferenceName();
                    String name = expression.getReferenceName();
                    ResourceType type = ResourceType.getEnum(typeName);
                    if (type != null && name != null) {
                        boolean isFramework = reference.getQualifier() instanceof PsiReferenceExpression && ANDROID_PKG.equals(((PsiReferenceExpression) reference.getQualifier()).getReferenceName());
                        return ResourceUrl.create(type, name, isFramework, false);
                    }
                }
            }
        }
    } else if (node instanceof PsiField) {
        PsiField field = (PsiField) node;
        PsiClass typeClass = field.getContainingClass();
        if (typeClass != null) {
            PsiClass rClass = typeClass.getContainingClass();
            if (rClass != null && R_CLASS.equals(rClass.getName())) {
                String name = field.getName();
                ResourceType type = ResourceType.getEnum(typeClass.getName());
                if (type != null && name != null) {
                    String qualifiedName = rClass.getQualifiedName();
                    boolean isFramework = qualifiedName != null && qualifiedName.startsWith(ANDROID_PKG_PREFIX);
                    return ResourceUrl.create(type, name, isFramework, false);
                }
            }
        }
    }
    return null;
}
Also used : PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) ResourceType(com.android.resources.ResourceType) Nullable(com.android.annotations.Nullable)

Example 85 with PsiField

use of com.intellij.psi.PsiField in project kotlin by JetBrains.

the class ParcelDetector method checkClass.

@Override
public void checkClass(@NonNull JavaContext context, @NonNull UClass declaration) {
    if (declaration instanceof UAnonymousClass) {
        // Anonymous classes aren't parcelable
        return;
    }
    // Only applies to concrete classes
    if (declaration.isInterface()) {
        return;
    }
    if (declaration.hasModifierProperty(PsiModifier.ABSTRACT)) {
        return;
    }
    // Parceling spans is handled in TextUtils#CHAR_SEQUENCE_CREATOR
    if (InheritanceUtil.isInheritor(declaration, false, "android.text.ParcelableSpan")) {
        return;
    }
    PsiField field = declaration.findFieldByName("CREATOR", false);
    if (field == null) {
        Location location = context.getUastNameLocation(declaration);
        context.reportUast(ISSUE, declaration, location, "This class implements `Parcelable` but does not " + "provide a `CREATOR` field");
    }
}
Also used : PsiField(com.intellij.psi.PsiField) UAnonymousClass(org.jetbrains.uast.UAnonymousClass) Location(com.android.tools.klint.detector.api.Location)

Aggregations

PsiField (com.intellij.psi.PsiField)86 PsiClass (com.intellij.psi.PsiClass)34 PsiElement (com.intellij.psi.PsiElement)27 ArrayList (java.util.ArrayList)13 PsiMethod (com.intellij.psi.PsiMethod)11 NotNull (org.jetbrains.annotations.NotNull)11 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)8 PsiReference (com.intellij.psi.PsiReference)7 PsiType (com.intellij.psi.PsiType)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 Nullable (org.jetbrains.annotations.Nullable)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpression (com.intellij.psi.PsiExpression)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 ResourceType (com.android.resources.ResourceType)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)4 PsiFile (com.intellij.psi.PsiFile)4