Search in sources :

Example 1 with JSResolveResult

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

the class MxmlReferenceContributor method registerReferenceProviders.

@Override
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withLocalName(or(string().endsWith(STYLE_NAME_ATTR_SUFFIX), string().equalTo(STYLE_NAME_ATTR))).and(new FilterPattern(new ElementFilter() {

        public boolean isAcceptable(final Object element, final PsiElement context) {
            return !((PsiElement) element).textContains('{');
        }

        public boolean isClassAcceptable(final Class hintClass) {
            return true;
        }
    })), CssReferenceProviderUtil.CSS_CLASS_OR_ID_KEY_PROVIDER.getProvider());
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, new ElementFilter() {

        @Override
        public boolean isAcceptable(Object element, PsiElement context) {
            PsiElement parent = ((PsiElement) element).getParent();
            if (parent instanceof XmlAttribute) {
                XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
                if (descriptor instanceof AnnotationBackedDescriptorImpl) {
                    String format = ((AnnotationBackedDescriptor) descriptor).getFormat();
                    return FlexCssPropertyDescriptor.COLOR_FORMAT.equals(format);
                }
            }
            return false;
        }

        @Override
        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    }, true, new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull ProcessingContext context) {
            XmlAttributeValue value = (XmlAttributeValue) element;
            XmlAttribute parent = (XmlAttribute) value.getParent();
            int length = value.getTextLength();
            if (length >= 2) {
                AnnotationBackedDescriptor descriptor = (AnnotationBackedDescriptor) parent.getDescriptor();
                assert descriptor != null;
                if (JSCommonTypeNames.ARRAY_CLASS_NAME.equals(descriptor.getType())) {
                    // drop quotes
                    String text = element.getText().substring(1, length - 1);
                    final List<PsiReference> references = new ArrayList<>();
                    new ArrayAttributeValueProcessor() {

                        @Override
                        protected void processElement(int start, int end) {
                            references.add(new FlexColorReference(element, new TextRange(start + 1, end + 1)));
                        }
                    }.process(text);
                    return references.toArray(new PsiReference[references.size()]);
                } else {
                    // inside quotes
                    return new PsiReference[] { new FlexColorReference(element, new TextRange(1, length - 1)) };
                }
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, new ElementFilter() {

        public boolean isAcceptable(final Object element, final PsiElement context) {
            PsiElement parent = ((PsiElement) element).getParent();
            if (!(parent instanceof XmlAttribute) || !((XmlAttribute) parent).isNamespaceDeclaration()) {
                return false;
            }
            final PsiElement parentParent = parent.getParent();
            if (parentParent instanceof XmlTag && MxmlJSClass.isInsideTagThatAllowsAnyXmlContent((XmlTag) parentParent)) {
                return false;
            }
            return true;
        }

        public boolean isClassAcceptable(final Class hintClass) {
            return true;
        }
    }, true, new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
            final String trimmedText = StringUtil.unquoteString(element.getText());
            if (CodeContext.isPackageBackedNamespace(trimmedText)) {
                final JSReferenceSet referenceSet = new JSReferenceSet(element, trimmedText, 1, false, false) {

                    @Override
                    protected JSTextReference createTextReference(String s, int offset, boolean methodRef) {
                        return new JSTextReference(this, s, offset, methodRef) {

                            @Override
                            protected ResolveResult[] doResolve(@NotNull PsiFile psiFile) {
                                if ("*".equals(getCanonicalText())) {
                                    return new ResolveResult[] { new JSResolveResult(mySet.getElement()) };
                                }
                                return super.doResolve(psiFile);
                            }

                            @Override
                            protected MyResolveProcessor createResolveProcessor(String name, PsiElement place, ResultSink resultSink) {
                                return new MyResolveProcessor(name, place, resultSink) {

                                    @Override
                                    public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
                                        if (!(element instanceof JSPackageWrapper))
                                            return true;
                                        return super.execute(element, state);
                                    }
                                };
                            }
                        };
                    }
                };
                return referenceSet.getReferences();
            } else {
                return PsiReference.EMPTY_ARRAY;
            }
        }
    });
    // source attribute of Binding tag is handled in JSLanguageInjector
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { FlexReferenceContributor.DESTINATION_ATTR_NAME }, new ScopeFilter(new ParentElementFilter(new AndFilter(XmlTagFilter.INSTANCE, new TagNameFilter(BINDING_TAG_NAME), new NamespaceFilter(JavaScriptSupportLoader.LANGUAGE_NAMESPACES)), 2)), new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            final String trimmedText = StringUtil.unquoteString(element.getText());
            final JSReferenceSet referenceSet = new JSReferenceSet(element, trimmedText, 1, false);
            return referenceSet.getReferences();
        }
    });
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { FlexReferenceContributor.SOURCE_ATTR_NAME }, new ScopeFilter(new ParentElementFilter(new AndFilter(XmlTagFilter.INSTANCE, new ElementFilterBase<PsiElement>(PsiElement.class) {

        protected boolean isElementAcceptable(final PsiElement element, final PsiElement context) {
            return true;
        }
    }), 2)), new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            final XmlAttribute attribute = (XmlAttribute) element.getParent();
            final XmlTag tag = attribute.getParent();
            final String tagName = tag.getLocalName();
            final String trimmedText = StringUtil.unquoteString(element.getText());
            if (JavaScriptSupportLoader.isLanguageNamespace(tag.getNamespace())) {
                if (FlexPredefinedTagNames.SCRIPT.equals(tagName)) {
                    return ReferenceSupport.getFileRefs(element, element, 1, ReferenceSupport.LookupOptions.SCRIPT_SOURCE);
                }
                final String[] tagsWithSourceAttr = { MxmlJSClass.XML_TAG_NAME, FlexPredefinedTagNames.MODEL, JSCommonTypeNames.STRING_CLASS_NAME, JSCommonTypeNames.BOOLEAN_CLASS_NAME, JSCommonTypeNames.INT_TYPE_NAME, JSCommonTypeNames.UINT_TYPE_NAME, JSCommonTypeNames.NUMBER_CLASS_NAME };
                if (ArrayUtil.contains(tagName, tagsWithSourceAttr)) {
                    return ReferenceSupport.getFileRefs(element, element, 1, ReferenceSupport.LookupOptions.XML_AND_MODEL_SOURCE);
                }
                if (FlexPredefinedTagNames.STYLE.equals(tagName)) {
                    if (trimmedText.startsWith("http:")) {
                        return PsiReference.EMPTY_ARRAY;
                    } else {
                        return ReferenceSupport.getFileRefs(element, element, 1, ReferenceSupport.LookupOptions.STYLE_SOURCE);
                    }
                }
            }
            if (element.textContains('{') || element.textContains('@')) {
                return PsiReference.EMPTY_ARRAY;
            }
            final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
            final PsiElement psiElement = descriptor == null ? null : descriptor.getDeclaration();
            if (psiElement instanceof JSFunction) {
                final JSAttribute inspectableAttr = AnnotationBackedDescriptorImpl.findInspectableAttr(psiElement);
                if (inspectableAttr != null) {
                    final JSAttributeNameValuePair attributeNameValuePair = inspectableAttr.getValueByName(FORMAT_ATTR_NAME);
                    if (attributeNameValuePair != null && FILE_ATTR_VALUE.equals(attributeNameValuePair.getSimpleValue())) {
                        return ReferenceSupport.getFileRefs(element, element, 1, ReferenceSupport.LookupOptions.NON_EMBEDDED_ASSET);
                    }
                }
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
    final Function<PsiReference, LocalQuickFix[]> quickFixProvider = reference -> {
        final PsiElement element = reference.getElement();
        final String classFqn = getTrimmedValueAndRange((XmlElement) element).first;
        final String tagOrAttrName = element instanceof XmlAttributeValue ? ((XmlAttribute) element.getParent()).getName() : ((XmlTag) element).getLocalName();
        final CreateClassIntentionWithCallback[] intentions;
        if (SKIN_CLASS_ATTR_NAME.equals(tagOrAttrName)) {
            intentions = new CreateClassIntentionWithCallback[] { new CreateFlexSkinIntention(classFqn, element) };
        } else if ("firstView".equals(tagOrAttrName)) {
            intentions = new CreateClassIntentionWithCallback[] { new CreateFlexMobileViewIntentionAndFix(classFqn, element, false) };
        } else {
            intentions = new CreateClassIntentionWithCallback[] { new ActionScriptCreateClassOrInterfaceFix(classFqn, null, element), new CreateFlexComponentFix(classFqn, element) };
        }
        for (CreateClassIntentionWithCallback intention : intentions) {
            intention.setCreatedClassFqnConsumer(fqn -> {
                if (!element.isValid())
                    return;
                if (element instanceof XmlAttributeValue) {
                    ((XmlAttribute) element.getParent()).setValue(fqn);
                } else {
                    ((XmlTag) element).getValue().setText(fqn);
                }
            });
        }
        return intentions;
    };
    XmlUtil.registerXmlTagReferenceProvider(registrar, null, TrueFilter.INSTANCE, true, createReferenceProviderForTagOrAttributeExpectingJSClass(quickFixProvider));
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, TrueFilter.INSTANCE, createReferenceProviderForTagOrAttributeExpectingJSClass(quickFixProvider));
    registrar.registerReferenceProvider(xmlAttribute().withParent(XmlTag.class).with(new PatternCondition<XmlAttribute>("") {

        @Override
        public boolean accepts(@NotNull XmlAttribute xmlAttribute, ProcessingContext context) {
            String attrName = xmlAttribute.getLocalName();
            int dotPos = attrName.indexOf('.');
            if (dotPos == -1)
                return false;
            return JavaScriptSupportLoader.isFlexMxmFile(xmlAttribute.getContainingFile());
        }
    }), new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            String attrName = ((XmlAttribute) element).getLocalName();
            int dotPos = attrName.indexOf('.');
            if (dotPos == -1)
                return PsiReference.EMPTY_ARRAY;
            return new PsiReference[] { new FlexReferenceContributor.StateReference(element, new TextRange(dotPos + 1, attrName.length())) };
        }
    });
    XmlUtil.registerXmlTagReferenceProvider(registrar, null, new ElementFilterBase<XmlTag>(XmlTag.class) {

        protected boolean isElementAcceptable(final XmlTag element, final PsiElement context) {
            return element.getName().indexOf('.') != -1;
        }
    }, false, new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            final String name = ((XmlTag) element).getName();
            int dotIndex = name.indexOf('.');
            if (dotIndex == -1)
                return PsiReference.EMPTY_ARRAY;
            final int tagOffset = element.getTextRange().getStartOffset();
            final XmlToken startTagElement = XmlTagUtil.getStartTagNameElement((XmlTag) element);
            final XmlToken endTagElement = XmlTagUtil.getEndTagNameElement((XmlTag) element);
            if (startTagElement != null) {
                if (endTagElement != null && endTagElement.getText().equals(startTagElement.getText())) {
                    final int start1 = startTagElement.getTextRange().getStartOffset() - tagOffset;
                    final int start2 = endTagElement.getTextRange().getStartOffset() - tagOffset;
                    return new PsiReference[] { new FlexReferenceContributor.StateReference(element, new TextRange(start1 + dotIndex + 1, startTagElement.getTextRange().getEndOffset() - tagOffset)), new FlexReferenceContributor.StateReference(element, new TextRange(start2 + dotIndex + 1, endTagElement.getTextRange().getEndOffset() - tagOffset)) };
                } else {
                    final int start = startTagElement.getTextRange().getStartOffset() - tagOffset;
                    return new PsiReference[] { new FlexReferenceContributor.StateReference(element, new TextRange(start + dotIndex + 1, startTagElement.getTextRange().getEndOffset() - tagOffset)) };
                }
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { "basedOn", "fromState", "toState", FlexStateElementNames.NAME, FlexStateElementNames.STATE_GROUPS }, new ScopeFilter(new ParentElementFilter(new AndFilter(XmlTagFilter.INSTANCE, new NamespaceFilter(MxmlJSClass.MXML_URIS)), 2)), new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            final PsiElement parent = element.getParent();
            final PsiElement tag = parent.getParent();
            PsiReference ref = null;
            String tagName = ((XmlTag) tag).getLocalName();
            String attrName = ((XmlAttribute) parent).getName();
            String attrValue = ((XmlAttribute) parent).getValue();
            if (attrValue != null && attrValue.contains("{"))
                return PsiReference.EMPTY_ARRAY;
            if (FlexStateElementNames.NAME.equals(attrName)) {
                if ("State".equals(tagName)) {
                    ref = new AttributeValueSelfReference(element);
                } else {
                    return PsiReference.EMPTY_ARRAY;
                }
            } else if ("basedOn".equals(attrName) && element.getTextLength() == 2) {
                return PsiReference.EMPTY_ARRAY;
            } else if (FlexStateElementNames.STATE_GROUPS.equals(attrName)) {
                if ("State".equals(tagName)) {
                    return buildStateRefs(element, true);
                } else {
                    return PsiReference.EMPTY_ARRAY;
                }
            }
            if (FlexReferenceContributor.TRANSITION_TAG_NAME.equals(tagName)) {
                if ((element.textContains('*') && "*".equals(StringUtil.unquoteString(element.getText()))) || // empty value for attr, current state
                element.getTextLength() == 2) {
                    return PsiReference.EMPTY_ARRAY;
                }
            }
            if (ref == null) {
                ref = new FlexReferenceContributor.StateReference(element);
            }
            return new PsiReference[] { ref };
        }
    });
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { FlexStateElementNames.EXCLUDE_FROM, FlexStateElementNames.INCLUDE_IN }, new ScopeFilter(new ParentElementFilter(XmlTagFilter.INSTANCE, 2)), new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            return buildStateRefs(element, false);
        }
    });
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { CodeContext.TARGET_ATTR_NAME }, new ScopeFilter(new ParentElementFilter(new AndFilter(XmlTagFilter.INSTANCE, new TagNameFilter(CodeContext.REPARENT_TAG_NAME), new NamespaceFilter(JavaScriptSupportLoader.MXML_URI3)), 2)), new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new XmlIdValueReference(element) };
        }
    });
}
Also used : JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) PsiMetaData(com.intellij.psi.meta.PsiMetaData) com.intellij.psi.filters(com.intellij.psi.filters) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) CreateClassIntentionWithCallback(com.intellij.lang.javascript.validation.fixes.CreateClassIntentionWithCallback) CreateFlexComponentFix(com.intellij.lang.javascript.flex.actions.newfile.CreateFlexComponentFix) CssReferenceProviderUtil(com.intellij.psi.css.resolve.CssReferenceProviderUtil) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) LocalQuickFixProvider(com.intellij.codeInspection.LocalQuickFixProvider) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSReferenceSet(com.intellij.lang.javascript.psi.impl.JSReferenceSet) FlexCssPropertyDescriptor(com.intellij.javascript.flex.css.FlexCssPropertyDescriptor) PatternCondition(com.intellij.patterns.PatternCondition) FilterPattern(com.intellij.psi.filters.position.FilterPattern) XmlTagUtil(com.intellij.xml.util.XmlTagUtil) ResultSink(com.intellij.lang.javascript.psi.resolve.ResultSink) TextRange(com.intellij.openapi.util.TextRange) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) XmlPatterns.xmlAttribute(com.intellij.patterns.XmlPatterns.xmlAttribute) StandardPatterns.string(com.intellij.patterns.StandardPatterns.string) AttributeValueSelfReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.AttributeValueSelfReference) JSFunction(com.intellij.lang.javascript.psi.JSFunction) List(java.util.List) AnnotationBackedDescriptorImpl(com.intellij.javascript.flex.mxml.schema.AnnotationBackedDescriptorImpl) XmlPatterns(com.intellij.patterns.XmlPatterns) com.intellij.psi(com.intellij.psi) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) CreateFlexSkinIntention(com.intellij.lang.javascript.flex.actions.newfile.CreateFlexSkinIntention) CodeContext(com.intellij.javascript.flex.mxml.schema.CodeContext) StringTokenizer(com.intellij.util.text.StringTokenizer) CreateFlexMobileViewIntentionAndFix(com.intellij.lang.javascript.validation.fixes.CreateFlexMobileViewIntentionAndFix) ActionScriptCreateClassOrInterfaceFix(com.intellij.lang.javascript.validation.fixes.ActionScriptCreateClassOrInterfaceFix) ParentElementFilter(com.intellij.psi.filters.position.ParentElementFilter) JSTextReference(com.intellij.lang.javascript.psi.impl.JSTextReference) ArrayList(java.util.ArrayList) NamespaceFilter(com.intellij.psi.filters.position.NamespaceFilter) com.intellij.psi.xml(com.intellij.psi.xml) XmlUtil(com.intellij.xml.util.XmlUtil) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSPackageWrapper(com.intellij.lang.javascript.psi.ecmal4.impl.JSPackageWrapper) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) StandardPatterns.or(com.intellij.patterns.StandardPatterns.or) StringUtil(com.intellij.openapi.util.text.StringUtil) ReferenceSupport(com.intellij.lang.javascript.flex.ReferenceSupport) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSCommonTypeNames(com.intellij.lang.javascript.psi.JSCommonTypeNames) Pair(com.intellij.openapi.util.Pair) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) Collections(java.util.Collections) JSPackageWrapper(com.intellij.lang.javascript.psi.ecmal4.impl.JSPackageWrapper) FilterPattern(com.intellij.psi.filters.position.FilterPattern) CreateFlexMobileViewIntentionAndFix(com.intellij.lang.javascript.validation.fixes.CreateFlexMobileViewIntentionAndFix) List(java.util.List) ArrayList(java.util.ArrayList) CreateFlexComponentFix(com.intellij.lang.javascript.flex.actions.newfile.CreateFlexComponentFix) PatternCondition(com.intellij.patterns.PatternCondition) TextRange(com.intellij.openapi.util.TextRange) ParentElementFilter(com.intellij.psi.filters.position.ParentElementFilter) ParentElementFilter(com.intellij.psi.filters.position.ParentElementFilter) CreateClassIntentionWithCallback(com.intellij.lang.javascript.validation.fixes.CreateClassIntentionWithCallback) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResultSink(com.intellij.lang.javascript.psi.resolve.ResultSink) NotNull(org.jetbrains.annotations.NotNull) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) JSFunction(com.intellij.lang.javascript.psi.JSFunction) ActionScriptCreateClassOrInterfaceFix(com.intellij.lang.javascript.validation.fixes.ActionScriptCreateClassOrInterfaceFix) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSTextReference(com.intellij.lang.javascript.psi.impl.JSTextReference) AnnotationBackedDescriptorImpl(com.intellij.javascript.flex.mxml.schema.AnnotationBackedDescriptorImpl) JSReferenceSet(com.intellij.lang.javascript.psi.impl.JSReferenceSet) NamespaceFilter(com.intellij.psi.filters.position.NamespaceFilter) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) AttributeValueSelfReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.AttributeValueSelfReference) CreateFlexSkinIntention(com.intellij.lang.javascript.flex.actions.newfile.CreateFlexSkinIntention)

