Search in sources :

Example 31 with PsiField

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;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) ASTNode(com.intellij.lang.ASTNode) PsiClass(com.intellij.psi.PsiClass) TextRange(com.intellij.openapi.util.TextRange) CommentFormatter(com.intellij.psi.impl.source.codeStyle.javadoc.CommentFormatter) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with PsiField

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");
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 33 with PsiField

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;
}
Also used : Set(java.util.Set) PsiField(com.intellij.psi.PsiField) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with PsiField

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;
}
Also used : PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) Settings(com.intellij.refactoring.makeStatic.Settings)

Example 35 with PsiField

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);
}
Also used : ScrollingModel(com.intellij.openapi.editor.ScrollingModel) PsiField(com.intellij.psi.PsiField) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiField (com.intellij.psi.PsiField)86 PsiClass (com.intellij.psi.PsiClass)34 PsiElement (com.intellij.psi.PsiElement)27 ArrayList (java.util.ArrayList)13 PsiMethod (com.intellij.psi.PsiMethod)11 NotNull (org.jetbrains.annotations.NotNull)11 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)8 PsiReference (com.intellij.psi.PsiReference)7 PsiType (com.intellij.psi.PsiType)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 Nullable (org.jetbrains.annotations.Nullable)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpression (com.intellij.psi.PsiExpression)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 ResourceType (com.android.resources.ResourceType)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)4 PsiFile (com.intellij.psi.PsiFile)4