Search in sources :

Example 66 with SmartList

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

the class TestIntegrationUtils method findSuitableFrameworks.

public static List<TestFramework> findSuitableFrameworks(PsiClass targetClass) {
    TestFramework[] frameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
    Project project = targetClass.getProject();
    List<TestFramework> result = new SmartList<>();
    for (TestFramework framework : frameworks) {
        if (isAvailableFor(project, framework)) {
            if (framework.isTestClass(targetClass)) {
                return Collections.singletonList(framework);
            }
            if (framework.isPotentialTestClass(targetClass)) {
                result.add(framework);
            }
        }
    }
    return result;
}
Also used : Project(com.intellij.openapi.project.Project) SmartList(com.intellij.util.SmartList)

Example 67 with SmartList

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

the class ExtendsClassChecker method checkExtendClass.

@NotNull
public static List<DomElementProblemDescriptor> checkExtendClass(final GenericDomValue element, final PsiClass value, final String name, final boolean instantiatable, final boolean canBeDecorator, final boolean allowInterface, final boolean allowNonPublic, final boolean allowAbstract, final boolean allowEnum, final DomElementAnnotationHolder holder) {
    final Project project = element.getManager().getProject();
    PsiClass extendClass = JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project));
    final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
    if (extendClass != null) {
        if (!name.equals(value.getQualifiedName()) && !value.isInheritor(extendClass, true)) {
            String message = DomBundle.message("class.is.not.a.subclass", value.getQualifiedName(), extendClass.getQualifiedName());
            list.add(holder.createProblem(element, message));
        }
    }
    if (instantiatable) {
        if (value.hasModifierProperty(PsiModifier.ABSTRACT)) {
            list.add(holder.createProblem(element, DomBundle.message("class.is.not.concrete", value.getQualifiedName())));
        } else if (!allowNonPublic && !value.hasModifierProperty(PsiModifier.PUBLIC)) {
            list.add(holder.createProblem(element, DomBundle.message("class.is.not.public", value.getQualifiedName())));
        } else if (!PsiUtil.hasDefaultConstructor(value, true)) {
            if (canBeDecorator) {
                boolean hasConstructor = false;
                for (PsiMethod method : value.getConstructors()) {
                    final PsiParameterList psiParameterList = method.getParameterList();
                    if (psiParameterList.getParametersCount() != 1)
                        continue;
                    PsiTypeElement typeElement = psiParameterList.getParameters()[0].getTypeElement();
                    if (typeElement != null) {
                        final PsiType psiType = typeElement.getType();
                        if (psiType instanceof PsiClassType) {
                            final PsiClass psiClass = ((PsiClassType) psiType).resolve();
                            if (psiClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, extendClass, true)) {
                                hasConstructor = true;
                                break;
                            }
                        }
                    }
                }
                if (!hasConstructor) {
                    list.add(holder.createProblem(element, DomBundle.message("class.decorator.or.has.default.constructor", value.getQualifiedName())));
                }
            } else {
                list.add(holder.createProblem(element, DomBundle.message("class.has.no.default.constructor", value.getQualifiedName())));
            }
        }
    }
    if (!allowInterface && value.isInterface()) {
        list.add(holder.createProblem(element, DomBundle.message("interface.not.allowed", value.getQualifiedName())));
    }
    if (!allowEnum && value.isEnum()) {
        list.add(holder.createProblem(element, DomBundle.message("enum.not.allowed", value.getQualifiedName())));
    }
    if (!allowAbstract && value.hasModifierProperty(PsiModifier.ABSTRACT) && !value.isInterface()) {
        list.add(holder.createProblem(element, DomBundle.message("abstract.class.not.allowed", value.getQualifiedName())));
    }
    return list;
}
Also used : Project(com.intellij.openapi.project.Project) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with SmartList

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

the class StructureViewTreeElement method getChildren.

@NotNull
public TreeElement[] getChildren() {
    final DomElement element = getElement();
    if (!element.isValid()) {
        return EMPTY_ARRAY;
    }
    final List<TreeElement> result = new SmartList<>();
    DomUtil.acceptAvailableChildren(element, new DomElementVisitor() {

        @Override
        public void visitDomElement(final DomElement domElement) {
            result.add(new StructureViewTreeElement(domElement));
        }
    });
    return ArrayUtil.toObjectArray(result, TreeElement.class);
}
Also used : DomElement(com.intellij.util.xml.DomElement) DomElementVisitor(com.intellij.util.xml.DomElementVisitor) SmartList(com.intellij.util.SmartList) DomStructureTreeElement(com.intellij.util.xml.structure.DomStructureTreeElement) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with SmartList

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

the class AngularJSCssInclusionContext method getContextFiles.

