use of com.intellij.psi.search.SearchScope in project yii2support by nvlad.
the class ViewUtil method getPhpViewVariables.
@NotNull
public static Collection<String> getPhpViewVariables(PsiFile psiFile) {
final ArrayList<String> result = new ArrayList<>();
final HashSet<String> allVariables = new HashSet<>();
final HashSet<String> declaredVariables = new HashSet<>();
final Collection<Variable> viewVariables = PsiTreeUtil.findChildrenOfType(psiFile, Variable.class);
for (FunctionReference reference : PsiTreeUtil.findChildrenOfType(psiFile, FunctionReference.class)) {
if (reference.getNode().getElementType() == PhpElementTypes.FUNCTION_CALL && psiFile.getUseScope().equals(reference.getUseScope())) {
if (reference.getName() != null && reference.getName().equals("compact")) {
for (PsiElement element : reference.getParameters()) {
if (element instanceof StringLiteralExpression) {
allVariables.add(((StringLiteralExpression) element).getContents());
}
}
}
}
}
final SearchScope fileScope = psiFile.getUseScope();
final HashSet<String> usedBeforeDeclaration = new HashSet<>();
for (Variable variable : viewVariables) {
String variableName = variable.getName();
if (variable.isDeclaration() && fileScope.equals(variable.getUseScope()) && !(variable.getParent() instanceof PhpUseList) && !(variable.getParent() instanceof UnaryExpression) && !(variable.getParent() instanceof SelfAssignmentExpression) && !usedBeforeDeclaration.contains(variableName)) {
declaredVariables.add(variableName);
} else {
if (!ignoredVariables.contains(variableName)) {
if (fileScope.equals(variable.getUseScope()) || variable.getParent() instanceof PhpUseList) {
if (variable.getName().equals("") && variable.getParent() instanceof StringLiteralExpression) {
Variable inlineVariable = PsiTreeUtil.findChildOfType(variable, Variable.class);
if (inlineVariable != null) {
allVariables.add(inlineVariable.getName());
usedBeforeDeclaration.add(variableName);
}
} else {
allVariables.add(variableName);
usedBeforeDeclaration.add(variableName);
}
}
}
}
}
for (String variable : allVariables) {
if (!declaredVariables.contains(variable)) {
result.add(variable);
}
}
return result;
}
use of com.intellij.psi.search.SearchScope in project intellij by bazelbuild.
the class BuildReferenceSearcher method processQuery.
@Override
public void processQuery(SearchParameters params, Processor<PsiReference> consumer) {
PsiElement element = params.getElementToSearch();
if (element instanceof NamedBuildElement) {
String fnName = ((NamedBuildElement) element).getName();
if (fnName != null) {
searchForString(params, element, fnName);
}
return;
}
PsiFile file = ResolveUtil.asFileSearch(element);
if (file != null) {
processFileReferences(params, file);
return;
}
if (!(element instanceof FuncallExpression)) {
return;
}
FuncallExpression funcall = (FuncallExpression) element;
PsiFile localFile = element.getContainingFile();
if (localFile == null) {
return;
}
Label label = funcall.resolveBuildLabel();
if (label == null) {
searchForExternalWorkspace(params, localFile, funcall);
return;
}
List<String> stringsToSearch = LabelUtils.getAllValidLabelStrings(label, true);
for (String string : stringsToSearch) {
if (LabelUtils.isAbsolute(string)) {
searchForString(params, element, string);
} else {
// only a valid reference from local package -- restrict the search scope accordingly
SearchScope scope = limitScopeToFile(params.getScopeDeterminedByUser(), localFile);
if (scope != null) {
searchForString(params, scope, element, string);
}
}
}
}
use of com.intellij.psi.search.SearchScope in project intellij by bazelbuild.
the class BuildReferenceSearcher method processFileReferences.
/**
* Find all references to the given file within BUILD files.
*/
private void processFileReferences(SearchParameters params, PsiFile file) {
if (file instanceof BuildFile) {
BuildFile buildFile = (BuildFile) file;
processBuildFileReferences(params, buildFile);
if (buildFile.getBlazeFileType() == BlazeFileType.BuildPackage) {
return;
}
// for skylark extensions, we also check for package-local references, below
}
BlazePackage blazePackage = BlazePackage.getContainingPackage(file);
PsiDirectory directory = blazePackage != null ? blazePackage.getContainingDirectory() : null;
if (directory == null) {
return;
}
Label label = LabelUtils.createLabelForFile(blazePackage, PsiUtils.getFilePath(file));
if (label == null) {
return;
}
if (!(file instanceof BuildFile)) {
// search globally, for an absolute label reference
String absoluteLabel = String.format("//%s:%s", label.blazePackage(), label.targetName());
searchForString(params, file, absoluteLabel);
}
// search for local references in the containing blaze package
List<String> stringsToSearch = LabelUtils.getAllValidLabelStrings(label, true);
SearchScope scope = params.getScopeDeterminedByUser().intersectWith(blazePackage.getSearchScope(true));
for (String string : stringsToSearch) {
searchForString(params, scope, file, string);
}
}
Aggregations