use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptFunctionSignatureChecker method checkConstructorCall.
@Override
public void checkConstructorCall(@NotNull JSCallExpression node, @NotNull JSClass target) {
if (node instanceof JSNewExpression || node.getMethodExpression() instanceof JSSuperExpression) {
final JSArgumentList argumentList = node.getArgumentList();
final JSExpression[] expressions = argumentList != null ? argumentList.getArguments() : JSExpression.EMPTY_ARRAY;
if (expressions.length > 0) {
final ActionScriptCreateConstructorFix fix = ActionScriptCreateConstructorFix.createIfApplicable(node);
registerProblem(node, JSBundle.message("javascript.invalid.number.of.parameters", "0"), fix != null ? new LocalQuickFix[] { fix } : LocalQuickFix.EMPTY_ARRAY);
}
} else {
reportProblemIfNotExpectedCountOfParameters(node, 1, "one");
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class PropertyProcessor method processClass.
// see ClassProperty test
private void processClass(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
JSClass jsClass = valueProvider.getJsClass();
// IDEA-73537, cannot use only valueProvider.getJsClass()
if (jsClass == null) {
String trimmed = valueProvider.getTrimmed();
XmlElement exceptionElement = valueProvider.getElement();
if (trimmed.isEmpty() && valueProvider.getElement() instanceof XmlTag) {
// case 1, fx:Class
final XmlTag propertyTag = (XmlTag) valueProvider.getElement();
final XmlTag[] propertyTagSubTags = propertyTag.getSubTags();
if (propertyTagSubTags.length == 1) {
final XmlTag contentTag = propertyTagSubTags[0];
exceptionElement = contentTag;
final XmlElementDescriptor contentTagDescriptor = contentTag.getDescriptor();
if (contentTagDescriptor instanceof ClassBackedElementDescriptor && AsCommonTypeNames.CLASS.equals(contentTagDescriptor.getQualifiedName())) {
trimmed = contentTag.getValue().getTrimmedText();
}
}
}
if (trimmed.isEmpty()) {
throw new InvalidPropertyException(exceptionElement, "invalid.class.value");
}
final Module module = ModuleUtilCore.findModuleForPsiElement(valueProvider.getElement());
if (module != null) {
jsClass = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(trimmed, module.getModuleWithDependenciesAndLibrariesScope(false));
}
if (jsClass == null) {
throw new InvalidPropertyException(exceptionElement, "unresolved.class", trimmed);
}
}
if (InjectionUtil.isProjectComponent(jsClass)) {
if (ActionScriptClassResolver.isParentClass(jsClass, "spark.components.View")) {
int projectComponentFactoryId = getProjectComponentFactoryId(jsClass);
assert projectComponentFactoryId != -1;
writer.projectClassReference(projectComponentFactoryId);
} else {
throw new InvalidPropertyException(valueProvider.getElement(), "class.reference.support.only.skin.class.or.view", jsClass.getQualifiedName());
}
} else {
writer.classReference(jsClass.getQualifiedName());
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class PropertyProcessor method writeClassFactory.
private void writeClassFactory(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
if (valueProvider instanceof XmlTagValueProvider) {
XmlTag tag = ((XmlTagValueProvider) valueProvider).getTag();
XmlTag[] subTags = tag.getSubTags();
if (subTags.length > 0) {
processFxComponent(subTags[0], true);
return;
}
}
String className = valueProvider.getTrimmed();
if (writeFxComponentReferenceIfProcessed(className) || writeReferenceIfReferenced(className)) {
return;
}
final JSClass jsClass = valueProvider.getJsClass();
if (jsClass == null) {
throw new InvalidPropertyException(valueProvider.getElement(), "unresolved.class", valueProvider.getTrimmed());
}
final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
final PsiElement parent = jsClass.getNavigationElement().getParent();
if (parent instanceof XmlTag && MxmlUtil.isComponentLanguageTag((XmlTag) parent)) {
// if referenced by inner class name, but inner fx component is not yet processed
if (parent.getContainingFile().equals(valueProvider.getElement().getContainingFile())) {
processFxComponent((XmlTag) parent, false);
return;
} else {
effectiveClassInfo = new Trinity<>(-1, "mx.core.UIComponent", null);
}
} else {
effectiveClassInfo = MxmlUtil.computeEffectiveClass(valueProvider.getElement(), jsClass, mxmlWriter.projectComponentReferenceCounter, false);
}
if (effectiveClassInfo.first == -1) {
if (effectiveClassInfo.second != null) {
if (effectiveClassInfo.second.equals("mx.core.UIComponent")) {
PsiMetaData psiMetaData = valueProvider.getPsiMetaData();
if (psiMetaData != null && psiMetaData.getName().equals("itemRenderer") && MxmlUtil.isPropertyOfSparkDataGroup((AnnotationBackedDescriptor) psiMetaData)) {
className = MxmlUtil.UNKNOWN_ITEM_RENDERER_CLASS_NAME;
} else {
className = MxmlUtil.UNKNOWN_COMPONENT_CLASS_NAME;
}
} else {
className = effectiveClassInfo.second;
}
}
writeNonProjectUnreferencedClassFactory(className);
} else {
writer.documentFactoryReference(effectiveClassInfo.first);
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class CreateJSSubclassIntention method invoke.
@Override
public void invoke(@NotNull final Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final JSClass jsClass = PsiTreeUtil.getParentOfType(element, JSClass.class);
if (jsClass == null)
return;
final PsiElement parent = jsClass.getParent();
if (!(parent instanceof JSPackageStatement))
return;
final JSPackageStatement jsPackageStatement = (JSPackageStatement) parent;
final String defaultTemplateName = ActionScriptCreateClassOrInterfaceFix.ACTION_SCRIPT_CLASS_WITH_SUPERS_TEMPLATE_NAME;
final String className;
final String packageName;
final String templateName;
final PsiDirectory targetDirectory;
final Collection<String> interfaces;
final Map<String, Object> templateAttributes;
final JSClass superClass;
if (ApplicationManager.getApplication().isUnitTestMode()) {
className = suggestSubclassName(jsClass.getName());
packageName = "foo";
templateName = defaultTemplateName;
targetDirectory = WriteAction.compute(() -> ActionScriptCreateClassOrInterfaceFix.findOrCreateDirectory(packageName, jsPackageStatement));
interfaces = jsClass.isInterface() ? Collections.singletonList(jsClass.getQualifiedName()) : Collections.emptyList();
templateAttributes = Collections.emptyMap();
superClass = jsClass.isInterface() ? null : jsClass;
} else {
CreateClassParameters p = ActionScriptCreateClassOrInterfaceFix.createAndShow(defaultTemplateName, jsClass, suggestSubclassName(jsClass.getName()), true, jsPackageStatement.getQualifiedName(), jsClass, JSBundle.message("new.actionscript.class.dialog.title"), () -> ActionScriptCreateClassOrInterfaceFix.getApplicableTemplates(ActionScriptCreateClassOrInterfaceFix.ACTIONSCRIPT_TEMPLATES_EXTENSIONS, project));
if (p == null)
return;
className = p.getClassName();
packageName = p.getPackageName();
templateName = p.getTemplateName();
targetDirectory = p.getTargetDirectory();
superClass = ActionScriptCreateClassOrInterfaceFix.calcClass(p.getSuperclassFqn(), element);
interfaces = p.getInterfacesFqns();
templateAttributes = new HashMap<>(p.getTemplateAttributes());
}
JSClass createdClass = ActionScriptCreateClassOrInterfaceFix.createClass(templateName, className, packageName, superClass, interfaces, targetDirectory, getTitle(jsClass), true, templateAttributes, aClass -> {
if (aClass != null && !aClass.isInterface() && (jsClass.isInterface() || !interfaces.isEmpty())) {
new MyImplementMethodsHandler(aClass).execute();
}
});
if (createdClass != null) {
createdClass.navigate(true);
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class ActionScriptCreateConstructorFix method createIfApplicable.
@Nullable
public static ActionScriptCreateConstructorFix createIfApplicable(final JSCallExpression node) {
final JSClass clazz;
final JSReferenceExpression reference;
if (node instanceof JSNewExpression) {
JSExpression methodExpression = node.getMethodExpression();
if (!(methodExpression instanceof JSReferenceExpression)) {
return null;
}
PsiElement resolved = ((JSReferenceExpression) methodExpression).resolve();
if (!(resolved instanceof JSClass) || resolved instanceof XmlBackedJSClass || ((JSClass) resolved).isInterface()) {
return null;
}
clazz = (JSClass) resolved;
reference = (JSReferenceExpression) methodExpression;
} else {
JSExpression methodExpression = node.getMethodExpression();
if (!(methodExpression instanceof JSSuperExpression)) {
return null;
}
JSClass containingClass = JSResolveUtil.getClassOfContext(node);
if (containingClass == null) {
return null;
}
clazz = containingClass.getSuperClasses()[0];
if (clazz.isInterface()) {
return null;
}
reference = (JSReferenceExpression) clazz.findNameIdentifier().getPsi();
}
return new ActionScriptCreateConstructorFix(clazz, reference, node);
}
Aggregations