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