Search in sources :

Example 6 with JSAttributeList

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

the class ActionScriptSmartCompletionContributor method getEventsMap.

public static Map<String, String> getEventsMap(JSClass clazzToProcess) {
    if (clazzToProcess == null)
        return Collections.emptyMap();
    final Map<String, String> eventsMap = new THashMap<>();
    class EventsDataCollector extends ResolveProcessor implements ActionScriptResolveUtil.MetaDataProcessor {

        public EventsDataCollector() {
            super(null);
            setToProcessHierarchy(true);
            setToProcessMembers(false);
            setTypeContext(true);
            setLocalResolve(true);
        }

        @Override
        public boolean process(@NotNull final JSAttribute jsAttribute) {
            if ("Event".equals(jsAttribute.getName())) {
                final JSAttributeNameValuePair eventAttr = jsAttribute.getValueByName("name");
                JSAttributeNameValuePair typeAttr = jsAttribute.getValueByName("type");
                if (eventAttr != null && typeAttr != null) {
                    final String simpleValue = eventAttr.getSimpleValue();
                    if (simpleValue != null) {
                        eventsMap.put(simpleValue, typeAttr.getSimpleValue());
                    }
                }
            }
            return true;
        }

        @Override
        public boolean handleOtherElement(final PsiElement el, final PsiElement context, final Ref<PsiElement> continuePassElement) {
            return true;
        }

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof JSClass) {
                ActionScriptResolveUtil.processMetaAttributesForClass(element, this, true);
            }
            return true;
        }
    }
    final EventsDataCollector eventsDataCollector = new EventsDataCollector();
    if (clazzToProcess instanceof XmlBackedJSClassImpl) {
        XmlFile file = (XmlFile) clazzToProcess.getParent().getContainingFile();
        if (file != null && JavaScriptSupportLoader.isFlexMxmFile(file)) {
            final XmlDocument xmlDocument = file.getDocument();
            final XmlTag rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
            final XmlTag[] tags = rootTag == null ? XmlTag.EMPTY : MxmlJSClass.findLanguageSubTags(rootTag, FlexPredefinedTagNames.METADATA);
            JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {

                @Override
                protected void process(JSFile file) {
                    for (PsiElement element : file.getChildren()) {
                        if (element instanceof JSAttributeList) {
                            ActionScriptResolveUtil.processAttributeList(eventsDataCollector, null, (JSAttributeList) element, true, true);
                        }
                    }
                }
            };
            for (XmlTag tag : tags) {
                JSResolveUtil.processInjectedFileForTag(tag, injectedFilesVisitor);
            }
        }
    }
    clazzToProcess.processDeclarations(eventsDataCollector, ResolveState.initial(), clazzToProcess, clazzToProcess);
    return eventsMap;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) NotNull(org.jetbrains.annotations.NotNull) ResolveState(com.intellij.psi.ResolveState) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 7 with JSAttributeList

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

the class JSImplicitlyInternalDeclarationInspection method process.

private static void process(final JSNamedElement node, final ProblemsHolder holder) {
    if (!DialectDetector.isActionScript(node))
        return;
    JSFunction fun = PsiTreeUtil.getParentOfType(node, JSFunction.class);
    if (fun != null)
        return;
    ASTNode nameIdentifier = node.findNameIdentifier();
    if (nameIdentifier == null)
        return;
    JSClass clazz = JSResolveUtil.getClassOfContext(node);
    if (clazz == null) {
        PsiElement parent = JSResolveUtil.findParent(node);
        if (!(parent instanceof JSPackageStatement))
            return;
    }
    JSAttributeList attributeList = ((JSAttributeListOwner) node).getAttributeList();
    JSAttributeList.AccessType accessType = attributeList != null ? attributeList.getAccessType() : null;
    if (accessType == JSAttributeList.AccessType.PACKAGE_LOCAL && attributeList.findAccessTypeElement() == null && attributeList.getNamespaceElement() == null && !JSResolveUtil.isConstructorFunction(node)) {
        holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("js.implicitly.internal.declaration.problem"), new LocalQuickFix() {

            @NotNull
            @Override
            public String getFamilyName() {
                return FlexBundle.message("js.implicitly.internal.declaration.problem.add.internal.fix");
            }

            @Override
            public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
                PsiElement anchor = descriptor.getPsiElement();
                JSChangeVisibilityUtil.setVisibility((JSAttributeListOwner) anchor.getParent(), JSAttributeList.AccessType.PACKAGE_LOCAL);
            }
        });
    }
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) ASTNode(com.intellij.lang.ASTNode) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 8 with JSAttributeList

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

