use of ool.intellij.plugin.psi.macro.param.descriptor.JsMacroParamDescriptor in project oxy-template-support-plugin by mutant-industries.
the class JsMacroParamSuggestionProvider method getMacroParamSuggestions.
@NotNull
@Override
protected MacroParamSuggestionSet getMacroParamSuggestions() {
JSParameter[] params;
if ((params = functionExpression.getParameterVariables()).length == 0) {
return MacroParamSuggestionSet.empty();
}
final MacroParamSuggestionSet result = new MacroParamSuggestionSet();
submergedCalls = new LinkedList<>();
String paramsObjectName = params[0].getText();
/**
* !! cannot be done via {@link com.intellij.psi.search.searches.ReferencesSearch.search}, which would in some
* special cases (foreach in foreach) end up in infinite loop - reference search calls type resolver, which makes use of this method
*/
for (PsiElement elementLocal : getParamReferencesLocal(params[0])) {
PsiElement element = elementLocal;
if (!(elementLocal instanceof JSReferenceExpression)) {
continue;
}
if ((elementLocal = elementLocal.getNextSibling()) != null) {
if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
elementLocal = elementLocal.getNextSibling();
}
if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.DOT) {
if ((elementLocal = elementLocal.getNextSibling()) != null) {
if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
elementLocal = elementLocal.getNextSibling();
}
if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
result.add(new JsMacroParamDescriptor(elementLocal.getText(), macro, getJsParamDoc(elementLocal.getText(), macro), true));
}
}
continue;
}
}
JSCallExpression macroCall = getMacroCall(element);
JSReferenceExpression callReference;
if (macroCall == null || (callReference = PsiTreeUtil.getChildOfType(macroCall, JSReferenceExpression.class)) == null || (element = callReference.resolve()) == null) {
continue;
}
submergedCalls.add(element);
}
if (macro.getFirstChild() instanceof JSDocComment) {
String paramName;
PsiReference reference;
PsiElement resolve;
for (JSDocTag docTag : ((JSDocComment) macro.getFirstChild()).getTags()) {
if ((reference = docTag.getReference()) != null && (resolve = reference.resolve()) != null && !params[0].isEquivalentTo(resolve) || (paramName = getCommentParameterName(docTag)) == null) {
continue;
}
paramName = paramName.replaceFirst("^" + paramsObjectName + "\\.", "");
if (result.getByName(paramName) != null) {
continue;
}
result.add(new JsMacroParamDescriptor(paramName, macro, docTag, false));
}
}
return result;
}
Aggregations