use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class FieldNode method toString.
public String toString() {
final PsiField field = (PsiField) getPsiElement();
if (field == null || !field.isValid())
return "";
String name = PsiFormatUtil.formatVariable(field, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER | PsiFormatUtil.SHOW_INITIALIZER, PsiSubstitutor.EMPTY);
int c = name.indexOf('\n');
if (c > -1) {
name = name.substring(0, c - 1);
}
return name;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class StructureViewUpdatingTest method testShowClassMembers.
public void testShowClassMembers() throws Exception {
final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
final FileEditor fileEditor = fileEditors[0];
final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
try {
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + " -Class2\n" + " +InnerClass1\n" + " +InnerClass2\n" + " getValue(): int\n" + " myField1: boolean\n" + " myField2: boolean\n" + " myField3: boolean\n" + " myField4: boolean\n");
final PsiField innerClassField = psiClass.getInnerClasses()[0].getFields()[0];
structureViewComponent.select(innerClassField, true);
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + " -Class2\n" + " -InnerClass1\n" + " +InnerClass12\n" + " myInnerClassField: int\n" + " +InnerClass2\n" + " getValue(): int\n" + " myField1: boolean\n" + " myField2: boolean\n" + " myField3: boolean\n" + " myField4: boolean\n");
CommandProcessor.getInstance().executeCommand(myProject, () -> WriteCommandAction.runWriteCommandAction(null, () -> {
try {
innerClassField.delete();
} catch (IncorrectOperationException e) {
fail(e.getLocalizedMessage());
}
}), null, null);
PlatformTestUtil.waitForAlarm(600);
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + " -Class2\n" + " -InnerClass1\n" + " +InnerClass12\n" + " +InnerClass2\n" + " getValue(): int\n" + " myField1: boolean\n" + " myField2: boolean\n" + " myField3: boolean\n" + " myField4: boolean\n");
} finally {
Disposer.dispose(structureViewComponent);
fileEditorManager.closeFile(virtualFile);
}
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class ProjectTreeBuilderTest method testShowClassMembers.
public void testShowClassMembers() throws IncorrectOperationException, IOException {
myStructure.setShowMembers(true);
useStandardProviders();
final PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(getPackageDirectory());
sortClassesByName(classes);
PsiClass aClass = classes[1];
PsiClass innerClass1 = aClass.getInnerClasses()[0];
PsiClass innerClass12 = innerClass1.getInnerClasses()[0];
PsiClass innerClass13 = innerClass12.getInnerClasses()[0];
PsiClass innerClass14 = innerClass13.getInnerClasses()[0];
PsiClass innerClass15 = innerClass14.getInnerClasses()[0];
PsiClass innerClass2 = aClass.getInnerClasses()[1];
PsiClass innerClass21 = innerClass2.getInnerClasses()[0];
PsiClass innerClass23 = innerClass21.getInnerClasses()[0];
PsiClass innerClass24 = innerClass23.getInnerClasses()[0];
PsiField innerClass1Field = innerClass14.getFields()[0];
PsiField innerClass2Field = innerClass24.getFields()[0];
final AbstractProjectViewPSIPane pane = myStructure.createPane();
myStructure.checkNavigateFromSourceBehaviour(innerClass2Field, innerClass2Field.getContainingFile().getVirtualFile(), pane);
IdeaTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: showClassMembers\n" + " -PsiDirectory: src\n" + " -PsiDirectory: com\n" + " -PsiDirectory: package1\n" + " +Class1\n" + " -Class2\n" + " +InnerClass1\n" + " -InnerClass2\n" + " -InnerClass22\n" + " -InnerClass23\n" + " -InnerClass24\n" + " +InnerClass25\n" + " myFieldToSelect:int\n" + " myInnerClassField:int\n" + " myInnerClassField:int\n" + " myInnerClassField:int\n" + " getValue():int\n" + " myField1:boolean\n" + " myField2:boolean\n" + " myField3:boolean\n" + " myField4:boolean\n" + getRootFiles() + " +External Libraries\n");
assertFalse(ProjectViewTestUtil.isExpanded(innerClass15.getFields()[0], pane));
assertFalse(ProjectViewTestUtil.isExpanded(innerClass1Field, pane));
assertTrue(ProjectViewTestUtil.isExpanded(innerClass2Field, pane));
VirtualFile virtualFile = aClass.getContainingFile().getVirtualFile();
FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
StructureViewComponent structureViewComponent2 = null;
StructureViewComponent structureViewComponent = null;
try {
structureViewComponent = (StructureViewComponent) fileEditors[0].getStructureViewBuilder().createStructureView(fileEditors[0], myProject);
TreeUtil.collapseAll(structureViewComponent.getTree(), -1);
structureViewComponent.select(innerClass2Field, true);
String expected = "-Class2.java\n" + " -Class2\n" + " +InnerClass1\n" + " -InnerClass2\n" + " -InnerClass22\n" + " -InnerClass23\n" + " -InnerClass24\n" + " +InnerClass25\n" + " myFieldToSelect: int\n" + " myInnerClassField: int\n" + " myInnerClassField: int\n" + " myInnerClassField: int\n" + " getValue(): int\n" + " myField1: boolean\n" + " myField2: boolean\n" + " myField3: boolean\n" + " myField4: boolean\n";
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), expected);
Disposer.dispose(structureViewComponent);
final FileEditor fileEditor = fileEditors[0];
structureViewComponent2 = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
structureViewComponent2.setActionActive(JavaInheritedMembersNodeProvider.ID, false);
IdeaTestUtil.assertTreeEqual(structureViewComponent2.getTree(), expected);
} finally {
fileEditorManager.closeFile(virtualFile);
if (structureViewComponent2 != null) {
Disposer.dispose(structureViewComponent2);
}
}
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class JUnitRuleInspection method buildVisitor.
@Override
public BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitField(PsiField field) {
final boolean ruleAnnotated = REPORT_RULE_PROBLEMS && AnnotationUtil.isAnnotated(field, RULE_FQN, false);
final boolean classRuleAnnotated = REPORT_CLASS_RULE_PROBLEMS && AnnotationUtil.isAnnotated(field, CLASS_RULE_FQN, false);
if (ruleAnnotated || classRuleAnnotated) {
String annotation = ruleAnnotated ? RULE_FQN : CLASS_RULE_FQN;
String errorMessage = getPublicStaticErrorMessage(field, ruleAnnotated, classRuleAnnotated);
if (errorMessage != null) {
registerError(field.getNameIdentifier(), InspectionGadgetsBundle.message("junit.rule.problem.descriptor", annotation, errorMessage), "Make field " + errorMessage, annotation);
}
final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(field.getType());
if (!InheritanceUtil.isInheritor(aClass, false, "org.junit.rules.TestRule") && !InheritanceUtil.isInheritor(aClass, false, "org.junit.rules.MethodRule")) {
registerError(field.getNameIdentifier(), InspectionGadgetsBundle.message("junit.rule.type.problem.descriptor"));
}
}
}
};
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class AtomicFieldUpdaterNotStaticFinalInspection method buildErrorString.
@NotNull
@Override
protected String buildErrorString(Object... infos) {
final PsiField field = (PsiField) infos[0];
final PsiType type = field.getType();
final String typeText = type.getPresentableText();
return InspectionGadgetsBundle.message("atomic.field.updater.not.static.final.problem.descriptor", typeText);
}
Aggregations