the class ActionScriptImplementedMethodProcessor method collectVisibleFunctions.

@NotNull
private JSFunctionCollector collectVisibleFunctions() {
    return JSFunctionCollector.collectAllVisibleClassFunctions(myJsClass, null, jsFunction -> {
        final JSAttributeList attributeList = jsFunction.getAttributeList();
        if (!JSInheritanceUtil.canHaveSuperMember(attributeList)) {
            return false;
        }
        PsiElement parentClass = JSResolveUtil.findParent(jsFunction);
        if (attributeList.getAccessType() != JSAttributeList.AccessType.PUBLIC && myJsClass != parentClass) {
            return false;
        }
        return true;
    });
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with JSAttributeList

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

the class ActionScriptCreateConstructorFix method applyFix.

@Override
protected void applyFix(final Project project, final PsiElement psiElement, PsiFile file, Editor editor) {
    final AtomicInteger count = new AtomicInteger();
    ReferencesSearch.search(myClass, myClass.getUseScope()).forEach(psiReference -> !isClassInstantiation(psiReference) || count.incrementAndGet() < 2);
    int usages = count.get();
    if (usages < 2) {
        usages += JSInheritanceUtil.findSuperConstructorCalls(myClass).size();
    }
    if (usages < 2) {
        final Collection<String> toImport = new ArrayList<>();
        for (JSExpression argument : myNode.getArguments()) {
            String type = JSResolveUtil.getQualifiedExpressionType(argument, argument.getContainingFile());
            if (StringUtil.isNotEmpty(type) && ImportUtils.needsImport(myClass, StringUtil.getPackageName(type))) {
                toImport.add(type);
            }
        }
        WriteAction.run(() -> {
            if (!toImport.isEmpty()) {
                FormatFixer formatFixer = ImportUtils.insertImportStatements(myClass, toImport);
                if (formatFixer != null) {
                    formatFixer.fixFormat();
                }
            }
            super.applyFix(project, psiElement, myClass.getContainingFile(), getEditor(myClass.getProject(), myClass.getContainingFile()));
        });
    } else {
        String text = "function " + myClass.getName() + "(){}";
        JSFunction fakeFunction = (JSFunction) JSChangeUtil.createStatementFromText(project, text, JavaScriptSupportLoader.ECMA_SCRIPT_L4).getPsi();
        new ChangeSignatureFix(fakeFunction, myNode.getArgumentList()) {

            @Override
            protected Pair<Boolean, List<JSParameterInfo>> handleCall(@NotNull JSFunction function, JSExpression[] arguments, boolean dummy) {
                List<JSParameterInfo> parameterInfos = super.handleCall(function, arguments, dummy).second;
                // always show dialog
                return Pair.create(true, parameterInfos);
            }

            @Override
            protected JSChangeSignatureDialog createDialog(PsiElement context, final List<JSParameterInfo> paramInfos) {
                JSMethodDescriptor descriptor = new JSMethodDescriptor(myFunction.getElement(), true) {

                    @Override
                    public List<JSParameterInfo> getParameters() {
                        return paramInfos;
                    }
                };
                return new MyDialog(descriptor, context);
            }

            @Override
            protected JSChangeSignatureProcessor createProcessor(List<JSParameterInfo> paramInfos, JSAttributeList attributeList, @NotNull JSFunction function) {
                return new MyProcessor(function, attributeList != null ? attributeList.getAccessType() : JSAttributeList.AccessType.PACKAGE_LOCAL, myClass.getName(), "", paramInfos.toArray(new JSParameterInfo[paramInfos.size()]), Collections.emptySet());
            }
        }.invoke(project, editor, file);
    }
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) FormatFixer(com.intellij.lang.javascript.refactoring.FormatFixer) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Example 10 with JSAttributeList

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList 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)

Aggregations

JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)22 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)12 JSFunction (com.intellij.lang.javascript.psi.JSFunction)5 JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)5 NotNull (org.jetbrains.annotations.NotNull)5 JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)4 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)4 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)3 JSFile (com.intellij.lang.javascript.psi.JSFile)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 THashMap (gnu.trove.THashMap)3 ASTNode (com.intellij.lang.ASTNode)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSPackageStatement (com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement)2 Module (com.intellij.openapi.module.Module)2 TextRange (com.intellij.openapi.util.TextRange)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2