use of com.intellij.psi.PsiJavaFile in project intellij-plugins by JetBrains.
the class CucumberGotoRelatedFileTest method testGotoRelated.
public void testGotoRelated() {
CucumberStepsIndex.getInstance(getProject()).reset();
myFixture.copyDirectoryToProject("gotoRelated", "");
myFixture.configureByFile("gotoRelated/test.feature");
List<GotoRelatedItem> items = GotoRelatedSymbolAction.getItems(myFixture.getFile(), myFixture.getEditor(), null);
assertEquals(1, items.size());
PsiElement gotoElement = items.get(0).getElement();
assertTrue(gotoElement instanceof PsiJavaFile);
assertEquals("ShoppingStepdefs.java", ((PsiJavaFile) gotoElement).getName());
}
use of com.intellij.psi.PsiJavaFile 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.PsiJavaFile in project android by JetBrains.
the class LombokPsiConverterTest method check.
private static void check(PsiFile psiFile, @Language("JAVA") String source) {
assertTrue(psiFile.getClass().getName(), psiFile instanceof PsiJavaFile);
PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
CompilationUnit node = LombokPsiConverter.convert(psiJavaFile);
assertNotNull(node);
String actualStructure;
if (CHECK_POSITIONS) {
StructureFormatter structureFormatter = StructureFormatter.formatterWithPositions();
node.accept(new SourcePrinter(structureFormatter));
actualStructure = structureFormatter.finish();
}
TextFormatter formatter = new TextFormatter();
node.accept(new SourcePrinter(formatter));
String actual = formatter.finish();
Node expectedNode = parse(source);
assertNotNull(expectedNode);
if (CHECK_POSITIONS) {
StructureFormatter structureFormatter = StructureFormatter.formatterWithPositions();
expectedNode.accept(new SourcePrinter(structureFormatter));
String masterStructure = structureFormatter.finish();
assertEquals(masterStructure, actualStructure);
}
formatter = new TextFormatter();
expectedNode.accept(new SourcePrinter(formatter));
String master = formatter.finish();
assertEquals(master, actual);
// Check for resilience to error nodes being present in the AST
Project project = psiFile.getProject();
final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
final Document document = manager.getDocument(psiFile);
assertNotNull(document);
// fixed seed for test reproducibility
final Random random = new Random(0L);
for (int i = 0; i < 500; i++) {
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
int pos = random.nextInt(document.getTextLength() - 1);
char ch = (char) (random.nextInt(64) + 32);
double operation = random.nextDouble();
if (operation < 0.33) {
document.insertString(pos, Character.toString(ch));
} else if (operation < 0.67) {
document.replaceString(pos, pos + 1, Character.toString(ch));
} else {
document.deleteString(pos, pos + 1);
}
manager.commitDocument(document);
}
});
node = LombokPsiConverter.convert(psiJavaFile);
assertNotNull(psiJavaFile.getText(), node);
}
}
use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.
the class ReplaceFullyQualifiedNameWithImportIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element) {
PsiJavaCodeReferenceElement reference = (PsiJavaCodeReferenceElement) element;
PsiElement target = reference.resolve();
if (!(target instanceof PsiClass)) {
PsiElement parent = reference.getParent();
while (parent instanceof PsiJavaCodeReferenceElement) {
reference = (PsiJavaCodeReferenceElement) parent;
target = reference.resolve();
if (target instanceof PsiClass) {
break;
}
parent = parent.getParent();
}
}
if (!(target instanceof PsiClass)) {
return;
}
final PsiClass aClass = (PsiClass) target;
final String qualifiedName = aClass.getQualifiedName();
if (qualifiedName == null) {
return;
}
final PsiJavaFile file = PsiTreeUtil.getParentOfType(reference, PsiJavaFile.class);
if (file == null) {
return;
}
ImportUtils.addImportIfNeeded(aClass, reference);
final String fullyQualifiedText = reference.getText();
final UnnecessaryFullyQualifiedNameInspection.QualificationRemover qualificationRemover = new UnnecessaryFullyQualifiedNameInspection.QualificationRemover(fullyQualifiedText);
file.accept(qualificationRemover);
final Collection<PsiElement> shortenedElements = qualificationRemover.getShortenedElements();
final int elementCount = shortenedElements.size();
final String text;
if (elementCount == 1) {
text = IntentionPowerPackBundle.message("1.fully.qualified.name.status.bar.escape.highlighting.message");
} else {
text = IntentionPowerPackBundle.message("multiple.fully.qualified.names.status.bar.escape.highlighting.message", Integer.valueOf(elementCount));
}
HighlightUtil.highlightElements(shortenedElements, text);
}
use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.
the class JavaFileEditorManagerTest method testFoldingIsNotBlinkingOnNavigationToSingleLineMethod.
public void testFoldingIsNotBlinkingOnNavigationToSingleLineMethod() {
VirtualFile file = getFile("/src/Bar.java");
PsiJavaFile psiFile = (PsiJavaFile) getPsiManager().findFile(file);
assertNotNull(psiFile);
PsiMethod method = psiFile.getClasses()[0].getMethods()[0];
method.navigate(true);
FileEditor[] editors = myManager.getEditors(file);
assertEquals(1, editors.length);
Editor editor = ((TextEditor) editors[0]).getEditor();
EditorTestUtil.waitForLoading(editor);
FoldRegion[] regions = editor.getFoldingModel().getAllFoldRegions();
assertEquals(2, regions.length);
assertTrue(regions[0].isExpanded());
assertTrue(regions[1].isExpanded());
CodeInsightTestFixtureImpl.instantiateAndRun(psiFile, editor, new int[] { Pass.UPDATE_ALL, Pass.LOCAL_INSPECTIONS }, false);
regions = editor.getFoldingModel().getAllFoldRegions();
assertEquals(2, regions.length);
assertTrue(regions[0].isExpanded());
assertTrue(regions[1].isExpanded());
}
Aggregations