Search in sources :

Example 96 with THashMap

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

the class FileChooserFactoryImpl method getMacroMap.

public static Map<String, String> getMacroMap() {
    final PathMacros macros = PathMacros.getInstance();
    final Set<String> allNames = macros.getAllMacroNames();
    final Map<String, String> map = new THashMap<>(allNames.size());
    for (String eachMacroName : allNames) {
        map.put("$" + eachMacroName + "$", macros.getValue(eachMacroName));
    }
    return map;
}
Also used : PathMacros(com.intellij.openapi.application.PathMacros) THashMap(gnu.trove.THashMap)

Example 97 with THashMap

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

the class ExternalizablePropertyContainer method readExternal.

public void readExternal(@NotNull Element element) {
    Map<String, AbstractProperty> propertyByName = new THashMap<>();
    for (AbstractProperty abstractProperty : myExternalizers.keySet()) {
        propertyByName.put(abstractProperty.getName(), abstractProperty);
    }
    for (Element child : element.getChildren()) {
        AbstractProperty property = propertyByName.get(child.getName());
        if (property == null) {
            continue;
        }
        Externalizer externalizer = myExternalizers.get(property);
        if (externalizer == null) {
            continue;
        }
        try {
            myValues.put(property, externalizer.readValue(child));
        } catch (Exception e) {
            LOG.info(e);
        }
    }
}
Also used : THashMap(gnu.trove.THashMap) Element(org.jdom.Element)

Example 98 with THashMap

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

the class FormsBindingManager method build.

@Override
public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
    ExitCode exitCode = ExitCode.NOTHING_DONE;
    final JpsProject project = context.getProjectDescriptor().getProject();
    final JpsUiDesignerConfiguration config = JpsUiDesignerExtensionService.getInstance().getOrCreateUiDesignerConfiguration(project);
    if (!config.isInstrumentClasses() && !config.isCopyFormsRuntimeToOutput()) {
        return exitCode;
    }
    final Map<File, ModuleBuildTarget> filesToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    final Map<File, ModuleBuildTarget> formsToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    final Map<File, Collection<File>> srcToForms = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    if (!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context) && config.isInstrumentClasses() && FORCE_FORMS_REBUILD_FLAG.get(context, Boolean.FALSE)) {
        // force compilation of all forms, but only once per chunk
        if (!FORMS_REBUILD_FORCED.get(context, Boolean.FALSE)) {
            FORMS_REBUILD_FORCED.set(context, Boolean.TRUE);
            FSOperations.markDirty(context, CompilationRound.CURRENT, chunk, FORM_SOURCES_FILTER);
        }
    }
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
            if (JAVA_SOURCES_FILTER.accept(file)) {
                filesToCompile.put(file, target);
            } else if (FORM_SOURCES_FILTER.accept(file)) {
                formsToCompile.put(file, target);
            }
            return true;
        }
    });
    if (config.isInstrumentClasses()) {
        final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
        final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
        // force compilation of bound source file if the form is dirty
        for (final Map.Entry<File, ModuleBuildTarget> entry : formsToCompile.entrySet()) {
            final File form = entry.getKey();
            final ModuleBuildTarget target = entry.getValue();
            final Collection<File> sources = findBoundSourceCandidates(context, target, form);
            for (File boundSource : sources) {
                if (!excludes.isExcluded(boundSource)) {
                    addBinding(boundSource, form, srcToForms);
                    FSOperations.markDirty(context, CompilationRound.CURRENT, boundSource);
                    filesToCompile.put(boundSource, target);
                    exitCode = ExitCode.OK;
                }
            }
        }
        // form should be considered dirty if the class it is bound to is dirty
        final OneToManyPathsMapping sourceToFormMap = context.getProjectDescriptor().dataManager.getSourceToFormMap();
        for (Map.Entry<File, ModuleBuildTarget> entry : filesToCompile.entrySet()) {
            final File srcFile = entry.getKey();
            final ModuleBuildTarget target = entry.getValue();
            final Collection<String> boundForms = sourceToFormMap.getState(srcFile.getPath());
            if (boundForms != null) {
                for (String formPath : boundForms) {
                    final File formFile = new File(formPath);
                    if (!excludes.isExcluded(formFile) && formFile.exists()) {
                        addBinding(srcFile, formFile, srcToForms);
                        FSOperations.markDirty(context, CompilationRound.CURRENT, formFile);
                        formsToCompile.put(formFile, target);
                        exitCode = ExitCode.OK;
                    }
                }
            }
        }
    }
    FORMS_TO_COMPILE.set(context, srcToForms.isEmpty() ? null : srcToForms);
    if (config.isCopyFormsRuntimeToOutput() && containsValidForm(formsToCompile.keySet())) {
        for (ModuleBuildTarget target : chunk.getTargets()) {
            if (!target.isTests()) {
                final File outputDir = target.getOutputDir();
                if (outputDir != null) {
                    final String outputRoot = FileUtil.toSystemIndependentName(outputDir.getPath());
                    final List<File> generatedFiles = CopyResourcesUtil.copyFormsRuntime(outputRoot, false);
                    if (!generatedFiles.isEmpty()) {
                        exitCode = ExitCode.OK;
                        // now inform others about files just copied
                        for (File file : generatedFiles) {
                            outputConsumer.registerOutputFile(target, file, Collections.<String>emptyList());
                        }
                    }
                }
            }
        }
    }
    return exitCode;
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) IOException(java.io.IOException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) THashMap(gnu.trove.THashMap) JpsUiDesignerConfiguration(org.jetbrains.jps.uiDesigner.model.JpsUiDesignerConfiguration) JpsProject(org.jetbrains.jps.model.JpsProject) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) THashMap(gnu.trove.THashMap)

