Search in sources :

Example 76 with PsiElement

use of com.intellij.psi.PsiElement in project buck by facebook.

the class BuckBuildUtil method extractBuckTarget.

/**
   * Get the buck target from a buck file.
   * TODO(#7908675): We should use Buck's own classes for it.
   */
public static String extractBuckTarget(Project project, VirtualFile file) {
    BuckFile buckFile = (BuckFile) PsiManager.getInstance(project).findFile(file);
    if (buckFile == null) {
        return null;
    }
    PsiElement[] children = buckFile.getChildren();
    for (PsiElement child : children) {
        if (child.getNode().getElementType() == BuckTypes.RULE_BLOCK) {
            PsiElement ruleName = child.getFirstChild();
            // Find rule "project_config"
            if (ruleName != null && BuckPsiUtils.testType(ruleName, BuckTypes.RULE_NAME) && ruleName.getText().equals(PROJECT_CONFIG_RULE_NAME)) {
                // Find property "src_target"
                PsiElement bodyElement = BuckPsiUtils.findChildWithType(child, BuckTypes.RULE_BODY);
                return getPropertyValue((BuckRuleBody) bodyElement, SRC_TARGET_PROPERTY_NAME);
            }
        }
    }
    return null;
}
Also used : BuckFile(com.facebook.buck.intellij.ideabuck.lang.BuckFile) PsiElement(com.intellij.psi.PsiElement)

Example 77 with PsiElement

use of com.intellij.psi.PsiElement in project buck by facebook.

the class BuckFormattingModelBuilder method getRangeAffectingIndent.

@Nullable
@Override
public TextRange getRangeAffectingIndent(PsiFile file, int offset, ASTNode elementAtOffset) {
    final PsiElement element = elementAtOffset.getPsi();
    final PsiElement container = element.getParent();
    return container != null ? container.getTextRange() : null;
}
Also used : PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 78 with PsiElement

use of com.intellij.psi.PsiElement in project buck by facebook.

the class DependenciesOptimizer method optimzeDeps.

public static void optimzeDeps(@NotNull PsiFile file) {
    final PropertyVisitor visitor = new PropertyVisitor();
    file.accept(new BuckVisitor() {

        @Override
        public void visitElement(PsiElement node) {
            node.acceptChildren(this);
            node.accept(visitor);
        }
    });
    // Commit modifications.
    final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());
    manager.doPostponedOperationsAndUnblockDocument(manager.getDocument(file));
}
Also used : BuckVisitor(com.facebook.buck.intellij.ideabuck.lang.psi.BuckVisitor) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 79 with PsiElement

use of com.intellij.psi.PsiElement in project android-parcelable-intellij-plugin by mcharmas.

the class ParcelableAction method getPsiClassFromContext.

private PsiClass getPsiClassFromContext(AnActionEvent e) {
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (psiFile == null || editor == null) {
        return null;
    }
    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);
    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
Also used : PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 80 with PsiElement

use of com.intellij.psi.PsiElement in project qi4j-sdk by Qi4j.

the class AbstractIntention method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    if (isFileReadOnly(project, file)) {
        return;
    }
    final PsiElement element = findMatchingElement(file, editor);
    if (element == null) {
        return;
    }
    processIntention(project, editor, element);
}
Also used : PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3198 Nullable (org.jetbrains.annotations.Nullable)493 PsiFile (com.intellij.psi.PsiFile)474 NotNull (org.jetbrains.annotations.NotNull)442 TextRange (com.intellij.openapi.util.TextRange)239 PsiReference (com.intellij.psi.PsiReference)227 Project (com.intellij.openapi.project.Project)222 VirtualFile (com.intellij.openapi.vfs.VirtualFile)210 ArrayList (java.util.ArrayList)195 ASTNode (com.intellij.lang.ASTNode)142 XmlTag (com.intellij.psi.xml.XmlTag)134 PsiClass (com.intellij.psi.PsiClass)115 Editor (com.intellij.openapi.editor.Editor)112 Document (com.intellij.openapi.editor.Document)109 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)85 PsiDirectory (com.intellij.psi.PsiDirectory)80 IElementType (com.intellij.psi.tree.IElementType)78 Module (com.intellij.openapi.module.Module)77 PsiMethod (com.intellij.psi.PsiMethod)73 UsageInfo (com.intellij.usageView.UsageInfo)70