Search in sources :

Example 11 with PsiIdentifier

use of com.intellij.psi.PsiIdentifier in project android by JetBrains.

the class AndroidLineMarkerProvider method getMarkerInfo.

@Nullable
private static MyMarkerInfo getMarkerInfo(@NotNull PsiElement element) {
    if (!(element instanceof XmlFile) && !(element instanceof PsiJavaFile)) {
        return null;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(element);
    if (facet == null) {
        return null;
    }
    if (element instanceof PsiJavaFile) {
        final PsiClass[] classes = ((PsiJavaFile) element).getClasses();
        if (classes.length == 1) {
            final PsiClass aClass = classes[0];
            final PsiIdentifier nameIdentifier = aClass.getNameIdentifier();
            if (nameIdentifier != null) {
                final Computable<List<GotoRelatedItem>> computable = AndroidGotoRelatedProvider.getLazyItemsForClass(aClass, facet, true);
                return computable != null ? new MyMarkerInfo(nameIdentifier, computable, "Related XML file", AllIcons.FileTypes.Xml) : null;
            }
        }
    } else {
        final XmlTag rootTag = ((XmlFile) element).getRootTag();
        final Computable<List<GotoRelatedItem>> computable = AndroidGotoRelatedProvider.getLazyItemsForXmlFile((XmlFile) element, facet);
        return computable != null ? new MyMarkerInfo(rootTag != null ? rootTag : element, computable, "Related context Java file", AllIcons.Nodes.Class) : null;
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiClass(com.intellij.psi.PsiClass) PsiIdentifier(com.intellij.psi.PsiIdentifier) PsiJavaFile(com.intellij.psi.PsiJavaFile) List(java.util.List) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with PsiIdentifier

use of com.intellij.psi.PsiIdentifier in project android by JetBrains.

the class ParcelableQuickFixTest method doTestApply.

private void doTestApply(@NotNull ParcelableQuickFix.Operation operation, @NotNull String source, @NotNull String expected, @NotNull String className) {
    PsiFile file = myFixture.addFileToProject(String.format("src/com/example/%s.java", className), source);
    final PsiIdentifier identifier = findClassIdentifier(file, className);
    final ParcelableQuickFix fix = new ParcelableQuickFix("Fix Parcelable", operation);
    assertTrue(fix.isApplicable(identifier, identifier, AndroidQuickfixContexts.DesignerContext.TYPE));
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            fix.apply(identifier, identifier, AndroidQuickfixContexts.DesignerContext.getInstance());
        }
    }.execute();
    Document document = FileDocumentManager.getInstance().getDocument(file.getVirtualFile());
    assert document != null;
    String actual = document.getText();
    String diff = lineDiff(actual, expected);
    assertTrue(diff, diff.isEmpty());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PsiIdentifier(com.intellij.psi.PsiIdentifier) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) Result(com.intellij.openapi.application.Result)

Aggregations

PsiIdentifier (com.intellij.psi.PsiIdentifier)12 PsiClass (com.intellij.psi.PsiClass)6 Nullable (org.jetbrains.annotations.Nullable)5 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)4 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 RefClass (com.intellij.codeInspection.reference.RefClass)2 RefEntity (com.intellij.codeInspection.reference.RefEntity)2 RefPackage (com.intellij.codeInspection.reference.RefPackage)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 NotNull (org.jetbrains.annotations.NotNull)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 GlobalInspectionTool (com.intellij.codeInspection.GlobalInspectionTool)1 LocalInspectionToolSession (com.intellij.codeInspection.LocalInspectionToolSession)1 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 RefModule (com.intellij.codeInspection.reference.RefModule)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Document (com.intellij.openapi.editor.Document)1