use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class FlexImplicitUsageProvider method isImplicitUsage.
@Override
public boolean isImplicitUsage(PsiElement element) {
if (element instanceof XmlAttribute && ((XmlAttribute) element).isNamespaceDeclaration() && JavaScriptSupportLoader.isLanguageNamespace(((XmlAttribute) element).getValue())) {
return true;
}
if (element instanceof JSClass) {
JSClass clazz = (JSClass) element;
final Module module = ModuleUtilCore.findModuleForPsiElement(clazz);
if (module == null || ModuleType.get(module) != FlexModuleType.getInstance())
return false;
if (FlashRunConfigurationProducer.isAcceptedMainClass(clazz, module))
return true;
if (ActionScriptClassResolver.isParentClass(clazz, FlashRunConfigurationForm.MODULE_BASE_CLASS_NAME))
return true;
FlexUnitSupport flexUnitSupport = FlexUnitSupport.getSupport(module);
if (flexUnitSupport != null && flexUnitSupport.isTestClass(clazz, true))
return true;
} else if (element instanceof JSFunction) {
if (isTestMethod((JSFunction) element))
return true;
if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
return true;
} else if (element instanceof JSVariable) {
if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
return true;
if (JSResolveUtil.findParent(element) instanceof JSClass) {
final JSAttributeList varAttrList = ((JSVariable) element).getAttributeList();
if (varAttrList != null && varAttrList.findAttributeByName(FlexAnnotationNames.EMBED) != null) {
return true;
}
}
}
if (element instanceof JSParameter) {
JSFunction function = PsiTreeUtil.getParentOfType(element, JSFunction.class);
if (function != null) {
final JSParameter[] params = function.getParameterVariables();
if (params.length == 1 && element == params[0]) {
@NonNls String type = ((JSParameter) element).getTypeString();
if (type != null)
type = JSImportHandlingUtil.resolveTypeName(type, element);
if (type != null) {
if (FlexCommonTypeNames.FLASH_EVENT_FQN.equals(type) || FlexCommonTypeNames.STARLING_EVENT_FQN.equals(type)) {
return true;
}
boolean b = JSResolveUtil.processHierarchy(type, element.getContainingFile(), jsClass -> !FlexCommonTypeNames.FLASH_EVENT_FQN.equals(jsClass.getQualifiedName()) && !FlexCommonTypeNames.STARLING_EVENT_FQN.equals(jsClass.getQualifiedName()), false);
if (!b)
return true;
}
}
}
}
return false;
}
use of com.intellij.lang.javascript.psi.JSFunction 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.JSFunction in project intellij-plugins by JetBrains.
the class CreateASFunctionIntentionTest method testCanGetIntroductionScopeForActionScriptClassMember.
public void testCanGetIntroductionScopeForActionScriptClassMember() throws Exception {
configureByText(ActionScriptFileType.INSTANCE, "package {\n" + "class test{\n" + " function foo() {\n" + " <caret>bar();\n" + " }\n" + "}\n" + "}");
JSExtractFunctionHandler extractFunctionHandler = new JSExtractFunctionHandler();
int offset = myEditor.getCaretModel().getOffset();
JSFunction function = PsiTreeUtil.getParentOfType(myFile.findElementAt(offset), JSFunction.class);
List<JSExtractFunctionHandler.IntroductionScope> scopes = extractFunctionHandler.findBases(function);
JSSignatureContext context = new JSSignatureContext() {
@Override
public boolean isActionScript() {
return true;
}
@Override
public boolean isAsync() {
return false;
}
@Nullable
@Override
public PsiElement getAnchor() {
return null;
}
@NotNull
@Override
public List<JSExtractFunctionHandler.IntroductionScope> getIntroductionScopes() {
return scopes;
}
};
Pass<JSExtractFunctionHandler.IntroductionScope> callback = new Pass<JSExtractFunctionHandler.IntroductionScope>() {
@Override
public void pass(JSExtractFunctionHandler.IntroductionScope scope) {
}
};
JSExtractFunctionHandler.IntroductionScope actualScope = extractFunctionHandler.getIntroductionScope(myEditor, new ExtractedFunctionSignatureGenerator(), context, callback, "extractedFunction");
Assert.assertEquals(ContainerUtil.getFirstItem(scopes), actualScope);
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class AngularBindingDescriptor method createOneTimeBinding.
@Nullable
private static AngularBindingDescriptor createOneTimeBinding(Pair<PsiElement, String> dom) {
PsiElement element = dom.first;
if (element instanceof JSImplicitElement) {
String type = ((JSImplicitElement) element).getTypeString();
if (type != null && (type.endsWith("String") || type.endsWith("Object"))) {
return new AngularBindingDescriptor(element, dom.second);
}
}
final JSType type = expandStringLiteralTypes(element instanceof JSFunction ? ((JSFunction) element).getReturnType() : element instanceof JSField ? ((JSField) element).getType() : null);
return type != null && type.isDirectlyAssignableType(STRING_TYPE, null) ? new AngularBindingDescriptor(element, dom.second) : null;
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method checkGetProperty.
private static void checkGetProperty(final PsiElement at) {
final JSFunction parentOfType = PsiTreeUtil.getParentOfType(at, JSFunction.class, false);
assertNotNull(parentOfType);
assertTrue(parentOfType.isGetProperty());
}
Aggregations