use of com.intellij.lang.javascript.psi.JSExpression 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.JSExpression 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.JSExpression in project oxy-template-support-plugin by mutant-industries.
the class JavaContext method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
Module module;
PsiElement element = parameters.getOriginalFile().getViewProvider().findElementAt(parameters.getOffset() - 1, OxyTemplateInnerJs.INSTANCE);
if (element == null || element.getNode().getElementType() != JSTokenTypes.DOT && (element = element.getPrevSibling()) == null) {
return;
}
if (element.getNode().getElementType() == TokenType.WHITE_SPACE) {
element = element.getPrevSibling();
}
while (element != null && element.getNode().getElementType() != JSTokenTypes.DOT) {
element = element.getLastChild();
if (element instanceof PsiErrorElement) {
element = element.getPrevSibling();
}
}
if (element == null || element.getNode().getElementType() != JSTokenTypes.DOT || (element = element.getPrevSibling()) == null) {
return;
}
if (element.getNode().getElementType() == TokenType.WHITE_SPACE) {
element = element.getPrevSibling();
}
if (!(element instanceof JSExpression) || (module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile())) == null) {
return;
}
JSSimpleTypeProcessor typeProcessor = new JSSimpleTypeProcessor();
JSTypeEvaluator.evaluateTypes((JSExpression) element, parameters.getOriginalFile().getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE), typeProcessor);
JSType type = typeProcessor.getType();
List<String> possibleJavaTypes = new LinkedList<>();
if (type != null) {
if (type instanceof JSCompositeTypeImpl) {
possibleJavaTypes.addAll(((JSCompositeTypeImpl) type).getTypes().stream().filter(jsType -> jsType instanceof JSTypeImpl).map(JSType::getTypeText).collect(Collectors.toList()));
} else if (type instanceof JSTypeImpl) {
possibleJavaTypes.add(type.getTypeText());
}
}
JavaPsiFacade facade = JavaPsiFacade.getInstance(parameters.getOriginalFile().getProject());
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
List<PsiClass> possibleInstancesOf = new LinkedList<>();
boolean suggestionsFound = false;
PsiClass aClass;
for (String possibleType : possibleJavaTypes) {
if ((aClass = facade.findClass(possibleType, scope)) != null) {
possibleInstancesOf.add(aClass);
possibleInstancesOf.addAll(ExtenderProvider.getExtenders(aClass));
}
}
for (PsiClass psiClass : possibleInstancesOf) {
List<String> alreadySuggested = new LinkedList<>();
for (PsiMethod method : psiClass.getAllMethods()) {
if (method.getContainingClass() == null || Object.class.getName().equals(method.getContainingClass().getQualifiedName()) || method.getReturnType() == null || shippedBaseExtenderMethods.contains(method.getName()) || !method.getModifierList().hasModifierProperty(PsiModifier.PUBLIC) || InheritanceUtil.isInheritor(method.getContainingClass(), EXTENDER_INTERFACE_FQN) && !InheritanceUtil.isInheritor(method.getContainingClass(), EXTENDER_BASE_CLASS_FQN)) {
continue;
}
String insertText = method.getName();
String presentableText = method.getName();
if (insertText.matches("((^is)|(^get)|(^set))[A-Z].*")) {
insertText = presentableText = StringUtils.decapitalize(insertText.replaceFirst("(^is)|(^get)|(^set)", ""));
} else {
presentableText = method.getPresentation() == null ? presentableText + "()" : method.getPresentation().getPresentableText();
insertText += "()";
}
if (alreadySuggested.contains(insertText)) {
continue;
}
result.consume(LookupElementBuilder.create(method, insertText).withIcon(method.getIcon(0)).withTypeText(method.getReturnType().getPresentableText(), true).withTailText(" (" + psiClass.getContainingFile().getName() + ")", true).withPresentableText(presentableText).withInsertHandler(new TrailingPatternConsumer(INSERT_CONSUME)).withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
alreadySuggested.add(insertText);
suggestionsFound = true;
}
}
if (suggestionsFound) {
result.stopHere();
}
}
use of com.intellij.lang.javascript.psi.JSExpression in project oxy-template-support-plugin by mutant-industries.
the class JsMacroParamSuggestionProvider method getMacroCall.
/**
* @param argument argument of call expression
* @return parent call expression, where utils namespace is skipped e.g.:
* oxy.foo(params) -> oxy.foo
* oxy.bar(utils.extend(params, {param: false}) -> oxy.bar
*/
@Nullable
private static JSCallExpression getMacroCall(@Nullable PsiElement argument) {
if (argument == null) {
return null;
}
JSCallExpression callExpression = PsiTreeUtil.getParentOfType(argument, JSCallExpression.class);
if (callExpression == null) {
return null;
}
if (callExpression.getText().startsWith(MacroIndex.UTILS_NAMESPACE)) {
return getMacroCall(callExpression);
}
JSExpression[] arguments = callExpression.getArguments();
if (arguments.length == 0 || !arguments[0].isEquivalentTo(argument)) {
return null;
}
return callExpression;
}
use of com.intellij.lang.javascript.psi.JSExpression in project intellij-plugins by JetBrains.
the class AngularJSTargetElementEvaluator method getElementByReference.
@Nullable
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
if (ref instanceof JSTextReference) {
final PsiElement element = ref.getElement();
final JSCallExpression call = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
final JSExpression expression = call != null ? call.getMethodExpression() : null;
if (expression instanceof JSReferenceExpression) {
JSReferenceExpression callee = (JSReferenceExpression) expression;
JSExpression qualifier = callee.getQualifier();
if (qualifier != null && AngularJSIndexingHandler.INTERESTING_METHODS.contains(callee.getReferencedName()) && AngularIndexUtil.hasAngularJS(element.getProject())) {
return element;
}
}
}
return null;
}
Aggregations