use of ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet in project oxy-template-support-plugin by mutant-industries.
the class JavaMacroParamSuggestionProvider method getParamsPulledFromParamHelper.
private MacroParamSuggestionSet getParamsPulledFromParamHelper(PsiLocalVariable paramHelper) {
MacroParamSuggestionSet params = new MacroParamSuggestionSet();
PsiReferenceExpression methodReference;
for (PsiReference reference : ReferencesSearch.search(paramHelper).findAll()) {
if ((methodReference = PsiTreeUtil.getParentOfType(reference.getElement(), PsiReferenceExpression.class)) != null) {
String parameterName = null;
boolean required = false;
boolean notNull = true;
String type = JSCommonTypeNames.ANY_TYPE_NAME;
String defaultValue = null;
while (methodReference != null) {
if (!(methodReference.getParent() instanceof PsiMethodCallExpression) || methodReference.getReferenceName() == null) {
break;
}
PsiMethodCallExpression callExpression = (PsiMethodCallExpression) methodReference.getParent();
PsiExpression[] expressions = callExpression.getArgumentList().getExpressions();
if (expressions.length == 0) {
break;
}
switch(methodReference.getReferenceName()) {
case "parameter":
case "pullParameter":
parameterName = getExpressionValue(expressions[0]);
if (expressions.length == 2 && expressions[1].getFirstChild() instanceof PsiTypeElement) {
type = InnerJsJavaTypeConverter.modifyCollectionType(((PsiTypeElement) expressions[1].getFirstChild()).getType(), paramHelper.getProject());
}
break;
case "pullIntegerValue":
parameterName = getExpressionValue(expressions[0]);
notNull = expressions.length < 2;
required = expressions.length < 2;
type = JSCommonTypeNames.NUMBER_TYPE_NAME;
if (expressions.length == 2) {
defaultValue = getExpressionValue(expressions[1]);
}
break;
case "pullBooleanValue":
parameterName = getExpressionValue(expressions[0]);
notNull = false;
required = false;
type = JSCommonTypeNames.BOOLEAN_TYPE_NAME;
if (expressions.length == 2) {
defaultValue = getExpressionValue(expressions[1]);
}
break;
case "setNonNull":
notNull = Boolean.valueOf(expressions[0].getText());
break;
case "setRequired":
required = Boolean.valueOf(expressions[0].getText());
break;
}
methodReference = PsiTreeUtil.getParentOfType(methodReference, PsiReferenceExpression.class);
}
if (parameterName != null) {
params.add(new JavaMacroParamDescriptor(parameterName, macro, notNull, required, type, defaultValue));
}
}
// TODO the case when object is passed to another method
}
return params;
}
use of ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet in project oxy-template-support-plugin by mutant-industries.
the class JavaMacroParamSuggestionProvider method getMacroParamSuggestions.
@NotNull
@Override
protected MacroParamSuggestionSet getMacroParamSuggestions() {
MacroParamSuggestionSet params = new MacroParamSuggestionSet();
PsiMethod[] methods = macro.findMethodsByName("execute", true);
PsiMethod executeMethod;
PsiParameter eventParam;
// current and / or superclass(es) + interface method
if (methods.length < 2 || (executeMethod = methods[0]).getParameterList().getParametersCount() < 1 || (eventParam = executeMethod.getParameterList().getParameters()[0]) == null || !eventParam.getType().equalsToText(MACRO_EVENT_FQN)) {
return params;
}
for (PsiReference reference : ReferencesSearch.search(eventParam).findAll()) {
PsiLocalVariable localVariable = PsiTreeUtil.getParentOfType(reference.getElement(), PsiLocalVariable.class);
if (localVariable == null || !localVariable.getType().equalsToText(MACRO_PARAM_HELPER_FQN)) {
continue;
}
// TODO the case when object is passed to another method
params.addAll(getParamsPulledFromParamHelper(localVariable));
}
return params;
}
use of ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet in project oxy-template-support-plugin by mutant-industries.
the class ParamSuggestionProvider method compute.
@Nullable
@Override
public Result<MacroParamSuggestionSet> compute() {
MacroParamSuggestionSet macroParamSuggestions = getMacroParamSuggestions();
Set<PsiElement> cacheDependencies = new HashSet<>();
for (MacroParamDescriptor descriptor : macroParamSuggestions) {
if (descriptor.getType() == null) {
continue;
}
SimplifiedClassNameResolver simplifiedClassNameResolver = new SimplifiedClassNameResolver(macro.getContainingFile());
descriptor.getType().accept(simplifiedClassNameResolver);
cacheDependencies.addAll(simplifiedClassNameResolver.getResolvedClassList());
}
cacheDependencies.addAll(this.cacheDependencies);
return Result.create(macroParamSuggestions, cacheDependencies);
}
use of ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet in project oxy-template-support-plugin by mutant-industries.
the class MacroParamDocumentationProvider method generateJsMacroDocumentation.
private static String generateJsMacroDocumentation(@NotNull JSProperty macro) {
JSDocComment comment;
MacroParamSuggestionSet paramDescriptors = MacroParamHelper.getJsMacroParamSuggestions(macro, false);
String qualifiedName = OxyTemplateIndexUtil.getMacroFullyQualifiedName(macro);
assert qualifiedName != null;
StringBuilder result = new StringBuilder();
result.append("<PRE><b>").append(qualifiedName).append("</b>( [ optional ] params )\n</PRE> ");
if ((comment = JSStubBasedPsiTreeUtil.findDocComment(macro)) != null) {
JSDocPlainCommentBuilder builder = new JSDocPlainCommentBuilder();
JSDocumentationUtils.processDocumentationTextFromComment(comment.getNode(), builder);
String doc = builder.getDoc().trim();
if (doc.length() > 0) {
result.append(doc).append("<br/>");
}
}
if (paramDescriptors.size() != 0) {
result.append("<br/><b>").append(I18nSupport.message("macro.param.block.heading")).append("</b><ul>");
for (MacroParamDescriptor descriptor : paramDescriptors) {
result.append("<li>").append(descriptor.getName()).append(" ").append(descriptor.generateTypeInfo());
if (!StringUtil.isEmpty(descriptor.getDocText())) {
result.append(" - ").append(descriptor.getDocText());
}
result.append("</li>");
}
result.append("</ul>");
}
return result.toString();
}
use of ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet 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