Search in sources :

Example 36 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class ResolveUtil method treeWalkUp.

public static boolean treeWalkUp(@Nullable PsiElement place, @NotNull PsiScopeProcessor processor) {
    PsiElement lastParent = null;
    PsiElement run = place;
    while (run != null) {
        if (place != run && !run.processDeclarations(processor, ResolveState.initial(), lastParent, place))
            return false;
        lastParent = run;
        run = run.getParent();
    }
    return true;
}
Also used : PsiElement(com.intellij.psi.PsiElement)

Example 37 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoConvertStringToByteQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    if (!(element instanceof GoConditionalExpr) || !element.isValid()) {
        return;
    }
    GoConditionalExpr expr = (GoConditionalExpr) element;
    GoStringLiteral literal = ContainerUtil.findInstance(Arrays.asList(expr.getLeft(), expr.getRight()), GoStringLiteral.class);
    if (literal == null || !isSingleCharLiteral(literal)) {
        return;
    }
    literal.replace(createExpression(project, extractSingleCharFromText(literal)));
}
Also used : GoConditionalExpr(com.goide.psi.GoConditionalExpr) GoStringLiteral(com.goide.psi.GoStringLiteral) PsiElement(com.intellij.psi.PsiElement)

Example 38 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoSimplifyBoolExprQuickFix method removeRedundantExpressions.

private static void removeRedundantExpressions(@NotNull GoBinaryExpr binaryExpr, @NotNull Project project, @NotNull List<GoExpression> expressions, @NotNull List<GoExpression> toRemove, boolean and) {
    for (GoExpression e : toRemove) {
        expressions.remove(e);
    }
    String separator = and ? " && " : " || ";
    String text = StringUtil.join(expressions, PsiElement::getText, separator);
    GoExpression expression = GoElementFactory.createExpression(project, text);
    binaryExpr.replace(expression);
}
Also used : GoExpression(com.goide.psi.GoExpression) LocalQuickFixOnPsiElement(com.intellij.codeInspection.LocalQuickFixOnPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 39 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoAnonymousFieldProcessor method prepareRenaming.

@Override
public void prepareRenaming(PsiElement element, String newName, @NotNull Map<PsiElement, String> allRenames, @NotNull SearchScope scope) {
    if (element instanceof GoTypeSpec) {
        Query<PsiReference> search = ReferencesSearch.search(element, scope);
        for (PsiReference ref : search) {
            PsiElement refElement = ref.getElement();
            PsiElement type = refElement == null ? null : refElement.getParent();
            if (!(type instanceof GoType))
                continue;
            PsiElement typeParent = type.getParent();
            GoPointerType pointer = ObjectUtils.tryCast(typeParent, GoPointerType.class);
            PsiElement anon = pointer != null ? pointer.getParent() : typeParent;
            if (anon instanceof GoAnonymousFieldDefinition) {
                allRenames.put(anon, newName);
            }
        }
    } else if (element instanceof GoAnonymousFieldDefinition) {
        GoTypeReferenceExpression reference = ((GoAnonymousFieldDefinition) element).getTypeReferenceExpression();
        PsiElement resolve = reference != null ? reference.resolve() : null;
        if (resolve instanceof GoTypeSpec) {
            allRenames.put(resolve, newName);
        }
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 40 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunUtil method getContextElement.

@Nullable
public static PsiElement getContextElement(@Nullable ConfigurationContext context) {
    if (context == null) {
        return null;
    }
    PsiElement psiElement = context.getPsiLocation();
    if (psiElement == null || !psiElement.isValid()) {
        return null;
    }
    FileIndexFacade indexFacade = FileIndexFacade.getInstance(psiElement.getProject());
    PsiFileSystemItem psiFile = psiElement instanceof PsiFileSystemItem ? (PsiFileSystemItem) psiElement : psiElement.getContainingFile();
    VirtualFile file = psiFile != null ? psiFile.getVirtualFile() : null;
    if (file != null && file.getFileType() != ScratchFileType.INSTANCE && (!indexFacade.isInContent(file) || indexFacade.isExcludedFile(file))) {
        return null;
    }
    return psiElement;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) Nullable(org.jetbrains.annotations.Nullable)

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