Example 2 with JSResolveResult

use of com.intellij.lang.javascript.psi.resolve.JSResolveResult in project oxy-template-support-plugin by mutant-industries.

the class InnerJsReferenceExpressionResolver method superResolveInPsiClassModified.

/**
 * modified supertype method, fixes the following issue: https://youtrack.jetbrains.com/issue/IDEA-138078
 *
 * @param aClass
 * @param isStatic
 * @return
 */
@NotNull
private List<ResolveResult> superResolveInPsiClassModified(PsiClass aClass, boolean isStatic) {
    SmartList<ResolveResult> results = new SmartList<>();
    Object candidates;
    Object field;
    if (myParent instanceof JSCallExpression) {
        candidates = aClass.findMethodsByName(myReferencedName, true);
    } else {
        field = aClass.findInnerClassByName(myReferencedName, true);
        if (field == null) {
            boolean inDefinitionExpr = myParent instanceof JSDefinitionExpression;
            String prefix = inDefinitionExpr ? "set" : "get";
            String candidate = prefix + StringUtil.capitalize(myReferencedName);
            PsiMethod[] hasStaticModifier = aClass.findMethodsByName(candidate, true);
            PsiMethod[] resolveProblem = hasStaticModifier;
            int resolveResult = hasStaticModifier.length;
            for (int i$1 = 0; i$1 < resolveResult; ++i$1) {
                PsiMethod accessor = resolveProblem[i$1];
                int parametersCount = accessor.getParameterList().getParametersCount();
                if (parametersCount == (inDefinitionExpr ? 1 : 0)) {
                    field = accessor;
                    break;
                }
            }
            if (field == null && !inDefinitionExpr) {
                prefix = "is";
                candidate = prefix + StringUtil.capitalize(myReferencedName);
                hasStaticModifier = aClass.findMethodsByName(candidate, true);
                resolveProblem = hasStaticModifier;
                resolveResult = hasStaticModifier.length;
                for (int i$1 = 0; i$1 < resolveResult; ++i$1) {
                    PsiMethod accessor = resolveProblem[i$1];
                    int parametersCount = accessor.getParameterList().getParametersCount();
                    if (parametersCount == 0) {
                        field = accessor;
                        break;
                    }
                }
            }
        }
        if (field == null) {
            field = aClass.findFieldByName(myReferencedName, true);
        }
        candidates = field != null ? new PsiModifierListOwner[] { (PsiModifierListOwner) field } : PsiMember.EMPTY_ARRAY;
    }
    int candidatesLength = ((Object[]) candidates).length;
    for (int var16 = 0; var16 < candidatesLength; ++var16) {
        Object var17 = ((Object[]) candidates)[var16];
        boolean var18 = ((PsiModifierListOwner) var17).hasModifierProperty("static");
        String var19 = isStatic && !var18 ? "javascript.instance.member.is.not.accessible.message" : (!((PsiModifierListOwner) var17).hasModifierProperty("public") ? "javascript.element.is.not.accessible.message" : null);
        JSResolveResult var20 = var19 == null ? new JSResolveResult((PsiElement) var17) : new JSResolveResult((PsiElement) var17, null, var19);
        results.add(var20);
    }
    return results;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) SmartList(com.intellij.util.SmartList) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JSResolveResult

