Search in sources :

Example 56 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class NewFlexComponentUmlAction method createElement.

@Nullable
@Override
public Object createElement(final DiagramDataModel<Object> model, final CreateClassParameters params, final AnActionEvent event) {
    final Ref<JSClass> clazz = new Ref<>();
    CommandProcessor.getInstance().executeCommand(params.getTargetDirectory().getProject(), () -> {
        try {
            ActionScriptCreateClassOrInterfaceFix.createClass(params.getTemplateName(), params.getClassName(), params.getPackageName(), getSuperClass(params), params.getInterfacesFqns(), params.getTargetDirectory(), getActionName(), true, new HashMap<>(params.getTemplateAttributes()), jsClass -> {
                CreateFlexComponentFix.fixParentComponent(jsClass, params.getSuperclassFqn());
                clazz.set(jsClass);
            });
        } catch (Exception e) {
            throw new IncorrectOperationException(e);
        }
    }, JSBundle.message(FlexBundle.message("new.flex.component.command.name")), null);
    return clazz.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) IncorrectOperationException(com.intellij.util.IncorrectOperationException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlashUmlImplementationsProvider method getElements.

public Object[] getElements(Object element, Project project) {
    JSClass clazz = (JSClass) element;
    final Collection<PsiElement> inheritors = Collections.synchronizedSet(new THashSet<PsiElement>());
    final Processor<JSClass> p = aClass -> {
        final PsiElement navigationElement = aClass.getNavigationElement();
        inheritors.add(navigationElement instanceof JSClass ? navigationElement : aClass);
        return true;
    };
    JSClassSearch.searchClassInheritors(clazz, true).forEach(p);
    if (clazz.isInterface()) {
        JSClassSearch.searchInterfaceImplementations(clazz, true).forEach(p);
    }
    return inheritors.toArray(new PsiElement[inheritors.size()]);
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ImplementationsProvider(com.intellij.diagram.extras.providers.ImplementationsProvider) Processor(com.intellij.util.Processor) Collection(java.util.Collection) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) THashSet(gnu.trove.THashSet) Comparator(java.util.Comparator) Collections(java.util.Collections) JSClassSearch(com.intellij.lang.javascript.search.JSClassSearch) JSBundle(com.intellij.lang.javascript.JSBundle) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 58 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlashUmlEdgeCreationPolicy method acceptTarget.

public boolean acceptTarget(@NotNull final DiagramNode<Object> target) {
    if (!(target.getIdentifyingElement() instanceof JSClass))
        return false;
    final JSClass clazz = (JSClass) target.getIdentifyingElement();
    JSAttributeList attributeList = clazz.getAttributeList();
    if (attributeList != null && attributeList.hasModifier(JSAttributeList.ModifierType.FINAL))
        return false;
    return true;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 59 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlashUmlElementManager method findInDataContext.

public PsiElement findInDataContext(DataContext context) {
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
    if (isAcceptableAsNode(element)) {
        return element;
    }
    // if caret stands on a member or whitespace, show diagram for the enclosing class
    final Editor editor = LangDataKeys.EDITOR.getData(context);
    if (editor != null) {
        final PsiFile file = CommonDataKeys.PSI_FILE.getData(context);
        if (file != null) {
            PsiElement elementAtOffset = file.findElementAt(editor.getCaretModel().getOffset());
            final PsiNamedElement enclosing = PsiTreeUtil.getParentOfType(elementAtOffset, JSClass.class, JSFile.class, XmlFile.class);
            if (enclosing instanceof JSClass) {
                element = enclosing;
            } else if (enclosing instanceof JSFile) {
                final XmlBackedJSClass clazz = JSResolveUtil.getXmlBackedClass((JSFile) enclosing);
                if (clazz != null) {
                    return clazz;
                }
                JSElement qualified = JSPsiImplUtils.findQualifiedElement((JSFile) enclosing);
                if (qualified instanceof JSClass) {
                    return qualified;
                }
            }
            if (enclosing instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) enclosing)) {
                return XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) enclosing);
            }
        }
    }
    // handle PsiPackage (invoked when 'View as packages' mode is selected)
    Project project = CommonDataKeys.PROJECT.getData(context);
    if (project != null) {
        VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
        if (file != null) {
            PsiDirectory directory = PsiManager.getInstance(project).findDirectory(file);
            if (directory != null && isAcceptableAsNode(directory)) {
                return directory;
            }
        }
    }
    return element;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlBackedJSClass(com.intellij.lang.javascript.psi.ecmal4.XmlBackedJSClass) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) Editor(com.intellij.openapi.editor.Editor) XmlBackedJSClass(com.intellij.lang.javascript.psi.ecmal4.XmlBackedJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 60 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class InjectedPsiVisitor method visit.

@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<Shred> places) {
    // will be called 2 - first for {demandSelectedTO.journalist.nom} and second for {demandSelectedTO.journalist.prenom}
    if (visited) {
        return;
    }
    visited = true;
    assert places.size() == 1;
    assert places.get(0).getHost() == host;
    JSFile jsFile = (JSFile) injectedPsi;
    JSSourceElement[] statements = jsFile.getStatements();
    if (statements.length == 0 && (valueWriter = checkCompilerDirective(jsFile)) != null) {
        return;
    }
    assert statements.length == 1;
    final JSExpression expr = ((JSExpressionStatement) statements[0]).getExpression();
    // <s:Image source="@Embed(source='/Users/develar/Pictures/iChat Ico
    if (!(expr instanceof JSCallExpression)) {
        valueWriter = InjectedASWriter.IGNORE;
        return;
    }
    JSCallExpression expression = (JSCallExpression) expr;
    JSExpression[] arguments = expression.getArguments();
    if (arguments.length != 1) {
        logUnsupported();
        return;
    }
    if (arguments[0] instanceof JSArrayLiteralExpression) {
        if (isUnexpected(JSCommonTypeNames.ARRAY_CLASS_NAME)) {
            return;
        }
        JSArrayLiteralExpression arrayLiteralExpression = (JSArrayLiteralExpression) arguments[0];
        JSExpression[] expressions = arrayLiteralExpression.getExpressions();
        if (expressions.length == 0) {
            valueWriter = InjectedASWriter.IGNORE;
            return;
        }
        // create ExpressionBinding only if expressions contains non-primitive values
        for (JSExpression itemExpression : expressions) {
            if (!(itemExpression instanceof JSLiteralExpression)) {
                binding = new ExpressionBinding(arrayLiteralExpression);
                return;
            }
        }
        valueWriter = new InjectedArrayOfPrimitivesWriter(arrayLiteralExpression);
    } else if (arguments[0] instanceof JSReferenceExpression && arguments[0].getChildren().length == 0) {
        // if propertyName="{CustomSkin}", so, write class, otherwise, it is binding
        JSReferenceExpression referenceExpression = (JSReferenceExpression) arguments[0];
        PsiElement element = referenceExpression.resolve();
        if (element == null) {
            invalidPropertyException = new InvalidPropertyException(expression, "unresolved.variable.or.type", referenceExpression.getReferencedName());
        } else if (element instanceof JSClass) {
            if (isExpectedObjectOrAnyType() || AsCommonTypeNames.CLASS.equals(expectedType)) {
                valueWriter = new ClassValueWriter(((JSClass) element));
            } else {
                invalidPropertyException = new InvalidPropertyException(expression, "implicit.coercion", "Class", expectedType);
            }
        } else if (element instanceof JSVariable) {
            binding = new VariableBinding(((JSVariable) element));
        } else if (element instanceof JSFunction) {
            binding = new ExpressionBinding(((JSFunction) element));
        } else {
            binding = new MxmlObjectBinding(referenceExpression.getReferencedName(), JSCommonTypeNames.ARRAY_CLASS_NAME.equals(expectedType));
        }
    } else {
        binding = new ExpressionBinding(arguments[0]);
    }
}
Also used : InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7