@NotNull
@Override
public PsiFile[] getContextFiles(@NotNull PsiFile current) {
    final PsiElement context = current.getContext();
    final JSProperty property = PsiTreeUtil.getParentOfType(context, JSProperty.class);
    if (property != null && "template".equals(property.getName())) {
        final JSObjectLiteralExpression object = (JSObjectLiteralExpression) property.getParent();
        final JSProperty styles = object.findProperty("styles");
        if (styles != null && styles.getValue() instanceof JSArrayLiteralExpression) {
            final List<PsiFile> result = new SmartList<>();
            for (JSExpression expression : ((JSArrayLiteralExpression) styles.getValue()).getExpressions()) {
                if (expression instanceof JSLiteralExpression && ((JSLiteralExpression) expression).isQuotedLiteral()) {
                    final List<Pair<PsiElement, TextRange>> injected = InjectedLanguageManager.getInstance(context.getProject()).getInjectedPsiFiles(expression);
                    if (injected != null) {
                        for (Pair<PsiElement, TextRange> pair : injected) {
                            if (pair.first instanceof StylesheetFile) {
                                result.add((PsiFile) pair.first);
                            }
                        }
                    }
                }
            }
            return result.toArray(PsiFile.EMPTY_ARRAY);
        }
    }
    return PsiFile.EMPTY_ARRAY;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) StylesheetFile(com.intellij.psi.css.StylesheetFile) PsiFile(com.intellij.psi.PsiFile) SmartList(com.intellij.util.SmartList) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with SmartList

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

the class DartFileUrlMapper method getUrls.

@NotNull
@Override
public List<Url> getUrls(@NotNull final VirtualFile file, @NotNull final Project project, @Nullable final String currentAuthority) {
    if (currentAuthority == null || file.getFileType() != DartFileType.INSTANCE)
        return Collections.emptyList();
    if (Registry.is("dart.redirect.to.pub.server", true) && ProjectFileIndex.getInstance(project).isInContent(file)) {
        final Pair<VirtualFile, String> servedDirAndPath = PubServerPathHandlerKt.getServedDirAndPathForPubServer(project, file);
        if (servedDirAndPath != null) {
            final VirtualFile servedDir = servedDirAndPath.first;
            final String path = servedDirAndPath.second;
            final String pubAuthority = BuiltInServerManagerImpl.isOnBuiltInWebServerByAuthority(currentAuthority) ? PubServerManager.getInstance(project).getPubServerAuthorityForServedDir(servedDir) : currentAuthority;
            if (pubAuthority != null) {
                return Collections.singletonList(Urls.newHttpUrl(pubAuthority, path));
            }
        }
    }
    final DartUrlResolver urlResolver = DartUrlResolver.getInstance(project, file);
    final String dartUri = urlResolver.getDartUrlForFile(file);
    if (!dartUri.startsWith(PACKAGE_PREFIX))
        return Collections.emptyList();
    if (BuiltInServerManagerImpl.isOnBuiltInWebServerByAuthority(currentAuthority)) {
        final List<Url> result = new SmartList<>();
        final VirtualFile pubspec = urlResolver.getPubspecYamlFile();
        final VirtualFile dartRoot = pubspec != null ? pubspec.getParent() : null;
        if (Registry.is("dart.redirect.to.pub.server", true)) {
            // package:PackageName/subdir/foo.dart -> http://localhost:45455/packages/PackageName/subdir/foo.dart
            final Collection<String> authorities = dartRoot != null ? PubServerManager.getInstance(project).getAlivePubServerAuthoritiesForDartRoot(pubspec.getParent()) : PubServerManager.getInstance(project).getAllAlivePubServerAuthorities();
            for (String pubAuthority : authorities) {
                final String pubUrlPath = "/packages/" + dartUri.substring(PACKAGE_PREFIX.length());
                result.add(Urls.newHttpUrl(pubAuthority, pubUrlPath));
            }
        } else if (dartRoot != null) {
            // for built-in server:
            // package:PackageName/subdir/foo.dart -> http://localhost:63342/ProjectName/MayBeRelPathToDartProject/web/packages/PackageName/subdir/foo.dart
            final String dartRootUrlPath = WebServerPathToFileManager.getInstance(project).getPath(dartRoot);
            if (dartRootUrlPath == null)
                return Collections.emptyList();
            //BuiltInWebBrowserUrlProviderKt.getBuiltInServerUrls(pubspec, project, currentAuthority);
            final Url dartRootUrl = Urls.newHttpUrl(currentAuthority, "/" + project.getName() + "/" + dartRootUrlPath);
            final String urlPath = StringUtil.trimEnd(dartRootUrl.getPath(), "/") + "/web/packages/" + dartUri.substring(PACKAGE_PREFIX.length());
            result.add(Urls.newHttpUrl(currentAuthority, urlPath));
        }
        return result;
    } else {
        // for any other server (e.g. localhost:8181):
        // package:PackageName/subdir/foo.dart -> http://localhost:8181/packages/PackageName/subdir/foo.dart
        final String urlPath = "/packages/" + dartUri.substring(PACKAGE_PREFIX.length());
        return Collections.singletonList(Urls.newHttpUrl(currentAuthority, urlPath));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) SmartList(com.intellij.util.SmartList) Url(com.intellij.util.Url) NotNull(org.jetbrains.annotations.NotNull)

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