use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project oxy-template-support-plugin by mutant-industries.
the class InnerJsReferenceExpressionResolver method superResolveInPsiClassModified.
/**
* modified supertype method, fixes the following issue: https://youtrack.jetbrains.com/issue/IDEA-138078
*
* @param aClass
* @param isStatic
* @return
*/
@NotNull
private List<ResolveResult> superResolveInPsiClassModified(PsiClass aClass, boolean isStatic) {
SmartList<ResolveResult> results = new SmartList<>();
Object candidates;
Object field;
if (myParent instanceof JSCallExpression) {
candidates = aClass.findMethodsByName(myReferencedName, true);
} else {
field = aClass.findInnerClassByName(myReferencedName, true);
if (field == null) {
boolean inDefinitionExpr = myParent instanceof JSDefinitionExpression;
String prefix = inDefinitionExpr ? "set" : "get";
String candidate = prefix + StringUtil.capitalize(myReferencedName);
PsiMethod[] hasStaticModifier = aClass.findMethodsByName(candidate, true);
PsiMethod[] resolveProblem = hasStaticModifier;
int resolveResult = hasStaticModifier.length;
for (int i$1 = 0; i$1 < resolveResult; ++i$1) {
PsiMethod accessor = resolveProblem[i$1];
int parametersCount = accessor.getParameterList().getParametersCount();
if (parametersCount == (inDefinitionExpr ? 1 : 0)) {
field = accessor;
break;
}
}
if (field == null && !inDefinitionExpr) {
prefix = "is";
candidate = prefix + StringUtil.capitalize(myReferencedName);
hasStaticModifier = aClass.findMethodsByName(candidate, true);
resolveProblem = hasStaticModifier;
resolveResult = hasStaticModifier.length;
for (int i$1 = 0; i$1 < resolveResult; ++i$1) {
PsiMethod accessor = resolveProblem[i$1];
int parametersCount = accessor.getParameterList().getParametersCount();
if (parametersCount == 0) {
field = accessor;
break;
}
}
}
}
if (field == null) {
field = aClass.findFieldByName(myReferencedName, true);
}
candidates = field != null ? new PsiModifierListOwner[] { (PsiModifierListOwner) field } : PsiMember.EMPTY_ARRAY;
}
int candidatesLength = ((Object[]) candidates).length;
for (int var16 = 0; var16 < candidatesLength; ++var16) {
Object var17 = ((Object[]) candidates)[var16];
boolean var18 = ((PsiModifierListOwner) var17).hasModifierProperty("static");
String var19 = isStatic && !var18 ? "javascript.instance.member.is.not.accessible.message" : (!((PsiModifierListOwner) var17).hasModifierProperty("public") ? "javascript.element.is.not.accessible.message" : null);
JSResolveResult var20 = var19 == null ? new JSResolveResult((PsiElement) var17) : new JSResolveResult((PsiElement) var17, null, var19);
results.add(var20);
}
return results;
}
use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project intellij-plugins by JetBrains.
the class AngularJSReferenceExpressionResolver method resolve.
@NotNull
@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
if (myReferencedName == null)
return ResolveResult.EMPTY_ARRAY;
if (myRef.getParent() instanceof JSDefinitionExpression) {
final PsiElement sibling = PsiTreeUtil.prevVisibleLeaf(myRef);
if (sibling != null && sibling.getNode().getElementType() == JSTokenTypes.LET_KEYWORD) {
return new JSResolveResult[] { new JSResolveResult(myRef) };
}
final AngularJSRepeatExpression repeat = PsiTreeUtil.getParentOfType(myRef, AngularJSRepeatExpression.class);
if (repeat != null) {
for (JSDefinitionExpression def : repeat.getDefinitions()) {
if (PsiTreeUtil.isAncestor(def, myRef, true))
return new JSResolveResult[] { new JSResolveResult(myRef) };
}
}
final AngularJSAsExpression as = PsiTreeUtil.getParentOfType(myRef, AngularJSAsExpression.class);
if (as != null) {
if (PsiTreeUtil.isAncestor(as.getDefinition(), myRef, true))
return new JSResolveResult[] { new JSResolveResult(myRef) };
}
JSClass clazz = myRef.getQualifier() == null ? AngularJS2IndexingHandler.findDirectiveClass(myRef) : null;
if (clazz != null && DialectDetector.isTypeScript(clazz)) {
final TypeScriptResolveProcessor localProcessor = new TypeScriptResolveProcessor(myReferencedName, myContainingFile, myRef, incompleteCode);
localProcessor.setToProcessHierarchy(true);
JSReferenceExpressionImpl.doProcessLocalDeclarations(clazz, myQualifier, localProcessor, false, false, null);
return localProcessor.getResultsAsResolveResults();
}
}
if (AngularJSAsExpression.isAsControllerRef(myRef, myRef.getParent())) {
final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularControllerIndex.KEY, myReferencedName);
if (resolve != null) {
return new JSResolveResult[] { new JSResolveResult(resolve) };
}
} else if (AngularJSFilterExpression.isFilterNameRef(myRef, myParent)) {
final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularFilterIndex.KEY, myReferencedName);
if (resolve != null) {
return new JSResolveResult[] { new JSResolveResult(resolve) };
}
} else if (myQualifier == null) {
final Collection<JSPsiElementBase> localVariables = getItemsByName(myReferencedName, myRef);
if (!localVariables.isEmpty()) {
return ContainerUtil.map2Array(localVariables, JSResolveResult.class, item -> new JSResolveResult(item));
}
}
return super.resolve(expression, incompleteCode);
}
use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project intellij-plugins by JetBrains.
the class JstdTestFileStructure method postProcess.
void postProcess() {
myNameByPsiElementMap = Collections.emptyMap();
myPrototypeBasedTestElements = Collections.emptyMap();
if (myTestCaseStructures.isEmpty()) {
return;
}
int totalCount = 0;
int prototypeBasedTestCount = 0;
for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
totalCount += testCaseStructure.getTestCount() + 1;
for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
if (testStructure.getWholeLeftDefExpr() != null) {
prototypeBasedTestCount++;
}
}
}
myNameByPsiElementMap = new IdentityHashMap<>(totalCount);
if (prototypeBasedTestCount > 0) {
myPrototypeBasedTestElements = new IdentityHashMap<>(prototypeBasedTestCount);
}
for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
JSExpression testCaseMethodExpr = testCaseStructure.getEnclosingCallExpression().getMethodExpression();
if (testCaseMethodExpr != null) {
myNameByPsiElementMap.put(testCaseMethodExpr, testCaseStructure.getName());
}
for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
PsiElement anchor = testStructure.getTestMethodNameDeclaration();
myNameByPsiElementMap.put(anchor, testStructure.getName());
JSDefinitionExpression wholeLeftDefExpr = testStructure.getWholeLeftDefExpr();
if (wholeLeftDefExpr != null) {
myPrototypeBasedTestElements.put(wholeLeftDefExpr, null);
}
}
}
}
use of com.intellij.lang.javascript.psi.JSDefinitionExpression 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.JSDefinitionExpression in project oxy-template-support-plugin by mutant-industries.
the class MacroIndex method isInMacroDefinition.
public static boolean isInMacroDefinition(@NotNull JSReferenceExpression expression) {
String referenceText = expression.getText();
JSReferenceExpression topReference = !(expression.getParent() instanceof JSReferenceExpression) ? expression : PsiTreeUtil.getTopmostParentOfType(expression, JSReferenceExpression.class);
return topReference != null && topReference.getParent() instanceof JSDefinitionExpression && !MacroIndex.isMacroRootNamespace(referenceText, true);
}
Aggregations