Search in sources :

Example 1 with JSQualifiedNamedElement

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

the class FlexNavigationTest method doTest.

public static void doTest(Editor editor, @Nullable VirtualFile expectedForSource, @Nullable VirtualFile expectedForDoc, @Nullable String expectedClassName, @Nullable Consumer<PsiElement> customCheck) {
    PsiElement clazz = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
    Collection<PsiElement> elementsToCheck;
    GlobalSearchScope scope;
    if (clazz == null || !(clazz instanceof JSQualifiedNamedElement)) {
        PsiReference reference = TargetElementUtil.findReference(editor);
        assertNotNull(reference);
        elementsToCheck = TargetElementUtil.getInstance().getTargetCandidates(reference);
        scope = null;
    } else {
        elementsToCheck = Arrays.asList(clazz);
        final PsiFile file = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(editor.getDocument());
        final PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset());
        scope = JSResolveUtil.getResolveScope(elementAt);
    }
    assertTrue("Target elements not found", elementsToCheck.size() > 0);
    for (PsiElement element : elementsToCheck) {
        if (element instanceof JSQualifiedNamedElement) {
            String qName = ((JSQualifiedNamedElement) element).getQualifiedName();
            GlobalSearchScope searchScope = scope != null ? scope : JSResolveUtil.getResolveScope(element);
            final Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, qName.hashCode(), editor.getProject(), searchScope, JSQualifiedNamedElement.class);
            for (JSQualifiedNamedElement candidate : candidates) {
                if (!qName.equals(candidate.getQualifiedName())) {
                    continue;
                }
                doCheck(candidate, expectedForSource, expectedForDoc, customCheck);
                checkClassName(expectedClassName, candidate);
            }
        } else {
            doCheck(element, expectedForSource, expectedForDoc, customCheck);
            checkClassName(expectedClassName, element);
        }
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)

Example 2 with JSQualifiedNamedElement

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

the class SwcCatalogXmlUtil method getTimestampFromCatalogXml.

public static long getTimestampFromCatalogXml(@NotNull final PsiElement psiElement) {
    final Long cachedTimestamp = psiElement.getUserData(TIMESTAMP_IN_CATALOG_XML);
    if (cachedTimestamp != null) {
        return cachedTimestamp;
    }
    if (!(psiElement instanceof JSQualifiedNamedElement)) {
        return -1;
    }
    final String qName = ((JSQualifiedNamedElement) psiElement).getQualifiedName();
    if (StringUtil.isEmpty(qName)) {
        return -1;
    }
    final PsiFile psiFile = psiElement.getContainingFile();
    if (JavaScriptIndex.ECMASCRIPT_JS2.equals(psiFile.getName()))
        return Integer.MIN_VALUE;
    final VirtualFile swfFile = psiFile.getVirtualFile();
    final VirtualFile dir = swfFile != null && "swf".equalsIgnoreCase(swfFile.getExtension()) ? swfFile.getParent() : null;
    final VirtualFile catalogFile = dir == null ? null : dir.findChild("catalog.xml");
    if (catalogFile == null) {
        return -1;
    }
    Pair<Long, THashMap<String, TObjectLongHashMap<String>>> modStampAndSwfNameToQnameWithTimestampMap = catalogFile.getUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP);
    if (modStampAndSwfNameToQnameWithTimestampMap == null || modStampAndSwfNameToQnameWithTimestampMap.first != catalogFile.getModificationStamp()) {
        final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = parseTimestampsFromCatalogXml(catalogFile);
        modStampAndSwfNameToQnameWithTimestampMap = Pair.create(catalogFile.getModificationStamp(), swfNameToQnameWithTimestampMap);
        catalogFile.putUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP, modStampAndSwfNameToQnameWithTimestampMap);
    }
    final TObjectLongHashMap<String> qnameWithTimestampMap = modStampAndSwfNameToQnameWithTimestampMap.second.get(swfFile.getName());
    final long timestamp = qnameWithTimestampMap == null ? -1 : qnameWithTimestampMap.get(qName);
    psiElement.putUserData(TIMESTAMP_IN_CATALOG_XML, timestamp);
    return timestamp;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) THashMap(gnu.trove.THashMap) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiFile(com.intellij.psi.PsiFile)

