Search in sources :

Example 71 with SmartList

use of com.intellij.util.SmartList in project android by JetBrains.

the class AndroidPsiElementFinder method findClasses.

@NotNull
@Override
public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
    Project project = scope.getProject();
    if (project == null || !ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
        return PsiClass.EMPTY_ARRAY;
    }
    if (INTERNAL_R_CLASS_QNAME.equals(qualifiedName)) {
        CommonProcessors.CollectUniquesProcessor<PsiClass> processor = new CommonProcessors.CollectUniquesProcessor<PsiClass>();
        processInternalRClasses(project, scope, processor);
        Collection<PsiClass> results = processor.getResults();
        return results.isEmpty() ? PsiClass.EMPTY_ARRAY : results.toArray(new PsiClass[results.size()]);
    }
    final int lastDot = qualifiedName.lastIndexOf('.');
    if (lastDot < 0) {
        return PsiClass.EMPTY_ARRAY;
    }
    final String shortName = qualifiedName.substring(lastDot + 1);
    final String parentName = qualifiedName.substring(0, lastDot);
    if (shortName.length() == 0 || !parentName.endsWith(".R")) {
        return PsiClass.EMPTY_ARRAY;
    }
    List<PsiClass> result = new SmartList<PsiClass>();
    for (PsiClass parentClass : JavaPsiFacade.getInstance(project).findClasses(parentName, scope)) {
        ContainerUtil.addIfNotNull(result, parentClass.findInnerClassByName(shortName, false));
    }
    return result.isEmpty() ? PsiClass.EMPTY_ARRAY : result.toArray(new PsiClass[result.size()]);
}
Also used : Project(com.intellij.openapi.project.Project) CommonProcessors(com.intellij.util.CommonProcessors) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with SmartList

use of com.intellij.util.SmartList in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPsiTreeUtil method getStubChildrenOfTypeAsList.

@NotNull
public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList(@Nullable PsiElement element, @NotNull Class<T> aClass) {
    if (element == null)
        return Collections.emptyList();
    StubElement<?> stub = element instanceof StubBasedPsiElement ? ((StubBasedPsiElement) element).getStub() : null;
    if (stub == null) {
        return getChildrenOfTypeAsList(element, aClass);
    }
    List<T> result = new SmartList<T>();
    for (StubElement childStub : stub.getChildrenStubs()) {
        PsiElement child = childStub.getPsi();
        if (aClass.isInstance(child)) {
            //noinspection unchecked
            result.add((T) child);
        }
    }
    return result;
}
Also used : StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) SmartList(com.intellij.util.SmartList) StubElement(com.intellij.psi.stubs.StubElement) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 73 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class ArtifactUtil method findSourceFilesByOutputPath.

public static List<VirtualFile> findSourceFilesByOutputPath(CompositePackagingElement<?> parent, final String outputPath, final PackagingElementResolvingContext context, final ArtifactType artifactType) {
    final String path = StringUtil.trimStart(outputPath, "/");
    if (path.isEmpty()) {
        return Collections.emptyList();
    }
    int i = path.indexOf('/');
    final String firstName = i != -1 ? path.substring(0, i) : path;
    final String tail = i != -1 ? path.substring(i + 1) : "";
    final List<VirtualFile> result = new SmartList<>();
    processElementsWithSubstitutions(parent.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {

        @Override
        public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath elementPath) {
            //todo[nik] replace by method findSourceFile() in PackagingElement
            if (element instanceof CompositePackagingElement) {
                final CompositePackagingElement<?> compositeElement = (CompositePackagingElement<?>) element;
                if (firstName.equals(compositeElement.getName())) {
                    result.addAll(findSourceFilesByOutputPath(compositeElement, tail, context, artifactType));
                }
            } else if (element instanceof FileCopyPackagingElement) {
                final FileCopyPackagingElement fileCopyElement = (FileCopyPackagingElement) element;
                if (firstName.equals(fileCopyElement.getOutputFileName()) && tail.isEmpty()) {
                    ContainerUtil.addIfNotNull(result, fileCopyElement.findFile());
                }
            } else if (element instanceof DirectoryCopyPackagingElement || element instanceof ExtractedDirectoryPackagingElement) {
                final VirtualFile sourceRoot = ((FileOrDirectoryCopyPackagingElement<?>) element).findFile();
                if (sourceRoot != null) {
                    ContainerUtil.addIfNotNull(result, sourceRoot.findFileByRelativePath(path));
                }
            } else if (element instanceof ModuleOutputPackagingElement) {
                final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject());
                for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement) element).getSourceRoots(context)) {
                    final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path);
                    if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) {
                        result.add(sourceFile);
                    }
                }
            }
            return true;
        }
    });
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) SmartList(com.intellij.util.SmartList)

