Search in sources :

Example 96 with THashSet

use of gnu.trove.THashSet in project android by JetBrains.

the class ResourceTypeInspection method isGoodExpression.

private static InspectionResult isGoodExpression(@NotNull PsiExpression e, @NotNull AllowedValues allowedValues, @NotNull PsiElement scope, @NotNull PsiManager manager, @Nullable Set<PsiExpression> visited) {
    PsiExpression expression = PsiUtil.deparenthesizeExpression(e);
    if (expression == null)
        return InspectionResult.valid();
    if (visited == null)
        visited = new THashSet<>();
    if (!visited.add(expression))
        return InspectionResult.valid();
    if (expression instanceof PsiConditionalExpression) {
        PsiExpression thenExpression = ((PsiConditionalExpression) expression).getThenExpression();
        if (thenExpression != null && isAllowed(scope, thenExpression, allowedValues, manager, visited).isInvalid()) {
            return InspectionResult.invalid(thenExpression);
        }
        PsiExpression elseExpression = ((PsiConditionalExpression) expression).getElseExpression();
        return (elseExpression == null || !isAllowed(scope, elseExpression, allowedValues, manager, visited).isInvalid()) ? InspectionResult.valid() : InspectionResult.invalid(elseExpression);
    } else if (expression instanceof PsiNewExpression) {
        PsiArrayInitializerExpression arrayInitializerExpression = ((PsiNewExpression) expression).getArrayInitializer();
        if (arrayInitializerExpression != null) {
            return checkArrayInitializerExpression(arrayInitializerExpression, allowedValues, scope, manager, visited);
        }
    } else if (expression instanceof PsiArrayInitializerExpression) {
        return checkArrayInitializerExpression((PsiArrayInitializerExpression) expression, allowedValues, scope, manager, visited);
    }
    if (isOneOf(expression, allowedValues, manager)) {
        return InspectionResult.valid();
    }
    if (allowedValues.canBeOred) {
        PsiExpression zero = getLiteralExpression(expression, manager, "0");
        if (same(expression, zero, manager))
            return InspectionResult.valid();
        PsiExpression one = getLiteralExpression(expression, manager, "-1");
        if (same(expression, one, manager))
            return InspectionResult.valid();
        if (expression instanceof PsiPolyadicExpression) {
            IElementType tokenType = ((PsiPolyadicExpression) expression).getOperationTokenType();
            if (JavaTokenType.OR.equals(tokenType) || JavaTokenType.AND.equals(tokenType) || JavaTokenType.PLUS.equals(tokenType)) {
                for (PsiExpression operand : ((PsiPolyadicExpression) expression).getOperands()) {
                    if (isAllowed(scope, operand, allowedValues, manager, visited).isInvalid())
                        return InspectionResult.invalid(operand);
                }
                return InspectionResult.valid();
            }
        }
        if (expression instanceof PsiPrefixExpression && JavaTokenType.TILDE.equals(((PsiPrefixExpression) expression).getOperationTokenType())) {
            PsiExpression operand = ((PsiPrefixExpression) expression).getOperand();
            if (operand == null) {
                return InspectionResult.valid();
            }
            return isAllowed(scope, operand, allowedValues, manager, visited);
        }
    }
    PsiElement resolved = null;
    if (expression instanceof PsiReference) {
        resolved = ((PsiReference) expression).resolve();
    } else if (expression instanceof PsiCallExpression) {
        resolved = ((PsiCallExpression) expression).resolveMethod();
    }
    Constraints allowedForRef;
    if (resolved instanceof PsiModifierListOwner && (allowedForRef = getAllowedValues((PsiModifierListOwner) resolved, getType((PsiModifierListOwner) resolved), null)) != null && allowedForRef.isSubsetOf(allowedValues, manager)) {
        return InspectionResult.valid();
    }
    //noinspection ConstantConditions
    return PsiType.NULL.equals(expression.getType()) ? InspectionResult.valid() : InspectionResult.invalid(expression);
}
Also used : THashSet(gnu.trove.THashSet) IElementType(com.intellij.psi.tree.IElementType)

Example 97 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class DartProjectComponent method collectFolderUrlsToExclude.

