Search in sources :

Example 16 with THashSet

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

the class GrabDependencies method prepareQueries.

static Map<String, String> prepareQueries(PsiFile file) {
    final Set<GrAnnotation> grabs = new LinkedHashSet<>();
    final Set<GrAnnotation> excludes = new THashSet<>();
    final Set<GrAnnotation> resolvers = new THashSet<>();
    file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof GrAnnotation) {
                GrAnnotation anno = (GrAnnotation) element;
                String qname = anno.getQualifiedName();
                if (GrabAnnos.GRAB_ANNO.equals(qname))
                    grabs.add(anno);
                else if (GrabAnnos.GRAB_EXCLUDE_ANNO.equals(qname))
                    excludes.add(anno);
                else if (GrabAnnos.GRAB_RESOLVER_ANNO.equals(qname))
                    resolvers.add(anno);
            }
            super.visitElement(element);
        }
    });
    Function<GrAnnotation, String> mapper = grAnnotation -> grAnnotation.getText();
    String common = StringUtil.join(excludes, mapper, " ") + " " + StringUtil.join(resolvers, mapper, " ");
    LinkedHashMap<String, String> result = new LinkedHashMap<>();
    for (GrAnnotation grab : grabs) {
        String grabText = grab.getText();
        result.put(grabText, (grabText + " " + common).trim());
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) THashSet(gnu.trove.THashSet) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GroovyScriptRunConfiguration(org.jetbrains.plugins.groovy.runner.GroovyScriptRunConfiguration) Library(com.intellij.openapi.roots.libraries.Library) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Task(com.intellij.openapi.progress.Task) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) OrderRootType(com.intellij.openapi.roots.OrderRootType) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) IncorrectOperationException(com.intellij.util.IncorrectOperationException) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) NotificationType(com.intellij.notification.NotificationType) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) Function(com.intellij.util.Function) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) NotificationDisplayType(com.intellij.notification.NotificationDisplayType) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) ExecutionException(com.intellij.execution.ExecutionException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GrReferenceElement(org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement) ContainerUtil(com.intellij.util.containers.ContainerUtil) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) NotificationGroup(com.intellij.notification.NotificationGroup) Project(com.intellij.openapi.project.Project) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) ProcessOutputTypes(com.intellij.execution.process.ProcessOutputTypes) MalformedURLException(java.net.MalformedURLException) StringUtil(com.intellij.openapi.util.text.StringUtil) DefaultGroovyScriptRunner(org.jetbrains.plugins.groovy.runner.DefaultGroovyScriptRunner) Key(com.intellij.openapi.util.Key) Editor(com.intellij.openapi.editor.Editor) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) ExceptionUtil(com.intellij.util.ExceptionUtil) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Result(com.intellij.openapi.application.Result) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) JavaParameters(com.intellij.execution.configurations.JavaParameters) PathUtil(com.intellij.util.PathUtil) CantRunException(com.intellij.execution.CantRunException) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) THashSet(gnu.trove.THashSet)

Example 17 with THashSet

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

the class SceneBuilderImpl method collectCustomComponents.

private Collection<CustomComponent> collectCustomComponents() {
    if (myProject.isDisposed()) {
        return Collections.emptyList();
    }
    final PsiClass nodeClass = JavaPsiFacade.getInstance(myProject).findClass(JavaFxCommonNames.JAVAFX_SCENE_NODE, GlobalSearchScope.allScope(myProject));
    if (nodeClass == null) {
        return Collections.emptyList();
    }
    final Collection<PsiClass> psiClasses = CachedValuesManager.getCachedValue(nodeClass, () -> {
        // Take custom components from libraries, but not from the project modules, because SceneBuilder instantiates the components' classes.
        // Modules might be not compiled or may change since last compile, it's too expensive to keep track of that.
        final GlobalSearchScope scope = ProjectScope.getLibrariesScope(nodeClass.getProject());
        final String ideJdkVersion = Object.class.getPackage().getSpecificationVersion();
        final LanguageLevel ideLanguageLevel = LanguageLevel.parse(ideJdkVersion);
        final Query<PsiClass> query = ClassInheritorsSearch.search(nodeClass, scope, true, true, false);
        final Set<PsiClass> result = new THashSet<>();
        query.forEach(psiClass -> {
            if (psiClass.hasModifierProperty(PsiModifier.PUBLIC) && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT) && !isBuiltInComponent(psiClass) && isCompatibleLanguageLevel(psiClass, ideLanguageLevel)) {
                result.add(psiClass);
            }
        });
        return CachedValueProvider.Result.create(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    });
    if (psiClasses.isEmpty()) {
        return Collections.emptyList();
    }
    return prepareCustomComponents(psiClasses);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) THashSet(gnu.trove.THashSet)