Example 74 with SmartList

use of com.intellij.util.SmartList in project intellij-plugins by JetBrains.

the class AS3InterfaceStubDumper method processModifierList.

@Override
protected void processModifierList(MemberInfo memberInfo, String attr, String indent) {
    StringTokenizer tokenizer = new StringTokenizer(attr, " ");
    List<JSAttributeList.ModifierType> modifiers = new SmartList<>();
    JSAttributeList.AccessType accessType = null;
    String ns = null;
    while (tokenizer.hasMoreTokens()) {
        String next = tokenizer.nextToken();
        boolean foundModifier = false;
        for (JSAttributeList.AccessType type : ourAccessTypes) {
            if (next.equalsIgnoreCase(type.name())) {
                accessType = type;
                foundModifier = true;
                break;
            }
        }
        if (!foundModifier) {
            for (JSAttributeList.ModifierType type : ourModifierTypes) {
                if (next.equalsIgnoreCase(type.name())) {
                    modifiers.add(type);
                    foundModifier = true;
                    break;
                }
            }
        }
        if (!foundModifier)
            ns = next;
    }
    Traits parentTraits = memberInfo.parentTraits;
    if (parentTraits.staticTrait != null) {
        parentTraits = parentTraits.staticTrait;
    }
    String resolvedNs = null;
    if (parentTraits.usedNamespacesToNamesMap != null) {
        List<String> keysByValue = parentTraits.usedNamespacesToNamesMap.getKeysByValue(ns);
        resolvedNs = keysByValue != null && keysByValue.size() > 0 ? keysByValue.get(0) : null;
    }
    parents.add(new ActionScriptAttributeListStubImpl(parents.getLast(), ns, resolvedNs, accessType, modifiers.toArray(new JSAttributeList.ModifierType[modifiers.size()])));
    super.processModifierList(memberInfo, attr, indent);
    parents.removeLast();
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) StringTokenizer(java.util.StringTokenizer) SmartList(com.intellij.util.SmartList)

Example 75 with SmartList

use of com.intellij.util.SmartList in project android by JetBrains.

the class InstantRunBuildAnalyzer method getApks.

private static Collection<ApkInfo> getApks(@NotNull InstantRunBuildInfo buildInfo, @NotNull InstantRunContext context) throws ExecutionException {
    List<ApkInfo> apks = new SmartList<>();
    for (InstantRunArtifact artifact : buildInfo.getArtifacts()) {
        if (artifact.type != MAIN) {
            String msg = "Expected to only find apks, but got : " + artifact.type + "\n";
            BuildSelection buildSelection = context.getBuildSelection();
            assert buildSelection != null : "Build must have completed before apks are obtained";
            if (buildSelection.getBuildMode() == BuildMode.HOT) {
                msg += "Could not use hot-swap artifacts when there is no existing session.";
            } else {
                msg += "Unexpected artifacts for build mode: " + buildSelection.getBuildMode();
            }
            InstantRunManager.LOG.error(msg);
            throw new ExecutionException(msg);
        }
        apks.add(new ApkInfo(artifact.file, context.getApplicationId()));
    }
    return apks;
}
Also used : ApkInfo(com.android.tools.idea.run.ApkInfo) InstantRunArtifact(com.android.tools.fd.client.InstantRunArtifact) SmartList(com.intellij.util.SmartList) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

SmartList (com.intellij.util.SmartList)163 NotNull (org.jetbrains.annotations.NotNull)70 Nullable (org.jetbrains.annotations.Nullable)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)14 TextRange (com.intellij.openapi.util.TextRange)12 PsiElement (com.intellij.psi.PsiElement)12 List (java.util.List)12 Element (org.jdom.Element)12 File (java.io.File)11 THashSet (gnu.trove.THashSet)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)8 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)6 IOException (java.io.IOException)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 IElementType (com.intellij.psi.tree.IElementType)5