use of com.intellij.lang.javascript.psi.JSFunctionExpression in project oxy-template-support-plugin by mutant-industries.
the class InnerJsTypeEvaluator method checkMacroFirstParameter.
/**
* @param parameter
* @return macro, if parameter is its first parameter, null otherwise
*/
@Nullable
private static JSProperty checkMacroFirstParameter(@Nullable JSParameter parameter) {
JSProperty macro;
JSFunctionExpression functionExpression;
if ((macro = PsiTreeUtil.getParentOfType(parameter, JSProperty.class)) != null && OxyTemplateIndexUtil.isMacro(macro) && macro.getLastChild() instanceof JSFunctionExpression) {
functionExpression = (JSFunctionExpression) macro.getLastChild();
if (functionExpression.getParameters().length > 0 && functionExpression.getParameters()[0].isEquivalentTo(parameter)) {
return macro;
}
}
return null;
}
use of com.intellij.lang.javascript.psi.JSFunctionExpression in project oxy-template-support-plugin by mutant-industries.
the class JsMacroParamSuggestionProvider method getParamReferencesLocal.
@NotNull
private Collection<PsiElement> getParamReferencesLocal(@NotNull JSParameter param) {
List<PsiElement> result = new LinkedList<>();
JSFunctionExpression function = (JSFunctionExpression) macro.getLastChild();
PsiFile file = macro.getContainingFile();
Matcher matcher = Pattern.compile(param.getText()).matcher(function.getText());
JSReferenceExpression referenceExpression;
PsiElement resolve;
while (matcher.find()) {
PsiElement elementAt = file.findElementAt(function.getNode().getStartOffset() + matcher.start());
if (elementAt != null && (referenceExpression = PsiTreeUtil.getParentOfType(elementAt, JSReferenceExpression.class)) != null && (resolve = referenceExpression.resolve()) != null && resolve.isEquivalentTo(param)) {
result.add(referenceExpression);
}
}
return result;
}
use of com.intellij.lang.javascript.psi.JSFunctionExpression in project oxy-template-support-plugin by mutant-industries.
the class JsMacroParamSuggestionProvider method getJsParamDoc.
@Nullable
private static JSDocTag getJsParamDoc(@NotNull String paramName, @NotNull JSProperty macro) {
JSFunctionExpression functionExpression = (JSFunctionExpression) macro.getLastChild();
JSDocComment docComment;
JSParameter[] referenceParams;
if (!(macro.getFirstChild() instanceof JSDocComment) || (referenceParams = functionExpression.getParameterVariables()).length == 0) {
return null;
}
String docParamExpectedName = referenceParams[0].getText() + '.' + paramName;
docComment = (JSDocComment) macro.getFirstChild();
String commentParameterName;
for (JSDocTag docTag : docComment.getTags()) {
if ((commentParameterName = getCommentParameterName(docTag)) == null) {
continue;
}
if (paramName.equals(commentParameterName) || docParamExpectedName.equals(commentParameterName)) {
return docTag;
}
}
return null;
}
use of com.intellij.lang.javascript.psi.JSFunctionExpression in project oxy-template-support-plugin by mutant-industries.
the class JsMacroNameDataIndexer method map.
@Override
@NotNull
public Map<String, JsMacroNameIndexedElement> map(@NotNull final FileContent inputData) {
PsiFile jsFile = inputData.getPsiFile().getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE);
Map<String, JsMacroNameIndexedElement> result = new HashMap<>();
for (PsiElement psiElement : jsFile.getChildren()) {
if (psiElement instanceof JSExpressionStatement && (psiElement = PsiTreeUtil.getChildOfAnyType(psiElement, JSAssignmentExpression.class)) != null && psiElement.getFirstChild() instanceof JSDefinitionExpression) {
String rootNamespace = psiElement.getFirstChild().getText().replace(MACRO_REGISTRY_NAMESPACE + ".", "");
boolean firstIteration = true;
for (JSReferenceExpression ref : PsiTreeUtil.findChildrenOfType(psiElement.getFirstChild(), JSReferenceExpression.class)) {
String namespace = ref.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", "");
if (!namespace.equals(DEFAULT_NAMESPACE) && !namespace.equals(MACRO_REGISTRY_NAMESPACE)) {
result.put(ref.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", ""), new JsMacroNameIndexedElement(firstIteration && psiElement.getLastChild() instanceof JSFunctionExpression, ref.getTextOffset() + ref.getTextLength() - 1));
}
firstIteration = false;
}
if (psiElement.getLastChild() instanceof JSObjectLiteralExpression) {
processObjectLiteralExpression((JSObjectLiteralExpression) psiElement.getLastChild(), rootNamespace, result);
}
}
}
return result;
}
use of com.intellij.lang.javascript.psi.JSFunctionExpression in project oxy-template-support-plugin by mutant-industries.
the class JsMacroNameDataIndexer method processObjectLiteralExpression.
private static void processObjectLiteralExpression(@NotNull JSObjectLiteralExpression expression, @NotNull String namespace, @NotNull Map<String, JsMacroNameIndexedElement> result) {
for (JSProperty property : expression.getProperties()) {
PsiElement nameIdentifier = property.getNameIdentifier();
if (nameIdentifier == null) {
continue;
}
if (property.getLastChild() instanceof JSObjectLiteralExpression) {
result.put(namespace + "." + nameIdentifier.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", ""), new JsMacroNameIndexedElement(nameIdentifier.getTextOffset() + nameIdentifier.getTextLength() - 1));
processObjectLiteralExpression((JSObjectLiteralExpression) property.getLastChild(), namespace + "." + property.getName(), result);
} else if (property.getLastChild() instanceof JSFunctionExpression) {
result.put(namespace + "." + nameIdentifier.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", ""), new JsMacroNameIndexedElement(true, nameIdentifier.getTextOffset() + nameIdentifier.getTextLength() - 1));
}
}
}
Aggregations