Example 99 with THashMap

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

the class MavenProjectNamer method generateNameMap.

//private static Logger LOG = Logger.getInstance(MavenProjectNamer.class);
public static Map<MavenProject, String> generateNameMap(Collection<MavenProject> mavenProjects) {
    MultiMap<String, MavenProject> artifactIdMap = new MultiMap<>();
    for (MavenProject project : mavenProjects) {
        artifactIdMap.putValue(project.getMavenId().getArtifactId(), project);
    }
    Map<MavenProject, String> res = new THashMap<>();
    for (Map.Entry<String, Collection<MavenProject>> entry : artifactIdMap.entrySet()) {
        List<MavenProject> projectList = (List<MavenProject>) entry.getValue();
        String artifactId = entry.getKey();
        if (projectList.size() == 1) {
            res.put(projectList.get(0), artifactId);
        } else if (allGroupsAreDifferent(projectList)) {
            for (MavenProject mavenProject : projectList) {
                res.put(mavenProject, mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId());
            }
        } else if (allGroupsEqual(mavenProjects)) {
            for (MavenProject mavenProject : projectList) {
                res.put(mavenProject, mavenProject.getMavenId().getArtifactId() + ':' + mavenProject.getMavenId().getVersion());
            }
        } else {
            for (MavenProject mavenProject : projectList) {
                MavenId mavenId = mavenProject.getMavenId();
                res.put(mavenProject, mavenId.getGroupId() + ':' + mavenId.getArtifactId() + ':' + mavenId.getVersion());
            }
        }
    }
    return res;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) THashMap(gnu.trove.THashMap) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap)

Example 100 with THashMap

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

the class SceneBuilderImpl method loadBuiltinComponents.

@NotNull
private static Map<String, BuiltinComponent> loadBuiltinComponents(Predicate<String> psiClassExists) {
    final Map<String, BuiltinComponent> components = new THashMap<>();
    for (LibraryItem item : BuiltinLibrary.getLibrary().getItems()) {
        final Ref<String> refQualifiedName = new Ref<>();
        final List<String> imports = new ArrayList<>();
        final Map<String, String> attributes = new THashMap<>();
        final Ref<Boolean> rootTagProcessed = new Ref<>(false);
        NanoXmlUtil.parse(new StringReader(item.getFxmlText()), new NanoXmlUtil.IXMLBuilderAdapter() {

            @Override
            public void newProcessingInstruction(String target, Reader reader) throws Exception {
                if ("import".equals(target)) {
                    final String imported = StreamUtil.readTextFrom(reader);
                    imports.add(imported);
                }
            }

            @Override
            public void addAttribute(String key, String nsPrefix, String nsURI, String value, String type) throws Exception {
                if (rootTagProcessed.get())
                    return;
                if (key != null && value != null && StringUtil.isEmpty(nsPrefix)) {
                    attributes.put(key, value);
                }
            }

            @Override
            public void elementAttributesProcessed(String name, String nsPrefix, String nsURI) throws Exception {
                rootTagProcessed.set(true);
            }

            @Override
            public void startElement(String name, String nsPrefix, String nsURI, String systemID, int lineNr) throws Exception {
                if (rootTagProcessed.get())
                    return;
                for (String imported : imports) {
                    if (imported.equals(name) || imported.endsWith("." + name)) {
                        refQualifiedName.set(imported);
                        break;
                    }
                    if (imported.endsWith(".*")) {
                        String className = imported.substring(0, imported.length() - 1) + name;
                        if (psiClassExists.test(className)) {
                            refQualifiedName.set(className);
                            break;
                        }
                    }
                }
            }
        });
        final String qualifiedName = refQualifiedName.get();
        if (!StringUtil.isEmpty(qualifiedName)) {
            final BuiltinComponent previous = components.get(qualifiedName);
            if (previous == null || previous.getAttributes().size() < attributes.size()) {
                components.put(qualifiedName, new BuiltinComponent(attributes));
            }
        }
    }
    return components;
}
Also used : LibraryItem(com.oracle.javafx.scenebuilder.kit.library.LibraryItem) Reader(java.io.Reader) StringReader(java.io.StringReader) NanoXmlUtil(com.intellij.util.xml.NanoXmlUtil) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) StringReader(java.io.StringReader) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

THashMap (gnu.trove.THashMap)129 NotNull (org.jetbrains.annotations.NotNull)33 THashSet (gnu.trove.THashSet)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 Element (org.jdom.Element)18 PsiElement (com.intellij.psi.PsiElement)16 IOException (java.io.IOException)16 File (java.io.File)15 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)9 List (java.util.List)9 Module (com.intellij.openapi.module.Module)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 Map (java.util.Map)7 java.util (java.util)6 ArrayList (java.util.ArrayList)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Document (com.intellij.openapi.editor.Document)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5