Search in sources :

Example 1 with JSAttributeListOwner

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner 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;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) NonNls(org.jetbrains.annotations.NonNls) XmlAttribute(com.intellij.psi.xml.XmlAttribute) JSVariable(com.intellij.lang.javascript.psi.JSVariable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) FlexUnitSupport(com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport) Module(com.intellij.openapi.module.Module) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSParameter(com.intellij.lang.javascript.psi.JSParameter) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 2 with JSAttributeListOwner

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

the class ActionScriptAccessibilityProcessingHandler method acceptsForMembersVisibility.

@Override
protected boolean acceptsForMembersVisibility(@NotNull JSPsiElementBase element, @NotNull SinkResolveProcessor resolveProcessor) {
    if (!(element instanceof JSAttributeListOwner))
        return true;
    final JSAttributeList attributeList = ((JSAttributeListOwner) element).getAttributeList();
    if (JSResolveUtil.getClassOfContext(place) != JSResolveUtil.getClassOfContext(element)) {
        if (!acceptPrivateMembers) {
            if (attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PRIVATE) {
                resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.PRIVATE_MEMBER_IS_NOT_ACCESSIBLE);
                return false;
            }
        }
        if (!acceptProtectedMembers) {
            if (attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PROTECTED) {
                // we are resolving in context of the class or element within context of the class
                if ((myClassScopeTypeName != null || isParentClassContext(element))) {
                    resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.PROTECTED_MEMBER_IS_NOT_ACCESSIBLE);
                    return false;
                }
            // if element / context out of class then protected element is ok due to includes
            }
        }
    }
    PsiElement elt = JSResolveUtil.findParent(element);
    if (processStatics) {
        if ((attributeList == null || !attributeList.hasModifier(JSAttributeList.ModifierType.STATIC))) {
            if (JSResolveUtil.PROTOTYPE_FIELD_NAME.equals(resolveProcessor.getName()))
                return true;
            resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.INSTANCE_MEMBER_INACCESSIBLE);
            return false;
        }
        if (myTypeName != null && elt instanceof JSClass && !myTypeName.equals(((JSClass) elt).getQualifiedName())) {
            // static members are inherited in TypeScript classes
            resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.STATIC_MEMBER_INACCESSIBLE);
            return false;
        }
    } else if (myClassDeclarationStarted && !allowUnqualifiedStaticsFromInstance) {
        // ActionScript only?
        if (attributeList != null && attributeList.hasModifier(JSAttributeList.ModifierType.STATIC)) {
            boolean referencingClass = false;
            if (place instanceof JSReferenceExpression) {
                JSExpression qualifier = ((JSReferenceExpression) place).getQualifier();
                if (qualifier instanceof JSReferenceExpression) {
                    JSElement expression = JSSymbolUtil.calcRefExprValue((JSReferenceExpression) qualifier);
                    if (expression instanceof JSReferenceExpression) {
                        for (ResolveResult r : ((JSReferenceExpression) expression).multiResolve(false)) {
                            PsiElement rElement = r.getElement();
                            if (rElement instanceof JSClass) {
                                referencingClass = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!referencingClass) {
                resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.STATIC_MEMBER_INACCESSIBLE);
                return false;
            }
        }
    }
    if (processActionScriptNotAllowedNsAttributes(element, resolveProcessor, attributeList))
        return false;
    return true;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSElement(com.intellij.lang.javascript.psi.JSElement) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSExpression(com.intellij.lang.javascript.psi.JSExpression) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 3 with JSAttributeListOwner

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

the class ActionScriptRearranger method detectModifiers.

@NotNull
protected Set<ArrangementSettingsToken> detectModifiers(@NotNull final JSAttributeListOwner fieldOrMethod) {
    final Set<ArrangementSettingsToken> result = ContainerUtil.newHashSet();
    final JSAttributeList attributes = fieldOrMethod.getAttributeList();
    if (attributes != null) {
        JSAttributeList.AccessType accessType = attributes.getExplicitAccessType();
        if (accessType == null) {
            final String namespace = attributes.getNamespace();
            if (namespace == null) {
                accessType = JSAttributeList.AccessType.PACKAGE_LOCAL;
            }
        }
        if (accessType != null) {
            switch(accessType) {
                case PUBLIC:
                    result.add(PUBLIC);
                    break;
                case PROTECTED:
                    result.add(PROTECTED);
                    break;
                case PACKAGE_LOCAL:
                    result.add(PACKAGE_PRIVATE);
                    break;
                case PRIVATE:
                    result.add(PRIVATE);
                    break;
            }
        }
        if (attributes.hasModifier(JSAttributeList.ModifierType.STATIC))
            result.add(STATIC);
        if (attributes.hasModifier(JSAttributeList.ModifierType.FINAL))
            result.add(FINAL);
        if (attributes.hasModifier(JSAttributeList.ModifierType.OVERRIDE))
            result.add(OVERRIDE);
    }
    return result;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) ArrangementSettingsToken(com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JSAttributeListOwner

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner 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 5 with JSAttributeListOwner

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

the class CreateFlexUnitTestDialog method createUIComponents.

private void createUIComponents() {
    final Module module = ModuleUtil.findModuleForPsiElement(myContextClass);
    assert module != null;
    myPackageCombo = JSReferenceEditor.forPackageName(StringUtil.getPackageName(myContextClass.getQualifiedName()), module.getProject(), null, getTestClassPackageScope(module), RefactoringBundle.message("choose.destination.package"));
    final Condition<JSClass> filter = jsClass -> {
        final JSAttributeList attributeList = jsClass.getAttributeList();
        return !jsClass.isInterface() && attributeList != null && !attributeList.hasModifier(JSAttributeList.ModifierType.FINAL);
    };
    mySuperClassField = JSReferenceEditor.forClassName("", module.getProject(), null, getSuperClassScope(module), null, filter, JSBundle.message("choose.super.class.title"));
    final List<JSMemberInfo> memberInfos = new ArrayList<>();
    JSMemberInfo.extractClassMembers(myContextClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {

        public boolean includeMember(final JSAttributeListOwner member) {
            final JSAttributeList attributeList = member.getAttributeList();
            return member instanceof JSFunction && ((JSFunction) member).getKind() != JSFunction.FunctionKind.CONSTRUCTOR && attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PUBLIC;
        }
    });
    myMemberSelectionPanel = new JSMemberSelectionPanel("Generate test methods for:", memberInfos, null);
}
Also used : ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) NullableComputable(com.intellij.openapi.util.NullableComputable) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) PsiManager(com.intellij.psi.PsiManager) ArrayList(java.util.ArrayList) ContentEntry(com.intellij.openapi.roots.ContentEntry) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) ModuleUtil(com.intellij.openapi.module.ModuleUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JSRefactoringUtil(com.intellij.lang.javascript.refactoring.util.JSRefactoringUtil) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) PsiElement(com.intellij.psi.PsiElement) Conditions(com.intellij.openapi.util.Conditions) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSReferenceEditor(com.intellij.lang.javascript.refactoring.ui.JSReferenceEditor) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) ThreeState(com.intellij.util.ThreeState) MarkRootActionBase(com.intellij.ide.projectView.actions.MarkRootActionBase) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IOException(java.io.IOException) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) ActionEvent(java.awt.event.ActionEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) JSMemberSelectionPanel(com.intellij.lang.javascript.refactoring.ui.JSMemberSelectionPanel) Nullable(org.jetbrains.annotations.Nullable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) PsiDirectory(com.intellij.psi.PsiDirectory) JSBundle(com.intellij.lang.javascript.JSBundle) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) JSMemberSelectionPanel(com.intellij.lang.javascript.refactoring.ui.JSMemberSelectionPanel) JSFunction(com.intellij.lang.javascript.psi.JSFunction) Module(com.intellij.openapi.module.Module) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Aggregations

JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)7 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)6 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)6 PsiElement (com.intellij.psi.PsiElement)5 JSFunction (com.intellij.lang.javascript.psi.JSFunction)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 JSMemberInfo (com.intellij.lang.javascript.refactoring.util.JSMemberInfo)3 JSVariable (com.intellij.lang.javascript.psi.JSVariable)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2 Module (com.intellij.openapi.module.Module)2 MemberInfoBase (com.intellij.refactoring.classMembers.MemberInfoBase)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 CodeInsightBundle (com.intellij.codeInsight.CodeInsightBundle)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 MarkRootActionBase (com.intellij.ide.projectView.actions.MarkRootActionBase)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 ActionScriptClassResolver (com.intellij.javascript.flex.resolve.ActionScriptClassResolver)1 ASTNode (com.intellij.lang.ASTNode)1