use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class FormatCommentsProcessor method formatCommentsInner.
/**
* Formats PsiDocComments of current ASTNode element and all his children PsiDocComments
*/
@NotNull
private static TextRange formatCommentsInner(@NotNull Project project, @NotNull ASTNode element, @NotNull final TextRange markedRange) {
TextRange resultTextRange = markedRange;
final PsiElement elementPsi = element.getPsi();
boolean shouldFormat = markedRange.contains(element.getTextRange());
if (shouldFormat) {
final ASTNode rangeAnchor;
// its parent.
if (elementPsi instanceof PsiDocComment) {
rangeAnchor = element.getTreeParent();
} else {
rangeAnchor = element;
}
TextRange before = rangeAnchor.getTextRange();
new CommentFormatter(project).processComment(element);
int deltaRange = rangeAnchor.getTextRange().getLength() - before.getLength();
resultTextRange = new TextRange(markedRange.getStartOffset(), markedRange.getEndOffset() + deltaRange);
}
// If element is out of range its children are also out of range. So in both cases formatting is finished. It's just for optimization.
if ((shouldFormat && (elementPsi instanceof PsiMethod || elementPsi instanceof PsiField || elementPsi instanceof PsiDocComment)) || markedRange.getEndOffset() < element.getStartOffset()) {
return resultTextRange;
}
ASTNode current = element.getFirstChildNode();
while (current != null) {
// When element is PsiClass its PsiDocComment is formatted up to this moment, so we didn't need to format it again.
if (!(shouldFormat && current.getPsi() instanceof PsiDocComment && elementPsi instanceof PsiClass)) {
resultTextRange = formatCommentsInner(project, current, resultTextRange);
}
current = current.getTreeNext();
}
return resultTextRange;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class PushDownMultifileTest method testUsagesInXml.
public void testUsagesInXml() throws Exception {
try {
doTest((rootDir, rootAfter) -> {
final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
assertTrue("Source class not found", srcClass != null);
final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
assertTrue("Target class not found", targetClass != null);
final PsiField[] fields = srcClass.getFields();
assertTrue("No methods found", fields.length > 0);
final MemberInfo memberInfo = new MemberInfo(fields[0]);
memberInfo.setChecked(true);
new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
//LocalFileSystem.getInstance().refresh(false);
//FileDocumentManager.getInstance().saveAllDocuments();
});
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
assertEquals(e.getMessage(), "Class <b><code>b.B</code></b> is package-private and will not be accessible from file <b><code>A.form</code></b>.");
return;
}
fail("Conflict was not detected");
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class FieldDependenciesManager method getRoots.
@NotNull
public List<ArrangementEntryDependencyInfo> getRoots() {
List<ArrangementEntryDependencyInfo> list = ContainerUtil.newArrayList();
for (Map.Entry<PsiField, Set<PsiField>> entry : myFieldDependencies.entrySet()) {
ArrangementEntryDependencyInfo currentInfo = myFieldInfosMap.get(entry.getKey());
for (PsiField usedInInitialization : entry.getValue()) {
ArrangementEntryDependencyInfo fieldInfo = myFieldInfosMap.get(usedInInitialization);
if (fieldInfo != null)
currentInfo.addDependentEntryInfo(fieldInfo);
}
list.add(currentInfo);
}
return list;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class MakeMethodStaticRefactoringImpl method getFields.
public List<PsiField> getFields() {
final Settings settings = myProcessor.getSettings();
List<PsiField> result = new ArrayList<>();
final List<Settings.FieldParameter> parameterOrderList = settings.getParameterOrderList();
for (final Settings.FieldParameter fieldParameter : parameterOrderList) {
result.add(fieldParameter.field);
}
return result;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class RemoveMiddlemanHandler method invoke.
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
final ScrollingModel scrollingModel = editor.getScrollingModel();
scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
if (!(element instanceof PsiField)) {
CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.field.to.be.refactored"), REFACTORING_NAME, getHelpID());
return;
}
invoke((PsiField) element, editor);
}
Aggregations