use of com.intellij.lang.javascript.psi.resolve.JSResolveResult in project oxy-template-support-plugin by mutant-industries.

the class DwrReferenceResolver method resolve.

@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
    PsiClass dwrClass;
    // dwr method ---------------------------------------------------------------------
    if (!(myRef.getParent() instanceof JSReferenceExpression) && myRef.getFirstChild() instanceof JSReferenceExpression) {
        PsiElement reference = ((JSReferenceExpression) myRef.getFirstChild()).resolve();
        if (reference instanceof PsiClass && isDwrClass(dwrClass = (PsiClass) reference)) {
            for (PsiMethod method : dwrClass.getMethods()) {
                if (method.getName().equals(myReferencedName) && isDwrMethod(method)) {
                    return new JSResolveResult[] { new JSResolveResult(method) };
                }
            }
        }
    }
    ResolveResult[] parentResult = super.resolve(expression, incompleteCode);
    if (parentResult.length == 0) {
        // dwr class ----------------------------------------------------------------------
        if (myRef.getParent() instanceof JSReferenceExpression && !(myRef.getParent().getParent() instanceof JSReferenceExpression) || !(myRef.getParent() instanceof JSReferenceExpression) && !(myRef.getFirstChild() instanceof JSReferenceExpression)) {
            final GlobalSearchScope allScope = GlobalSearchScope.allScope(myRef.getProject());
            PsiClass remoteProxyAnnotation = JavaPsiFacade.getInstance(myRef.getProject()).findClass(DWR_REMOTE_PROXY_FQN, allScope);
            if (remoteProxyAnnotation != null && remoteProxyAnnotation.isAnnotationType()) {
                for (PsiReference remoteProxyAnnotationReference : ReferencesSearch.search(remoteProxyAnnotation).findAll()) {
                    PsiElement reference = remoteProxyAnnotationReference.getElement();
                    if ((dwrClass = PsiTreeUtil.getParentOfType(reference, PsiClass.class)) != null && dwrClass.getName().equals(myReferencedName)) {
                        return new JSResolveResult[] { new JSResolveResult(dwrClass) };
                    }
                }
            }
        }
    }
    return parentResult;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) PsiMethod(com.intellij.psi.PsiMethod) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) PsiReference(com.intellij.psi.PsiReference) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 4 with JSResolveResult

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