Example 18 with THashSet

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

the class JarFromModulesTemplate method doCreateArtifact.

@Nullable
public NewArtifactConfiguration doCreateArtifact(final Module[] modules, final String mainClassName, final String directoryForManifest, final boolean extractLibrariesToJar, final boolean includeTests) {
    VirtualFile manifestFile = null;
    final Project project = myContext.getProject();
    if (mainClassName != null && !mainClassName.isEmpty() || !extractLibrariesToJar) {
        final VirtualFile directory;
        try {
            directory = ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<VirtualFile, IOException>() {

                @Override
                public VirtualFile compute() throws IOException {
                    return VfsUtil.createDirectoryIfMissing(directoryForManifest);
                }
            });
        } catch (IOException e) {
            LOG.info(e);
            Messages.showErrorDialog(project, "Cannot create directory '" + directoryForManifest + "': " + e.getMessage(), CommonBundle.getErrorTitle());
            return null;
        }
        if (directory == null)
            return null;
        manifestFile = ManifestFileUtil.createManifestFile(directory, project);
        if (manifestFile == null) {
            return null;
        }
        ManifestFileUtil.updateManifest(manifestFile, mainClassName, null, true);
    }
    String name = modules.length == 1 ? modules[0].getName() : project.getName();
    final PackagingElementFactory factory = PackagingElementFactory.getInstance();
    final CompositePackagingElement<?> archive = factory.createArchive(ArtifactUtil.suggestArtifactFileName(name) + ".jar");
    OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(project).orderEntries(Arrays.asList(modules));
    final Set<Library> libraries = new THashSet<>();
    if (!includeTests) {
        orderEnumerator = orderEnumerator.productionOnly();
    }
    final ModulesProvider modulesProvider = myContext.getModulesProvider();
    final OrderEnumerator enumerator = orderEnumerator.using(modulesProvider).withoutSdk().runtimeOnly().recursively();
    enumerator.forEachLibrary(new CommonProcessors.CollectProcessor<>(libraries));
    enumerator.forEachModule(module -> {
        if (ProductionModuleOutputElementType.ELEMENT_TYPE.isSuitableModule(modulesProvider, module)) {
            archive.addOrFindChild(factory.createModuleOutput(module));
        }
        if (includeTests && TestModuleOutputElementType.ELEMENT_TYPE.isSuitableModule(modulesProvider, module)) {
            archive.addOrFindChild(factory.createTestModuleOutput(module));
        }
        return true;
    });
    final JarArtifactType jarArtifactType = JarArtifactType.getInstance();
    if (manifestFile != null && !manifestFile.equals(ManifestFileUtil.findManifestFile(archive, myContext, jarArtifactType))) {
        archive.addFirstChild(factory.createFileCopyWithParentDirectories(manifestFile.getPath(), ManifestFileUtil.MANIFEST_DIR_NAME));
    }
    final String artifactName = name + ":jar";
    if (extractLibrariesToJar) {
        addExtractedLibrariesToJar(archive, factory, libraries);
        return new NewArtifactConfiguration(archive, artifactName, jarArtifactType);
    } else {
        final ArtifactRootElement<?> root = factory.createArtifactRootElement();
        List<String> classpath = new ArrayList<>();
        root.addOrFindChild(archive);
        addLibraries(libraries, root, archive, classpath);
        ManifestFileUtil.updateManifest(manifestFile, mainClassName, classpath, true);
        return new NewArtifactConfiguration(root, artifactName, PlainArtifactType.getInstance());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) OrderEnumerator(com.intellij.openapi.roots.OrderEnumerator) Library(com.intellij.openapi.roots.libraries.Library) CommonProcessors(com.intellij.util.CommonProcessors) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with THashSet

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

the class BuildArtifactsBeforeRunTaskProviderBase method configureTask.