private static Set<String> collectFolderUrlsToExclude(@NotNull final Module module, @NotNull final VirtualFile pubspecYamlFile) {
    final THashSet<String> newExcludedPackagesUrls = new THashSet<>();
    final VirtualFile root = pubspecYamlFile.getParent();
    newExcludedPackagesUrls.add(root.getUrl() + "/.pub");
    newExcludedPackagesUrls.add(root.getUrl() + "/build");
    newExcludedPackagesUrls.addAll(getExcludedPackageSymlinkUrls(module.getProject(), root));
    return newExcludedPackagesUrls;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet)

Example 98 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class DartIndexUtil method processImportOrExportStatement.

private static void processImportOrExportStatement(@NotNull final DartFileIndexData result, @NotNull final DartImportOrExportStatement importOrExportStatement) {
    final String uri = importOrExportStatement.getUriString();
    final Set<String> showComponentNames = new THashSet<>();
    for (DartShowCombinator showCombinator : importOrExportStatement.getShowCombinatorList()) {
        final DartLibraryReferenceList libraryReferenceList = showCombinator.getLibraryReferenceList();
        if (libraryReferenceList != null) {
            for (DartExpression expression : libraryReferenceList.getLibraryComponentReferenceExpressionList()) {
                showComponentNames.add(expression.getText());
            }
        }
    }
    final Set<String> hideComponentNames = new THashSet<>();
    for (DartHideCombinator hideCombinator : importOrExportStatement.getHideCombinatorList()) {
        final DartLibraryReferenceList libraryReferenceList = hideCombinator.getLibraryReferenceList();
        if (libraryReferenceList != null) {
            for (DartExpression expression : libraryReferenceList.getLibraryComponentReferenceExpressionList()) {
                hideComponentNames.add(expression.getText());
            }
        }
    }
    final DartComponentName importPrefixComponent = importOrExportStatement instanceof DartImportStatement ? ((DartImportStatement) importOrExportStatement).getImportPrefix() : null;
    final String importPrefix = importPrefixComponent != null ? importPrefixComponent.getName() : null;
    final Kind kind = importOrExportStatement instanceof DartImportStatement ? Kind.Import : Kind.Export;
    result.addImportInfo(new DartImportOrExportInfo(kind, uri, importPrefix, showComponentNames, hideComponentNames));
    result.addComponentInfo(importPrefix, new DartComponentInfo(DartComponentType.LABEL, null));
}
Also used : Kind(com.jetbrains.lang.dart.ide.index.DartImportOrExportInfo.Kind) THashSet(gnu.trove.THashSet)

Example 99 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class DartSymbolIndex method getItemsByName.

public static List<DartComponentName> getItemsByName(@NotNull final String name, @NotNull final Project project, @NotNull final GlobalSearchScope searchScope) {
    final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(DART_SYMBOL_INDEX, name, searchScope);
    final Set<DartComponentName> result = new THashSet<>();
    for (VirtualFile vFile : files) {
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
        for (PsiElement root : DartResolveUtil.findDartRoots(psiFile)) {
            processComponents(root, component -> {
                if (name.equals(component.getName())) {
                    result.add(component.getComponentName());
                }
                return true;
            });
        }
    }
    return new ArrayList<>(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Example 100 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class DartControlFlowUtil method getSimpleDeclarations.

public static Set<DartComponentName> getSimpleDeclarations(PsiElement[] children, @Nullable PsiElement lastParent, boolean stopAtLastParent) {
    final Set<DartComponentName> result = new THashSet<>();
    boolean addComponentsFlag = true;
    for (PsiElement child : children) {
        if (child == lastParent && stopAtLastParent) {
            addComponentsFlag = false;
        }
        if (addComponentsFlag && child instanceof DartVarDeclarationList) {
            addFromVarDeclarationList(result, (DartVarDeclarationList) child);
        } else if (child instanceof DartComponent) {
            boolean isFieldOrVar = child instanceof DartVarAccessDeclaration || child instanceof DartVarDeclarationListPart;
            if (!isFieldOrVar) {
                result.add(((DartComponent) child).getComponentName());
            }
        }
    }
    return result;
}
Also used : THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10