Search in sources :

Example 1 with JSElement

use of com.intellij.lang.javascript.psi.JSElement 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 2 with JSElement

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

the class FlexTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    List<AbstractTreeNode> result = new ArrayList<>();
    if (parent instanceof SwfQualifiedNamedElementNode || parent instanceof FlexFileNode) {
        if (((ProjectViewNode) parent).getSettings().isShowMembers()) {
            JSQualifiedNamedElement parentElement = getElement(parent);
            if (parentElement != null) {
                JSStructureViewElement structureViewElement = parentElement instanceof XmlBackedJSClassImpl ? new FlexStructureViewElement(((XmlBackedJSClassImpl) parentElement), (XmlFile) parentElement.getContainingFile(), false) : new JSStructureViewElement(parentElement, false, true);
                StructureViewTreeElement[] structureViewChildren = structureViewElement.getChildren();
                for (final StructureViewTreeElement structureViewChild : structureViewChildren) {
                    if (structureViewChild instanceof JSStructureViewElement) {
                        PsiElement childElement = ((JSStructureViewElement) structureViewChild).getValue();
                        result.add(new FlexClassMemberNode((JSElement) childElement, ((ProjectViewNode) parent).getSettings()));
                    } else {
                        result.add(new UnknownNode(parentElement.getProject(), structureViewChild, ((ProjectViewNode) parent).getSettings()));
                    }
                }
            }
        }
    } else {
        for (final AbstractTreeNode child : children) {
            Object o = child.getValue();
            if (o instanceof JSFileImpl && !(o instanceof PsiCompiledFile) && DialectDetector.isActionScript((PsiFile) o) || o instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) o)) {
                result.add(new FlexFileNode((PsiFile) o, ((ProjectViewNode) parent).getSettings()));
                continue;
            }
            result.add(child);
        }
    }
    return result;
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSStructureViewElement(com.intellij.lang.javascript.structureView.JSStructureViewElement) FlexStructureViewElement(com.intellij.lang.javascript.flex.presentation.FlexStructureViewProvider.FlexStructureViewElement) JSFileImpl(com.intellij.lang.javascript.psi.impl.JSFileImpl) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiCompiledFile(com.intellij.psi.PsiCompiledFile) JSElement(com.intellij.lang.javascript.psi.JSElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JSElement

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

the class FlexClassMemberNode method update.

@Override
protected void update(PresentationData presentation) {
    String text;
    JSElement value = getValue();
    if (value == null || !value.isValid()) {
        return;
    }
    if (value instanceof JSFunction) {
        text = JSFormatUtil.formatMethod(((JSFunction) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER, PsiFormatUtilBase.SHOW_TYPE);
    } else if (value instanceof JSVariable) {
        text = JSFormatUtil.formatField(((JSVariable) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER);
    } else {
        text = value.getName();
    }
    presentation.setPresentableText(text);
    presentation.setIcon(value.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSElement(com.intellij.lang.javascript.psi.JSElement) JSVariable(com.intellij.lang.javascript.psi.JSVariable)

Example 4 with JSElement

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

the class FlexQualifiedNameLocationProvider method findElement.

@Nullable
private static JSElement findElement(String link, Project project) {
    String moduleName = link.substring(0, link.indexOf(":"));
    Module module = ModuleManager.getInstance(project).findModuleByName(moduleName);
    link = link.substring(link.indexOf(":") + 1);
    final JavaScriptIndex index = JavaScriptIndex.getInstance(project);
    PsiElement element = ActionScriptClassResolver.findClassByQName(link, index, module);
    if (element instanceof JSClass) {
        return (JSElement) element;
    }
    if (element == null && link.contains(".") && link.endsWith("()")) {
        String qname = link.substring(0, link.lastIndexOf('.'));
        element = ActionScriptClassResolver.findClassByQName(qname, index, module);
        if (element instanceof JSClass) {
            String methodName = link.substring(link.lastIndexOf('.') + 1, link.length() - 2);
            return ((JSClass) element).findFunctionByNameAndKind(methodName, JSFunction.FunctionKind.SIMPLE);
        }
    }
    return null;
}
Also used : JavaScriptIndex(com.intellij.lang.javascript.index.JavaScriptIndex) JSElement(com.intellij.lang.javascript.psi.JSElement) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSElement (com.intellij.lang.javascript.psi.JSElement)4 PsiElement (com.intellij.psi.PsiElement)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)1 FlexStructureViewElement (com.intellij.lang.javascript.flex.presentation.FlexStructureViewProvider.FlexStructureViewElement)1 JavaScriptIndex (com.intellij.lang.javascript.index.JavaScriptIndex)1 JSExpression (com.intellij.lang.javascript.psi.JSExpression)1 JSFunction (com.intellij.lang.javascript.psi.JSFunction)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 JSVariable (com.intellij.lang.javascript.psi.JSVariable)1 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)1 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)1 JSFileImpl (com.intellij.lang.javascript.psi.impl.JSFileImpl)1 JSStructureViewElement (com.intellij.lang.javascript.structureView.JSStructureViewElement)1 Module (com.intellij.openapi.module.Module)1 PsiCompiledFile (com.intellij.psi.PsiCompiledFile)1