use of com.intellij.util.containers.hash.HashSet in project intellij-community by JetBrains.
the class GroovyFoldingBuilder method appendDescriptors.
private void appendDescriptors(PsiElement element, List<FoldingDescriptor> descriptors, Set<PsiElement> usedComments) {
ASTNode node = element.getNode();
if (node == null)
return;
IElementType type = node.getElementType();
if (TokenSets.BLOCK_SET.contains(type) && !isSingleHighLevelClassBody(element) || type == GroovyElementTypes.CLOSABLE_BLOCK) {
if (isMultiline(element)) {
collapseBlock(descriptors, element);
}
}
// comments
if ((type.equals(GroovyTokenTypes.mML_COMMENT) || type.equals(GroovyDocElementTypes.GROOVY_DOC_COMMENT)) && isMultiline(element) && isWellEndedComment(element)) {
descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
}
if (type.equals(GroovyTokenTypes.mSL_COMMENT) && !usedComments.contains(element)) {
boolean containsCustomRegionMarker = isCustomRegionElement(element);
usedComments.add(element);
PsiElement end = null;
for (PsiElement current = element.getNextSibling(); current != null; current = current.getNextSibling()) {
if (PsiImplUtil.isWhiteSpaceOrNls(current))
continue;
IElementType elementType = current.getNode().getElementType();
if (elementType == GroovyTokenTypes.mSL_COMMENT) {
end = current;
usedComments.add(current);
containsCustomRegionMarker |= isCustomRegionElement(current);
continue;
}
break;
}
if (end != null && !containsCustomRegionMarker) {
final TextRange range = new TextRange(element.getTextRange().getStartOffset(), end.getTextRange().getEndOffset());
descriptors.add(new FoldingDescriptor(element, range));
}
}
//multiline strings
addFoldingForStrings(descriptors, node);
Set<PsiElement> newUsedComments = new HashSet<>();
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
appendDescriptors(child, descriptors, newUsedComments);
}
if (element instanceof GroovyFile) {
processImports(descriptors, ((GroovyFile) element).getImportStatements());
}
}
use of com.intellij.util.containers.hash.HashSet in project android by JetBrains.
the class AndroidPrecompileTask method checkArtifacts.
private static boolean checkArtifacts(@NotNull CompileContext context) {
final Project project = context.getProject();
final CompileScope scope = context.getCompileScope();
final Set<Artifact> artifacts = ApplicationManager.getApplication().runReadAction(new Computable<Set<Artifact>>() {
@Override
public Set<Artifact> compute() {
return ArtifactCompileScope.getArtifactsToBuild(project, scope, false);
}
});
if (artifacts == null) {
return true;
}
final Set<Artifact> debugArtifacts = new HashSet<>();
final Set<Artifact> releaseArtifacts = new HashSet<>();
final Map<AndroidFacet, List<Artifact>> facet2artifacts = new HashMap<>();
for (final Artifact artifact : artifacts) {
final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
if (properties instanceof AndroidApplicationArtifactProperties) {
final AndroidArtifactSigningMode mode = ((AndroidApplicationArtifactProperties) properties).getSigningMode();
if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
debugArtifacts.add(artifact);
} else {
releaseArtifacts.add(artifact);
}
}
final AndroidFacet facet = ApplicationManager.getApplication().runReadAction(new Computable<AndroidFacet>() {
@Nullable
@Override
public AndroidFacet compute() {
return AndroidArtifactUtil.getPackagedFacet(project, artifact);
}
});
if (facet != null) {
List<Artifact> list = facet2artifacts.get(facet);
if (list == null) {
list = new ArrayList<>();
facet2artifacts.put(facet, list);
}
list.add(artifact);
}
}
boolean success = true;
if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + toString(debugArtifacts) + "\n" + "Release artifacts: " + toString(releaseArtifacts);
context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
success = false;
}
if (releaseArtifacts.size() > 0 && CompileStepBeforeRun.getRunConfiguration(context) != null) {
final String message = "Cannot build release Android artifacts in the 'make before run' session\n" + "Release artifacts: " + toString(releaseArtifacts);
context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
success = false;
}
for (Map.Entry<AndroidFacet, List<Artifact>> entry : facet2artifacts.entrySet()) {
final List<Artifact> list = entry.getValue();
final String moduleName = entry.getKey().getModule().getName();
if (list.size() > 1) {
final Artifact firstArtifact = list.get(0);
final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
for (int i = 1; i < list.size(); i++) {
final Artifact artifact = list.get(i);
if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
context.addMessage(CompilerMessageCategory.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName(), null, -1, -1);
success = false;
break;
}
}
}
}
return success;
}
use of com.intellij.util.containers.hash.HashSet in project android by JetBrains.
the class AndroidPrecompileTask method unexcludeAllSourceRoots.
private static void unexcludeAllSourceRoots(AndroidFacet facet, ExcludesConfiguration configuration) {
final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(facet.getModule()).getSourceRoots();
final Set<VirtualFile> sourceRootSet = new HashSet<>();
sourceRootSet.addAll(Arrays.asList(sourceRoots));
final String aidlGenSourceRootPath = AndroidRootUtil.getAidlGenSourceRootPath(facet);
if (aidlGenSourceRootPath != null) {
final VirtualFile aidlGenSourceRoot = LocalFileSystem.getInstance().findFileByPath(aidlGenSourceRootPath);
if (aidlGenSourceRoot != null) {
sourceRootSet.remove(aidlGenSourceRoot);
}
}
final String aptGenSourceRootPath = AndroidRootUtil.getAptGenSourceRootPath(facet);
if (aptGenSourceRootPath != null) {
final VirtualFile aptGenSourceRoot = LocalFileSystem.getInstance().findFileByPath(aptGenSourceRootPath);
if (aptGenSourceRoot != null) {
sourceRootSet.remove(aptGenSourceRoot);
}
}
final VirtualFile rsGenRoot = AndroidRootUtil.getRenderscriptGenDir(facet);
if (rsGenRoot != null) {
sourceRootSet.remove(rsGenRoot);
}
final VirtualFile buildconfigGenDir = AndroidRootUtil.getBuildconfigGenDir(facet);
if (buildconfigGenDir != null) {
sourceRootSet.remove(buildconfigGenDir);
}
final ExcludeEntryDescription[] descriptions = configuration.getExcludeEntryDescriptions();
configuration.removeAllExcludeEntryDescriptions();
for (ExcludeEntryDescription description : descriptions) {
final VirtualFile file = description.getVirtualFile();
if (file == null || !sourceRootSet.contains(file)) {
configuration.addExcludeEntryDescription(description);
}
}
}
use of com.intellij.util.containers.hash.HashSet in project android by JetBrains.
the class AndroidPrecompileTask method prepareForCompilation.
private static boolean prepareForCompilation(CompileContext context) {
final Project project = context.getProject();
if (!checkArtifacts(context)) {
return false;
}
checkAndroidDependencies(context);
ExcludesConfiguration configuration = CompilerConfiguration.getInstance(project).getExcludedEntriesConfiguration();
Set<ExcludeEntryDescription> addedEntries = new HashSet<>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
continue;
}
if (context.isRebuild()) {
clearResCache(facet, context);
}
final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
final int platformToolsRevision = platform != null ? platform.getSdkData().getPlatformToolsRevision() : -1;
LOG.debug("Platform-tools revision for module " + module.getName() + " is " + platformToolsRevision);
if (!facet.isAppProject()) {
if (platformToolsRevision >= 0 && platformToolsRevision <= 7) {
LOG.debug("Excluded sources of module " + module.getName());
excludeAllSourceRoots(module, configuration, addedEntries);
} else {
// todo: support this by project converter to use on compile-server
unexcludeAllSourceRoots(facet, configuration);
}
}
}
if (addedEntries.size() > 0) {
LOG.debug("Files excluded by Android: " + addedEntries.size());
project.getMessageBus().connect().subscribe(CompilerTopics.COMPILATION_STATUS, new MyCompilationStatusListener(project, addedEntries));
}
return true;
}
use of com.intellij.util.containers.hash.HashSet in project intellij-community by JetBrains.
the class LibraryJarUsagesCollector method getProjectUsages.
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) throws CollectUsagesException {
final LibraryJarDescriptor[] descriptors = LibraryJarStatisticsService.getInstance().getTechnologyDescriptors();
final Set<UsageDescriptor> result = new HashSet<>(descriptors.length);
ApplicationManager.getApplication().runReadAction(() -> {
for (LibraryJarDescriptor descriptor : descriptors) {
String className = descriptor.myClass;
if (className == null)
continue;
PsiClass[] psiClasses = JavaPsiFacade.getInstance(project).findClasses(className, ProjectScope.getLibrariesScope(project));
for (PsiClass psiClass : psiClasses) {
if (psiClass == null)
continue;
VirtualFile jarFile = JarFileSystem.getInstance().getLocalVirtualFileFor(psiClass.getContainingFile().getVirtualFile());
if (jarFile == null)
continue;
String version = getVersionByJarManifest(jarFile);
if (version == null) {
version = getVersionByJarFileName(jarFile.getName());
}
if (version == null || !StringUtil.containsChar(version, '.')) {
continue;
}
result.add(new UsageDescriptor(descriptor.myName + "_" + version, 1));
}
}
});
return result;
}
Aggregations