use of com.intellij.lang.javascript.psi.JSParameter 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.JSParameter in project intellij-plugins by JetBrains.
the class CodeContext method hasDefaultConstructor.
public static boolean hasDefaultConstructor(@NotNull final JSClass jsClass) {
final JSFunction constructor = jsClass.getConstructor();
final JSParameter[] parameters = constructor == null ? null : constructor.getParameterVariables();
return parameters == null || parameters.length == 0 || parameters[0].isOptional() || parameters[0].isRest();
}
use of com.intellij.lang.javascript.psi.JSParameter in project oxy-template-support-plugin by mutant-industries.
the class JsMacroParamSuggestionProvider method getMacroParamSuggestions.
@NotNull
@Override
protected MacroParamSuggestionSet getMacroParamSuggestions() {
JSParameter[] params;
if ((params = functionExpression.getParameterVariables()).length == 0) {
return MacroParamSuggestionSet.empty();
}
final MacroParamSuggestionSet result = new MacroParamSuggestionSet();
submergedCalls = new LinkedList<>();
String paramsObjectName = params[0].getText();
/**
* !! cannot be done via {@link com.intellij.psi.search.searches.ReferencesSearch.search}, which would in some
* special cases (foreach in foreach) end up in infinite loop - reference search calls type resolver, which makes use of this method
*/
for (PsiElement elementLocal : getParamReferencesLocal(params[0])) {
PsiElement element = elementLocal;
if (!(elementLocal instanceof JSReferenceExpression)) {
continue;
}
if ((elementLocal = elementLocal.getNextSibling()) != null) {
if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
elementLocal = elementLocal.getNextSibling();
}
if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.DOT) {
if ((elementLocal = elementLocal.getNextSibling()) != null) {
if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
elementLocal = elementLocal.getNextSibling();
}
if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
result.add(new JsMacroParamDescriptor(elementLocal.getText(), macro, getJsParamDoc(elementLocal.getText(), macro), true));
}
}
continue;
}
}
JSCallExpression macroCall = getMacroCall(element);
JSReferenceExpression callReference;
if (macroCall == null || (callReference = PsiTreeUtil.getChildOfType(macroCall, JSReferenceExpression.class)) == null || (element = callReference.resolve()) == null) {
continue;
}
submergedCalls.add(element);
}
if (macro.getFirstChild() instanceof JSDocComment) {
String paramName;
PsiReference reference;
PsiElement resolve;
for (JSDocTag docTag : ((JSDocComment) macro.getFirstChild()).getTags()) {
if ((reference = docTag.getReference()) != null && (resolve = reference.resolve()) != null && !params[0].isEquivalentTo(resolve) || (paramName = getCommentParameterName(docTag)) == null) {
continue;
}
paramName = paramName.replaceFirst("^" + paramsObjectName + "\\.", "");
if (result.getByName(paramName) != null) {
continue;
}
result.add(new JsMacroParamDescriptor(paramName, macro, docTag, false));
}
}
return result;
}
use of com.intellij.lang.javascript.psi.JSParameter 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;
}
Aggregations