use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class ActionScriptAccessibilityProcessingHandler method acceptsForMembersVisibility.
@Override
protected boolean acceptsForMembersVisibility(@NotNull JSPsiElementBase element, @NotNull SinkResolveProcessor resolveProcessor) {
if (!(element instanceof JSAttributeListOwner))
return true;
final JSAttributeList attributeList = ((JSAttributeListOwner) element).getAttributeList();
if (JSResolveUtil.getClassOfContext(place) != JSResolveUtil.getClassOfContext(element)) {
if (!acceptPrivateMembers) {
if (attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PRIVATE) {
resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.PRIVATE_MEMBER_IS_NOT_ACCESSIBLE);
return false;
}
}
if (!acceptProtectedMembers) {
if (attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PROTECTED) {
// we are resolving in context of the class or element within context of the class
if ((myClassScopeTypeName != null || isParentClassContext(element))) {
resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.PROTECTED_MEMBER_IS_NOT_ACCESSIBLE);
return false;
}
// if element / context out of class then protected element is ok due to includes
}
}
}
PsiElement elt = JSResolveUtil.findParent(element);
if (processStatics) {
if ((attributeList == null || !attributeList.hasModifier(JSAttributeList.ModifierType.STATIC))) {
if (JSResolveUtil.PROTOTYPE_FIELD_NAME.equals(resolveProcessor.getName()))
return true;
resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.INSTANCE_MEMBER_INACCESSIBLE);
return false;
}
if (myTypeName != null && elt instanceof JSClass && !myTypeName.equals(((JSClass) elt).getQualifiedName())) {
// static members are inherited in TypeScript classes
resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.STATIC_MEMBER_INACCESSIBLE);
return false;
}
} else if (myClassDeclarationStarted && !allowUnqualifiedStaticsFromInstance) {
// ActionScript only?
if (attributeList != null && attributeList.hasModifier(JSAttributeList.ModifierType.STATIC)) {
boolean referencingClass = false;
if (place instanceof JSReferenceExpression) {
JSExpression qualifier = ((JSReferenceExpression) place).getQualifier();
if (qualifier instanceof JSReferenceExpression) {
JSElement expression = JSSymbolUtil.calcRefExprValue((JSReferenceExpression) qualifier);
if (expression instanceof JSReferenceExpression) {
for (ResolveResult r : ((JSReferenceExpression) expression).multiResolve(false)) {
PsiElement rElement = r.getElement();
if (rElement instanceof JSClass) {
referencingClass = true;
break;
}
}
}
}
}
if (!referencingClass) {
resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.STATIC_MEMBER_INACCESSIBLE);
return false;
}
}
}
if (processActionScriptNotAllowedNsAttributes(element, resolveProcessor, attributeList))
return false;
return true;
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class AddImportECMAScriptClassOrFunctionAction method getCandidates.
private Collection<JSQualifiedNamedElement> getCandidates(Editor editor, PsiFile file) {
final Collection<JSQualifiedNamedElement> candidates;
if (myReference instanceof JSReferenceExpression && ((JSReferenceExpression) myReference).getQualifier() == null) {
Collection<JSQualifiedNamedElement> c = getCandidates(editor, file, myReference.getCanonicalText());
filterCandidates(c);
candidates = new THashSet<>(c, JSPsiImplUtils.QUALIFIED_NAME_HASHING_STRATEGY);
} else {
JSQualifiedNamedElement invalidResult = null;
for (ResolveResult r : myReference.multiResolve(false)) {
PsiElement element = r.getElement();
if (element instanceof JSQualifiedNamedElement) {
invalidResult = (JSQualifiedNamedElement) element;
}
}
if (invalidResult != null) {
if (myReference.getElement().getParent() instanceof JSNewExpression && invalidResult instanceof JSFunction && ((JSFunction) invalidResult).isConstructor()) {
invalidResult = (JSClass) invalidResult.getParent();
}
candidates = new SmartList<>();
candidates.add(invalidResult);
} else {
candidates = Collections.emptyList();
}
}
return candidates;
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class FlexXmlBackedClassesIndex method getIndexer.
@Override
@NotNull
public DataIndexer<String, Void, FileContent> getIndexer() {
return new DataIndexer<String, Void, FileContent>() {
@Override
@NotNull
public Map<String, Void> map(@NotNull FileContent inputData) {
final XmlFile file = (XmlFile) inputData.getPsiFile();
final Map<String, Void> result = new HashMap<>();
for (JSClass clazz : XmlBackedJSClassImpl.getClasses(file)) {
JSReferenceList supers = getSupers(clazz);
if (supers != null) {
final JSExpression[] expressions = supers.getExpressions();
for (JSExpression expr : expressions) {
String s = expr instanceof JSReferenceExpression ? ((JSReferenceExpression) expr).getReferenceName() : null;
if (s != null)
result.put(s, null);
}
}
}
return result;
}
};
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class AbstractMethodBasedInspection method createVisitor.
@NotNull
@Override
protected final JSElementVisitor createVisitor(final ProblemsHolder holder, LocalInspectionToolSession session) {
if (holder == null) {
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
Project project = holder.getProject();
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
}
return new JSElementVisitor() {
@Override
public void visitJSCallExpression(final JSCallExpression jsCallExpression) {
JSFile jsFile = null;
if (jsCallExpression != null) {
jsFile = ObjectUtils.tryCast(jsCallExpression.getContainingFile(), JSFile.class);
}
if (jsFile == null) {
return;
}
JSReferenceExpression methodExpression = ObjectUtils.tryCast(jsCallExpression.getMethodExpression(), JSReferenceExpression.class);
if (methodExpression == null) {
return;
}
boolean suitableSymbol = isSuitableElement(jsFile, jsCallExpression);
if (suitableSymbol) {
boolean resolved = isResolved(methodExpression);
if (!resolved) {
TextRange rangeInElement = TextRange.create(0, methodExpression.getTextLength());
HintWrapperQuickFix fix = new HintWrapperQuickFix(methodExpression, rangeInElement, getFix());
holder.registerProblem(methodExpression, getProblemDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, fix);
}
}
}
};
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method testNamespaceElementReferences2.
public void testNamespaceElementReferences2() throws Exception {
defaultTest();
JSReferenceExpression expr = PsiTreeUtil.getParentOfType(myFile.findElementAt(myEditor.getCaretModel().getOffset()), JSReferenceExpression.class);
assertNotNull(expr);
PsiElement exprResolve = expr.resolve();
assertTrue(exprResolve instanceof JSFunction);
JSClass clazz = PsiTreeUtil.getParentOfType(exprResolve, JSClass.class);
assertNotNull(clazz);
assertEquals("Foo", clazz.getQualifiedName());
}
Aggregations