Example 3 with JSQualifiedNamedElement

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

the class FlexMoveClassProcessor method findUsages.

@NotNull
@Override
protected UsageInfo[] findUsages() {
    Collection<UsageInfo> result = Collections.synchronizedCollection(new ArrayList<UsageInfo>());
    result.addAll(Arrays.asList(super.findUsages()));
    for (JSQualifiedNamedElement element : myElements) {
        if (element instanceof JSClass) {
            JSRefactoringUtil.addConstructorUsages((JSClass) element, result);
        }
        TextOccurrencesUtil.findNonCodeUsages(element, element.getQualifiedName(), mySearchInComments, mySearchInNonJavaFiles, StringUtil.getQualifiedName(myTargetPackage, element.getName()), result);
    }
    return result.toArray(new UsageInfo[result.size()]);
}
Also used : JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JSQualifiedNamedElement

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

the class ActionScriptImportHandler method resolveTypeNameUsingImports.

@Nullable
private static JSImportedElementResolveResult resolveTypeNameUsingImports(@NotNull final String referencedName, PsiNamedElement parent) {
    final Map<String, JSImportedElementResolveResult> map = myImportResolveCache.get(ourImportResolveCache, parent, null).getValue();
    JSImportedElementResolveResult result = map.get(referencedName);
    if (result == null) {
        SinkResolveProcessor resolveProcessor = new SinkResolveProcessor(referencedName, new ResolveResultSink(null, referencedName));
        INSTANCE.resolveTypeNameUsingImportsInner(resolveProcessor, parent);
        final ResolveResult[] resolveResults = resolveProcessor.getResultsAsResolveResults();
        assert resolveResults.length < 2;
        if (resolveResults.length == 1 && resolveResults[0] instanceof JSResolveResult) {
            JSResolveResult resolveResult = (JSResolveResult) resolveResults[0];
            final PsiElement element = resolveResult.getElement();
            String typeName = ((JSQualifiedNamedElement) element).getQualifiedName();
            result = new JSImportedElementResolveResult(typeName, element, resolveResult.getActionScriptImport());
        }
        map.put(referencedName, result != null ? result : JSImportedElementResolveResult.EMPTY_RESULT);
    }
    return result != JSImportedElementResolveResult.EMPTY_RESULT ? result : null;
}
Also used : JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with JSQualifiedNamedElement

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

the class AddImportECMAScriptClassOrFunctionAction method isAvailable.

public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
    if (!myReference.getElement().isValid())
        return false;
    final long modL = myReference.getElement().getManager().getModificationTracker().getModificationCount();
    if (!isAvailableCalculated || modL != modificationCount) {
        final ResolveResult[] results = myReference.multiResolve(false);
        boolean hasValidResult = false;
        for (ResolveResult r : results) {
            if (r.isValidResult()) {
                hasValidResult = true;
                break;
            }
        }
        if (!hasValidResult) {
            final Collection<JSQualifiedNamedElement> candidates = getCandidates(editor, file);
            isAvailableCalculated = true;
            isAvailable = candidates.size() > 0;
            String text;
            if (isAvailable) {
                final JSQualifiedNamedElement element = candidates.iterator().next();
                text = element.getQualifiedName() + "?";
                if (candidates.size() > 1)
                    text += " (multiple choices...)";
                if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
                    text += " Alt+Enter";
                }
            } else {
                text = "";
            }
            myText = text;
        } else {
            isAvailableCalculated = true;
            isAvailable = false;
            myText = "";
        }
        modificationCount = modL;
    }
    return isAvailable;
}
Also used : JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)

Aggregations

JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)27 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)12 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiFile (com.intellij.psi.PsiFile)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)8 JSFile (com.intellij.lang.javascript.psi.JSFile)4 Project (com.intellij.openapi.project.Project)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Nullable (org.jetbrains.annotations.Nullable)4 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 Module (com.intellij.openapi.module.Module)3 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 ArrayList (java.util.ArrayList)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 Attachment (com.intellij.openapi.diagnostic.Attachment)2