public boolean configureTask(RunConfiguration runConfiguration, T task) {
    final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts();
    Set<ArtifactPointer> pointers = new THashSet<>();
    for (Artifact artifact : artifacts) {
        pointers.add(ArtifactPointerManager.getInstance(myProject).createPointer(artifact));
    }
    pointers.addAll(task.getArtifactPointers());
    ArtifactChooser chooser = new ArtifactChooser(new ArrayList<>(pointers));
    chooser.markElements(task.getArtifactPointers());
    chooser.setPreferredSize(JBUI.size(400, 300));
    DialogBuilder builder = new DialogBuilder(myProject);
    builder.setTitle(CompilerBundle.message("build.artifacts.before.run.selector.title"));
    builder.setDimensionServiceKey("#BuildArtifactsBeforeRunChooser");
    builder.addOkAction();
    builder.addCancelAction();
    builder.setCenterPanel(chooser);
    builder.setPreferredFocusComponent(chooser);
    if (builder.show() == DialogWrapper.OK_EXIT_CODE) {
        task.setArtifactPointers(chooser.getMarkedElements());
        return true;
    }
    return false;
}
Also used : DialogBuilder(com.intellij.openapi.ui.DialogBuilder) THashSet(gnu.trove.THashSet)

Example 20 with THashSet

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

the class CompilerManagerImpl method compileJavaCode.

@Override
public Collection<ClassObject> compileJavaCode(List<String> options, Collection<File> platformCp, Collection<File> classpath, Collection<File> modulePath, Collection<File> sourcePath, Collection<File> files, File outputDir) throws IOException, CompilationException {
    final Pair<Sdk, JavaSdkVersion> runtime = BuildManager.getJavacRuntimeSdk(myProject);
    final Sdk sdk = runtime.getFirst();
    final SdkTypeId type = sdk.getSdkType();
    String javaHome = null;
    if (type instanceof JavaSdkType) {
        javaHome = sdk.getHomePath();
        if (!isJdkOrJre(javaHome)) {
            // this can be a java-dependent SDK, implementing JavaSdkType
            // hack, because there is no direct way to obtain the java sdk, this sdk depends on
            final String binPath = ((JavaSdkType) type).getBinPath(sdk);
            javaHome = binPath != null ? new File(binPath).getParent() : null;
            if (!isJdkOrJre(javaHome)) {
                javaHome = null;
            }
        }
    }
    if (javaHome == null) {
        throw new IOException("Was not able to determine JDK for project " + myProject.getName());
    }
    final OutputCollector outputCollector = new OutputCollector();
    DiagnosticCollector diagnostic = new DiagnosticCollector();
    final Set<File> sourceRoots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    if (!sourcePath.isEmpty()) {
        for (File file : sourcePath) {
            sourceRoots.add(file);
        }
    } else {
        for (File file : files) {
            final File parentFile = file.getParentFile();
            if (parentFile != null) {
                sourceRoots.add(parentFile);
            }
        }
    }
    final Map<File, Set<File>> outs = Collections.singletonMap(outputDir, sourceRoots);
    final ExternalJavacManager javacManager = getJavacManager();
    boolean compiledOk = javacManager != null && javacManager.forkJavac(javaHome, -1, Collections.emptyList(), options, platformCp, classpath, modulePath, sourcePath, files, outs, diagnostic, outputCollector, new JavacCompilerTool(), CanceledStatus.NULL);
    if (!compiledOk) {
        final List<CompilationException.Message> messages = new SmartList<>();
        for (Diagnostic<? extends JavaFileObject> d : diagnostic.getDiagnostics()) {
            final JavaFileObject source = d.getSource();
            final URI uri = source != null ? source.toUri() : null;
            messages.add(new CompilationException.Message(kindToCategory(d.getKind()), d.getMessage(Locale.US), uri != null ? uri.toURL().toString() : null, (int) d.getLineNumber(), (int) d.getColumnNumber()));
        }
        throw new CompilationException("Compilation failed", messages);
    }
    final List<ClassObject> result = new ArrayList<>();
    for (OutputFileObject fileObject : outputCollector.getCompiledClasses()) {
        final BinaryContent content = fileObject.getContent();
        result.add(new CompiledClass(fileObject.getName(), fileObject.getClassName(), content != null ? content.toByteArray() : null));
    }
    return result;
}
Also used : JavacCompilerTool(org.jetbrains.jps.builders.impl.java.JavacCompilerTool) THashSet(gnu.trove.THashSet) BinaryContent(org.jetbrains.jps.incremental.BinaryContent) URI(java.net.URI) JavaFileObject(javax.tools.JavaFileObject) OutputFileObject(org.jetbrains.jps.javac.OutputFileObject) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) ExternalJavacManager(org.jetbrains.jps.javac.ExternalJavacManager) SmartList(com.intellij.util.SmartList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

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