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;
}
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)));
}
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);
}
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);
}
}
}
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;
}
Aggregations