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;
}
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);
}
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());
}
}
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;
}
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;
}
Aggregations