use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class InspectionRVContentProviderImpl method checkReportedProblems.
@Override
public boolean checkReportedProblems(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper) {
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
presentation.updateContent();
final SearchScope searchScope = context.getCurrentScope().toSearchScope();
if (searchScope instanceof LocalSearchScope) {
final Map<String, Set<RefEntity>> contents = presentation.getContent();
final Map<RefEntity, CommonProblemDescriptor[]> problemElements = presentation.getProblemElements();
for (Set<RefEntity> entities : contents.values()) {
for (Iterator<RefEntity> iterator = entities.iterator(); iterator.hasNext(); ) {
RefEntity entity = iterator.next();
if (entity instanceof RefElement) {
final PsiElement element = ((RefElement) entity).getElement();
if (element != null) {
final TextRange range = element.getTextRange();
if (range != null && ((LocalSearchScope) searchScope).containsRange(element.getContainingFile(), range)) {
continue;
}
}
}
problemElements.remove(entity);
iterator.remove();
}
}
}
return presentation.hasReportedProblems();
}
use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class DfaPsiUtil method getVariableAssignmentsInFile.
@NotNull
public static Collection<PsiExpression> getVariableAssignmentsInFile(@NotNull PsiVariable psiVariable, final boolean literalsOnly, final PsiElement place) {
Ref<Boolean> modificationRef = Ref.create(Boolean.FALSE);
PsiElement codeBlock = place == null ? null : getTopmostBlockInSameClass(place);
int placeOffset = codeBlock != null ? place.getTextRange().getStartOffset() : 0;
PsiFile containingFile = psiVariable.getContainingFile();
LocalSearchScope scope = new LocalSearchScope(new PsiElement[] { containingFile }, null, true);
Collection<PsiReference> references = ReferencesSearch.search(psiVariable, scope).findAll();
List<PsiExpression> list = ContainerUtil.mapNotNull(references, (NullableFunction<PsiReference, PsiExpression>) psiReference -> {
if (modificationRef.get())
return null;
final PsiElement parent = psiReference.getElement().getParent();
if (parent instanceof PsiAssignmentExpression) {
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression) parent;
final IElementType operation = assignmentExpression.getOperationTokenType();
if (assignmentExpression.getLExpression() == psiReference) {
if (JavaTokenType.EQ.equals(operation)) {
final PsiExpression rValue = assignmentExpression.getRExpression();
if (!literalsOnly || allOperandsAreLiterals(rValue)) {
if (codeBlock != null && PsiTreeUtil.isAncestor(codeBlock, parent, true) && placeOffset < parent.getTextRange().getStartOffset()) {
return null;
}
return rValue;
} else {
modificationRef.set(Boolean.TRUE);
}
} else if (JavaTokenType.PLUSEQ.equals(operation)) {
modificationRef.set(Boolean.TRUE);
}
}
}
return null;
});
if (modificationRef.get())
return Collections.emptyList();
PsiExpression initializer = psiVariable.getInitializer();
if (initializer != null && (!literalsOnly || allOperandsAreLiterals(initializer))) {
list = ContainerUtil.concat(list, Collections.singletonList(initializer));
}
return list;
}
use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class MagicConstantInspection method processValuesFlownTo.
private static boolean processValuesFlownTo(@NotNull final PsiExpression argument, @NotNull PsiElement scope, @NotNull PsiManager manager, @NotNull final Processor<PsiExpression> processor) {
SliceAnalysisParams params = new SliceAnalysisParams();
params.dataFlowToThis = true;
params.scope = new AnalysisScope(new LocalSearchScope(scope), manager.getProject());
SliceRootNode rootNode = new SliceRootNode(manager.getProject(), new DuplicateMap(), LanguageSlicing.getProvider(argument).createRootUsage(argument, params));
Collection<? extends AbstractTreeNode> children = rootNode.getChildren().iterator().next().getChildren();
for (AbstractTreeNode child : children) {
SliceUsage usage = (SliceUsage) child.getValue();
PsiElement element = usage.getElement();
if (element instanceof PsiExpression && !processor.process((PsiExpression) element))
return false;
}
return !children.isEmpty();
}
use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class AllClassesSearchExecutor method execute.
@Override
public boolean execute(@NotNull final AllClassesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
SearchScope scope = queryParameters.getScope();
if (scope instanceof GlobalSearchScope) {
return processAllClassesInGlobalScope((GlobalSearchScope) scope, queryParameters, consumer);
}
PsiElement[] scopeRoots = ((LocalSearchScope) scope).getScope();
for (final PsiElement scopeRoot : scopeRoots) {
if (!processScopeRootForAllClasses(scopeRoot, consumer))
return false;
}
return true;
}
use of com.intellij.psi.search.LocalSearchScope in project intellij-community by JetBrains.
the class ConvertSwitchToIfIntention method dumpBody.
private static void dumpBody(List<PsiElement> bodyStatements, Set<PsiLocalVariable> variables, @NonNls StringBuilder ifStatementString) {
ifStatementString.append('{');
for (PsiLocalVariable variable : variables) {
if (ReferencesSearch.search(variable, new LocalSearchScope(bodyStatements.toArray(new PsiElement[bodyStatements.size()]))).findFirst() != null) {
final PsiType varType = variable.getType();
ifStatementString.append(varType.getCanonicalText());
ifStatementString.append(' ');
ifStatementString.append(variable.getName());
ifStatementString.append(';');
}
}
for (PsiElement bodyStatement : bodyStatements) {
if (bodyStatement instanceof PsiBlockStatement) {
final PsiBlockStatement blockStatement = (PsiBlockStatement) bodyStatement;
final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
final PsiStatement[] statements = codeBlock.getStatements();
for (PsiStatement statement : statements) {
appendElement(statement, ifStatementString);
}
} else {
appendElement(bodyStatement, ifStatementString);
}
}
ifStatementString.append("\n}");
}
Aggregations