use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class FieldElement method copyElement.
@Override
public ASTNode copyElement() {
final CharTable table = SharedImplUtil.findCharTableByTree(this);
final PsiClass psiClass = ((PsiField) getPsi()).getContainingClass();
return psiClass != null ? ChangeUtil.copyElement(this, psiClass.getTypeParameterList(), table) : super.copyElement();
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class FieldSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
final PsiField field = (PsiField) e;
final TextRange range = field.getTextRange();
final PsiIdentifier first = field.getNameIdentifier();
final TextRange firstRange = first.getTextRange();
final PsiElement last = field.getInitializer();
final int end = last == null ? firstRange.getEndOffset() : last.getTextRange().getEndOffset();
PsiDocComment comment = field.getDocComment();
if (comment != null) {
TextRange commentTextRange = comment.getTextRange();
addRangeElem(result, editorText, comment, commentTextRange.getEndOffset());
}
addRangeElem(result, editorText, first, end);
//addRangeElem (result, editorText, field, textLength, field.getTypeElement(), end);
addRangeElem(result, editorText, field.getModifierList(), range.getEndOffset());
//addRangeElem (result, editorText, field, textLength, field.getDocComment(), end);
result.addAll(expandToWholeLine(editorText, range));
return result;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class GenerateEqualsTestCase method performTest.
private static void performTest(Function<PsiField[], PsiField[]> equals, Function<PsiField[], PsiField[]> hashCode, Function<PsiField[], PsiField[]> nonNull, boolean insertOverride, boolean useAccessors) {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.GENERATE_FINAL_LOCALS = true;
settings.INSERT_OVERRIDE_ANNOTATION = insertOverride;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
try {
PsiElement element = getFile().findElementAt(getEditor().getCaretModel().getOffset());
if (element == null)
return;
PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (aClass == null)
return;
PsiField[] fields = aClass.getFields();
new GenerateEqualsHelper(getProject(), aClass, equals.fun(fields), hashCode.fun(fields), nonNull.fun(fields), false, useAccessors).invoke();
FileDocumentManager.getInstance().saveAllDocuments();
} finally {
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
}
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class WrapReturnValueTest method doTest.
private void doTest(final boolean existing, String exceptionMessage, final boolean createInnerClass) {
try {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
assertNotNull("Class Test not found", aClass);
PsiMethod method = aClass.findMethodsByName("foo", false)[0];
String wrapperClassName = "Wrapper";
PsiClass wrapperClass = myJavaFacade.findClass(wrapperClassName, GlobalSearchScope.projectScope(getProject()));
assertTrue(!existing || wrapperClass != null);
PsiField delegateField = existing ? wrapperClass.findFieldByName("myField", false) : null;
new WrapReturnValueProcessor(wrapperClassName, "", null, method, existing, createInnerClass, delegateField).run();
});
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (exceptionMessage != null) {
assertEquals(exceptionMessage, e.getMessage());
return;
}
throw e;
}
if (exceptionMessage != null) {
fail("Conflict was not found");
}
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class RemoveMiddleManTest method doTest.
private void doTest(final String conflict) throws Exception {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
if (aClass == null)
aClass = myJavaFacade.findClass("p.Test", GlobalSearchScope.allScope(getProject()));
assertNotNull("Class Test not found", aClass);
final PsiField field = aClass.findFieldByName("myField", false);
final Set<PsiMethod> methods = DelegationUtils.getDelegatingMethodsForField(field);
List<MemberInfo> infos = new ArrayList<>();
for (PsiMethod method : methods) {
final MemberInfo info = new MemberInfo(method);
info.setChecked(true);
info.setToAbstract(true);
infos.add(info);
}
try {
RemoveMiddlemanProcessor processor = new RemoveMiddlemanProcessor(field, infos);
processor.run();
LocalFileSystem.getInstance().refresh(false);
FileDocumentManager.getInstance().saveAllDocuments();
if (conflict != null)
fail("Conflict expected");
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (conflict == null)
throw e;
assertEquals(conflict, e.getMessage());
}
});
}
Aggregations