the class AngularJSReferenceExpressionResolver method resolve.

@NotNull
@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
    if (myReferencedName == null)
        return ResolveResult.EMPTY_ARRAY;
    if (myRef.getParent() instanceof JSDefinitionExpression) {
        final PsiElement sibling = PsiTreeUtil.prevVisibleLeaf(myRef);
        if (sibling != null && sibling.getNode().getElementType() == JSTokenTypes.LET_KEYWORD) {
            return new JSResolveResult[] { new JSResolveResult(myRef) };
        }
        final AngularJSRepeatExpression repeat = PsiTreeUtil.getParentOfType(myRef, AngularJSRepeatExpression.class);
        if (repeat != null) {
            for (JSDefinitionExpression def : repeat.getDefinitions()) {
                if (PsiTreeUtil.isAncestor(def, myRef, true))
                    return new JSResolveResult[] { new JSResolveResult(myRef) };
            }
        }
        final AngularJSAsExpression as = PsiTreeUtil.getParentOfType(myRef, AngularJSAsExpression.class);
        if (as != null) {
            if (PsiTreeUtil.isAncestor(as.getDefinition(), myRef, true))
                return new JSResolveResult[] { new JSResolveResult(myRef) };
        }
        JSClass clazz = myRef.getQualifier() == null ? AngularJS2IndexingHandler.findDirectiveClass(myRef) : null;
        if (clazz != null && DialectDetector.isTypeScript(clazz)) {
            final TypeScriptResolveProcessor localProcessor = new TypeScriptResolveProcessor(myReferencedName, myContainingFile, myRef, incompleteCode);
            localProcessor.setToProcessHierarchy(true);
            JSReferenceExpressionImpl.doProcessLocalDeclarations(clazz, myQualifier, localProcessor, false, false, null);
            return localProcessor.getResultsAsResolveResults();
        }
    }
    if (AngularJSAsExpression.isAsControllerRef(myRef, myRef.getParent())) {
        final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularControllerIndex.KEY, myReferencedName);
        if (resolve != null) {
            return new JSResolveResult[] { new JSResolveResult(resolve) };
        }
    } else if (AngularJSFilterExpression.isFilterNameRef(myRef, myParent)) {
        final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularFilterIndex.KEY, myReferencedName);
        if (resolve != null) {
            return new JSResolveResult[] { new JSResolveResult(resolve) };
        }
    } else if (myQualifier == null) {
        final Collection<JSPsiElementBase> localVariables = getItemsByName(myReferencedName, myRef);
        if (!localVariables.isEmpty()) {
            return ContainerUtil.map2Array(localVariables, JSResolveResult.class, item -> new JSResolveResult(item));
        }
    }
    return super.resolve(expression, incompleteCode);
}
Also used : JSPsiElementBase(com.intellij.lang.javascript.psi.JSPsiElementBase) AngularJSRepeatExpression(org.angularjs.lang.psi.AngularJSRepeatExpression) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) TypeScriptResolveProcessor(com.intellij.lang.javascript.ecmascript6.TypeScriptResolveProcessor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) AngularJSAsExpression(org.angularjs.lang.psi.AngularJSAsExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JSResolveResult

use of com.intellij.lang.javascript.psi.resolve.JSResolveResult in project oxy-template-support-plugin by mutant-industries.

the class InnerJsReferenceExpressionResolver method getResultsFromProcessor.

/**
 *  !!    TEMP CODE -  https://youtrack.jetbrains.com/issue/IDEA-138078    !!
 *
 * duplicated code to {@link NashornJSReferenceExpressionResolver#getResultsFromProcessor(WalkUpResolveProcessor)}
 *  - {@link super#resolveInPsiClass(PsiClass, boolean)} will one day (hopefully) be protected
 */
// --------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------
protected ResolveResult[] getResultsFromProcessor(WalkUpResolveProcessor processor) {
    List<JSTaggedResolveResult> taggedResolveResults = processor.getTaggedResolveResults();
    if (taggedResolveResults.isEmpty() || (taggedResolveResults.get(0)).hasTag(JSTaggedResolveResult.ResolveResultTag.PARTIAL)) {
        Module module;
        if (JSSymbolUtil.isAccurateReferenceExpression(this.myRef)) {
            if (this.myQualifier instanceof JSReferenceExpression) {
                PsiElement qualifierResolve = ((JSReferenceExpression) this.myQualifier).resolve();
                if (qualifierResolve instanceof PsiClass) {
                    List<ResolveResult> results = this.resolveInPsiClass((PsiClass) qualifierResolve, true);
                    return results.isEmpty() ? ResolveResult.EMPTY_ARRAY : results.toArray(new ResolveResult[results.size()]);
                }
            }
            JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(this.myContainingFile.getProject());
            module = ModuleUtilCore.findModuleForPsiElement(this.myContainingFile);
            JSQualifiedName qualifiedName = JSSymbolUtil.getAccurateReferenceName(this.myRef);
            if (qualifiedName != null) {
                qualifiedName = ((JSQualifiedNameImpl) qualifiedName).withoutInnermostComponent("Packages");
            }
            if (qualifiedName != null) {
                String qName = qualifiedName.getQualifiedName();
                if (module != null) {
                    PsiClass aClass = psiFacade.findClass(qName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
                    if (aClass != null) {
                        return new ResolveResult[] { new JSResolveResult(aClass) };
                    }
                }
                PsiPackage aPackage = psiFacade.findPackage(qName);
                if (aPackage != null) {
                    return new ResolveResult[] { new JSResolveResult(aPackage) };
                }
            }
        }
        JSTypeInfo typeInfo = processor.getTypeInfo();
        if (!typeInfo.myContextLevels.isEmpty() && (module = ModuleUtilCore.findModuleForPsiElement(this.myContainingFile)) != null) {
            JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(this.myContainingFile.getProject());
            GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
            List<ResolveResult> javaResults = new SmartList();
            boolean contextResolvesToJavaClass = false;
            Iterator var9 = typeInfo.myContextLevels.iterator();
            while (var9.hasNext()) {
                JSContextLevel level = (JSContextLevel) var9.next();
                JSQualifiedName qualifiedName = level.myNamespace.getQualifiedName();
                if (level.myRelativeLevel == 0 && qualifiedName != null) {
                    PsiClass aClass = psiFacade.findClass(qualifiedName.getQualifiedName(), scope);
                    if (aClass != null) {
                        contextResolvesToJavaClass = true;
                        List<ResolveResult> results = this.resolveInPsiClass(aClass, level.myNamespace.getJSContext() == JSContext.STATIC);
                        javaResults.addAll(results);
                    }
                }
            }
            if (contextResolvesToJavaClass) {
                return javaResults.toArray(ResolveResult.EMPTY_ARRAY);
            }
        }
    }
    return processor.getResults();
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) JSTypeInfo(com.intellij.lang.javascript.psi.resolve.JSTypeInfo) PsiClass(com.intellij.psi.PsiClass) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) PsiPackage(com.intellij.psi.PsiPackage) JSQualifiedName(com.intellij.lang.javascript.psi.JSQualifiedName) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Iterator(java.util.Iterator) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResolveResult(com.intellij.psi.ResolveResult) JSContextLevel(com.intellij.lang.javascript.psi.resolve.JSContextLevel) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSResolveResult (com.intellij.lang.javascript.psi.resolve.JSResolveResult)5 PsiElement (com.intellij.psi.PsiElement)4 ResolveResult (com.intellij.psi.ResolveResult)3 NotNull (org.jetbrains.annotations.NotNull)3 JSDefinitionExpression (com.intellij.lang.javascript.psi.JSDefinitionExpression)2 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSTaggedResolveResult (com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult)2 PsiMethod (com.intellij.psi.PsiMethod)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1 FlexCssPropertyDescriptor (com.intellij.javascript.flex.css.FlexCssPropertyDescriptor)1 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)1 AnnotationBackedDescriptorImpl (com.intellij.javascript.flex.mxml.schema.AnnotationBackedDescriptorImpl)1 CodeContext (com.intellij.javascript.flex.mxml.schema.CodeContext)1 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)1 TypeScriptResolveProcessor (com.intellij.lang.javascript.ecmascript6.TypeScriptResolveProcessor)1 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)1 ReferenceSupport (com.intellij.lang.javascript.flex.ReferenceSupport)1 CreateFlexComponentFix (com.intellij.lang.javascript.flex.actions.newfile.CreateFlexComponentFix)1 CreateFlexSkinIntention (com.intellij.lang.javascript.flex.actions.newfile.CreateFlexSkinIntention)1