use of com.intellij.util.containers.MultiMap in project intellij-plugins by JetBrains.
the class FelixRunner method setupParameters.
/**
* See <a href="http://felix.apache.org/site/apache-felix-framework-configuration-properties.html">Felix Configuration Properties</a>.
*/
@Override
protected void setupParameters(@NotNull JavaParameters parameters) {
ParametersList vmParameters = parameters.getVMParametersList();
// bundles and start levels
MultiMap<Integer, String> startBundles = new MultiMap<>();
List<String> installBundles = ContainerUtil.newSmartList();
for (SelectedBundle bundle : myBundles) {
String bundlePath = bundle.getBundlePath();
if (bundlePath == null)
continue;
boolean isFragment = CachingBundleInfoProvider.isFragmentBundle(bundlePath);
String bundleUrl = toFileUri(bundlePath);
if (bundle.isStartAfterInstallation() && !isFragment) {
int startLevel = getBundleStartLevel(bundle);
startBundles.putValue(startLevel, bundleUrl);
} else {
installBundles.add(bundleUrl);
}
}
for (Integer startLevel : startBundles.keySet()) {
vmParameters.addProperty("felix.auto.start." + startLevel, StringUtil.join(startBundles.get(startLevel), " "));
}
if (!installBundles.isEmpty()) {
vmParameters.addProperty("felix.auto.install.1", StringUtil.join(installBundles, " "));
}
int startLevel = getFrameworkStartLevel();
vmParameters.addProperty("org.osgi.framework.startlevel.beginning", String.valueOf(startLevel));
int defaultStartLevel = myRunConfiguration.getDefaultStartLevel();
vmParameters.addProperty("felix.startlevel.bundle", String.valueOf(defaultStartLevel));
// framework-specific options
vmParameters.addProperty("org.osgi.framework.storage.clean", "onFirstInit");
if (GenericRunProperties.isDebugMode(myAdditionalProperties)) {
vmParameters.addProperty("felix.log.level", "4");
}
parameters.setMainClass(MAIN_CLASS);
}
use of com.intellij.util.containers.MultiMap in project android by JetBrains.
the class AndroidApt method doCompile.
private static Map<AndroidCompilerMessageKind, List<String>> doCompile(@NotNull IAndroidTarget target, @NotNull String manifestFileOsPath, @NotNull String outDirOsPath, @NotNull String[] resourceDirsOsPaths, @NotNull List<Pair<String, String>> libRTxtFilesAndPackages, @Nullable String customPackage, boolean nonConstantIds, @Nullable String proguardCfgOutputFileOsPath, @Nullable String rTxtOutDirOsPath, boolean optimizeRFile) throws IOException {
final List<String> args = new ArrayList<String>();
BuildToolInfo buildToolInfo = target.getBuildToolInfo();
if (buildToolInfo == null) {
return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
}
args.add(buildToolInfo.getPath(BuildToolInfo.PathId.AAPT));
args.add("package");
args.add("-m");
if (nonConstantIds) {
args.add("--non-constant-id");
}
if (resourceDirsOsPaths.length > 1) {
args.add("--auto-add-overlay");
}
final Set<String> extraPackages = new HashSet<String>();
for (Pair<String, String> pair : libRTxtFilesAndPackages) {
extraPackages.add(pair.getSecond());
}
if (extraPackages.size() > 0) {
args.add("--extra-packages");
args.add(toPackagesString(ArrayUtil.toStringArray(extraPackages)));
}
if (customPackage != null) {
args.add("--custom-package");
args.add(customPackage);
}
if (rTxtOutDirOsPath != null) {
args.add("--output-text-symbols");
args.add(rTxtOutDirOsPath);
}
args.add("-J");
args.add(outDirOsPath);
args.add("-M");
args.add(manifestFileOsPath);
for (String libResFolderOsPath : resourceDirsOsPaths) {
args.add("-S");
args.add(libResFolderOsPath);
}
args.add("-I");
args.add(target.getPath(IAndroidTarget.ANDROID_JAR));
if (proguardCfgOutputFileOsPath != null) {
args.add("-G");
args.add(proguardCfgOutputFileOsPath);
}
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidExecutionUtil.doExecute(ArrayUtil.toStringArray(args));
LOG.info(AndroidCommonUtils.command2string(args));
if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
return messages;
}
if (optimizeRFile && !libRTxtFilesAndPackages.isEmpty() && rTxtOutDirOsPath != null) {
final File rFile = new File(rTxtOutDirOsPath, SdkConstants.FN_RESOURCE_TEXT);
// if the project has no resources the file could not exist.
if (rFile.isFile()) {
final SymbolLoader fullSymbolValues = new SymbolLoader(rFile);
fullSymbolValues.load();
final MultiMap<String, SymbolLoader> libMap = new MultiMap<String, SymbolLoader>();
for (Pair<String, String> pair : libRTxtFilesAndPackages) {
final File rTextFile = new File(pair.getFirst());
final String libPackage = pair.getSecond();
if (rTextFile.isFile()) {
final SymbolLoader libSymbols = new SymbolLoader(rTextFile);
libSymbols.load();
libMap.putValue(libPackage, libSymbols);
}
}
for (Map.Entry<String, Collection<SymbolLoader>> entry : libMap.entrySet()) {
final String libPackage = entry.getKey();
final Collection<SymbolLoader> symbols = entry.getValue();
final SymbolWriter writer = new SymbolWriter(outDirOsPath, libPackage, fullSymbolValues);
for (SymbolLoader symbolLoader : symbols) {
writer.addSymbolsToWrite(symbolLoader);
}
writer.write();
}
}
}
return messages;
}
use of com.intellij.util.containers.MultiMap in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoUnusedImportInspection method checkFile.
@Override
protected void checkFile(@NotNull GoFile file, @NotNull ProblemsHolder problemsHolder) {
MultiMap<String, GoImportSpec> importMap = file.getImportMap();
for (PsiElement importIdentifier : GoImportOptimizer.findRedundantImportIdentifiers(importMap)) {
problemsHolder.registerProblem(importIdentifier, "Redundant alias", ProblemHighlightType.LIKE_UNUSED_SYMBOL, OPTIMIZE_QUICK_FIX);
}
Set<GoImportSpec> duplicatedEntries = GoImportOptimizer.findDuplicatedEntries(importMap);
for (GoImportSpec duplicatedImportSpec : duplicatedEntries) {
problemsHolder.registerProblem(duplicatedImportSpec, "Redeclared import", ProblemHighlightType.GENERIC_ERROR, OPTIMIZE_QUICK_FIX);
}
for (Map.Entry<String, Collection<GoImportSpec>> specs : importMap.entrySet()) {
Iterator<GoImportSpec> imports = specs.getValue().iterator();
GoImportSpec originalImport = imports.next();
if (originalImport.isDot() || originalImport.isForSideEffects()) {
continue;
}
while (imports.hasNext()) {
GoImportSpec redeclaredImport = imports.next();
if (!duplicatedEntries.contains(redeclaredImport)) {
LocalQuickFix[] quickFixes = FindManager.getInstance(redeclaredImport.getProject()).canFindUsages(redeclaredImport) ? new LocalQuickFix[] { new GoRenameQuickFix(redeclaredImport) } : LocalQuickFix.EMPTY_ARRAY;
problemsHolder.registerProblem(redeclaredImport, "Redeclared import", ProblemHighlightType.GENERIC_ERROR, quickFixes);
}
}
}
if (importMap.containsKey(".")) {
if (!problemsHolder.isOnTheFly() || ApplicationManager.getApplication().isUnitTestMode())
resolveAllReferences(file);
}
MultiMap<String, GoImportSpec> unusedImportsMap = GoImportOptimizer.filterUnusedImports(file, importMap);
Set<GoImportSpec> unusedImportSpecs = ContainerUtil.newHashSet(unusedImportsMap.values());
for (PsiElement importEntry : unusedImportSpecs) {
GoImportSpec spec = GoImportOptimizer.getImportSpec(importEntry);
if (spec != null && spec.getImportString().resolve() != null) {
problemsHolder.registerProblem(spec, "Unused import", ProblemHighlightType.GENERIC_ERROR, OPTIMIZE_QUICK_FIX, IMPORT_FOR_SIDE_EFFECTS_QUICK_FIX);
}
}
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class CompileDriver method compileInExternalProcess.
@Nullable
private TaskFuture compileInExternalProcess(@NotNull final CompileContextImpl compileContext, final boolean onlyCheckUpToDate) throws Exception {
final CompileScope scope = compileContext.getCompileScope();
final Collection<String> paths = CompileScopeUtil.fetchFiles(compileContext);
List<TargetTypeBuildScope> scopes = getBuildScopes(compileContext, scope, paths);
// need to pass scope's user data to server
final Map<String, String> builderParams;
if (onlyCheckUpToDate) {
builderParams = Collections.emptyMap();
} else {
final Map<Key, Object> exported = scope.exportUserData();
if (!exported.isEmpty()) {
builderParams = new HashMap<>();
for (Map.Entry<Key, Object> entry : exported.entrySet()) {
final String _key = entry.getKey().toString();
final String _value = entry.getValue().toString();
builderParams.put(_key, _value);
}
} else {
builderParams = Collections.emptyMap();
}
}
final MessageBus messageBus = myProject.getMessageBus();
final MultiMap<String, Artifact> outputToArtifact = ArtifactCompilerUtil.containsArtifacts(scopes) ? ArtifactCompilerUtil.createOutputToArtifactMap(myProject) : null;
final BuildManager buildManager = BuildManager.getInstance();
buildManager.cancelAutoMakeTasks(myProject);
return buildManager.scheduleBuild(myProject, compileContext.isRebuild(), compileContext.isMake(), onlyCheckUpToDate, scopes, paths, builderParams, new DefaultMessageHandler(myProject) {
@Override
public void sessionTerminated(final UUID sessionId) {
if (compileContext.shouldUpdateProblemsView()) {
final ProblemsView view = ProblemsView.SERVICE.getInstance(myProject);
view.clearProgress();
view.clearOldMessages(compileContext.getCompileScope(), compileContext.getSessionId());
}
}
@Override
public void handleFailure(UUID sessionId, CmdlineRemoteProto.Message.Failure failure) {
compileContext.addMessage(CompilerMessageCategory.ERROR, failure.hasDescription() ? failure.getDescription() : "", null, -1, -1);
final String trace = failure.hasStacktrace() ? failure.getStacktrace() : null;
if (trace != null) {
LOG.info(trace);
}
compileContext.putUserData(COMPILE_SERVER_BUILD_STATUS, ExitStatus.ERRORS);
}
@Override
protected void handleCompileMessage(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
final CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind kind = message.getKind();
//System.out.println(compilerMessage.getText());
final String messageText = message.getText();
if (kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.PROGRESS) {
final ProgressIndicator indicator = compileContext.getProgressIndicator();
indicator.setText(messageText);
if (message.hasDone()) {
indicator.setFraction(message.getDone());
}
} else {
final CompilerMessageCategory category = kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.ERROR ? CompilerMessageCategory.ERROR : kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.WARNING ? CompilerMessageCategory.WARNING : CompilerMessageCategory.INFORMATION;
String sourceFilePath = message.hasSourceFilePath() ? message.getSourceFilePath() : null;
if (sourceFilePath != null) {
sourceFilePath = FileUtil.toSystemIndependentName(sourceFilePath);
}
final long line = message.hasLine() ? message.getLine() : -1;
final long column = message.hasColumn() ? message.getColumn() : -1;
final String srcUrl = sourceFilePath != null ? VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, sourceFilePath) : null;
compileContext.addMessage(category, messageText, srcUrl, (int) line, (int) column);
if (compileContext.shouldUpdateProblemsView() && kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.JPS_INFO) {
// treat JPS_INFO messages in a special way: add them as info messages to the problems view
final Project project = compileContext.getProject();
ProblemsView.SERVICE.getInstance(project).addMessage(new CompilerMessageImpl(project, category, messageText), compileContext.getSessionId());
}
}
}
@Override
protected void handleBuildEvent(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Type eventType = event.getEventType();
switch(eventType) {
case FILES_GENERATED:
final List<CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile> generated = event.getGeneratedFilesList();
final CompilationStatusListener publisher = !myProject.isDisposed() ? messageBus.syncPublisher(CompilerTopics.COMPILATION_STATUS) : null;
Set<String> writtenArtifactOutputPaths = outputToArtifact != null ? new THashSet<>(FileUtil.PATH_HASHING_STRATEGY) : null;
for (CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile generatedFile : generated) {
final String root = FileUtil.toSystemIndependentName(generatedFile.getOutputRoot());
final String relativePath = FileUtil.toSystemIndependentName(generatedFile.getRelativePath());
if (publisher != null) {
publisher.fileGenerated(root, relativePath);
}
if (outputToArtifact != null) {
Collection<Artifact> artifacts = outputToArtifact.get(root);
if (!artifacts.isEmpty()) {
for (Artifact artifact : artifacts) {
ArtifactsCompiler.addChangedArtifact(compileContext, artifact);
}
writtenArtifactOutputPaths.add(FileUtil.toSystemDependentName(DeploymentUtil.appendToPath(root, relativePath)));
}
}
}
if (writtenArtifactOutputPaths != null && !writtenArtifactOutputPaths.isEmpty()) {
ArtifactsCompiler.addWrittenPaths(compileContext, writtenArtifactOutputPaths);
}
break;
case BUILD_COMPLETED:
ExitStatus status = ExitStatus.SUCCESS;
if (event.hasCompletionStatus()) {
final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status completionStatus = event.getCompletionStatus();
switch(completionStatus) {
case CANCELED:
status = ExitStatus.CANCELLED;
break;
case ERRORS:
status = ExitStatus.ERRORS;
break;
case SUCCESS:
status = ExitStatus.SUCCESS;
break;
case UP_TO_DATE:
status = ExitStatus.UP_TO_DATE;
break;
}
}
compileContext.putUserDataIfAbsent(COMPILE_SERVER_BUILD_STATUS, status);
break;
case CUSTOM_BUILDER_MESSAGE:
if (event.hasCustomBuilderMessage()) {
final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.CustomBuilderMessage message = event.getCustomBuilderMessage();
if (GlobalOptions.JPS_SYSTEM_BUILDER_ID.equals(message.getBuilderId()) && GlobalOptions.JPS_UNPROCESSED_FS_CHANGES_MESSAGE_ID.equals(message.getMessageType())) {
final String text = message.getMessageText();
if (!StringUtil.isEmpty(text)) {
compileContext.addMessage(CompilerMessageCategory.INFORMATION, text, null, -1, -1);
}
}
}
break;
}
}
});
}
use of com.intellij.util.containers.MultiMap in project intellij-plugins by JetBrains.
the class ActionScriptGenerateDelegatesHandler method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
final JSClass jsClass = findClass(file, editor);
if (jsClass == null)
return;
Collection<JSField> fields = findCandidateFields(jsClass);
final JSField field;
if (ApplicationManager.getApplication().isUnitTestMode()) {
LOG.assertTrue(fields.size() == 1);
field = fields.iterator().next();
} else {
final MemberChooser<JSNamedElementNode> targetChooser = createMemberChooserDialog(project, jsClass, wrap(fields), false, false, CodeInsightBundle.message("generate.delegate.target.chooser.title"));
targetChooser.show();
if (targetChooser.getExitCode() != DialogWrapper.OK_EXIT_CODE)
return;
field = (JSField) targetChooser.getSelectedElements().get(0).getPsiElement();
}
JSType fieldType = field.getType();
if (fieldType == null)
return;
JSClass fieldClass = fieldType.resolveClass();
if (fieldClass == null)
return;
final boolean allowPackageLocal = !JSPsiImplUtils.differentPackageName(StringUtil.getPackageName(fieldClass.getQualifiedName()), StringUtil.getPackageName(jsClass.getQualifiedName()));
// don't add members along with their supers
class MemberDescriptor {
private final String name;
@Nullable
private final JSFunction.FunctionKind kind;
public MemberDescriptor(JSFunction method) {
name = method.getName();
kind = method.getKind();
}
public MemberDescriptor(JSVariable field) {
name = field.getName();
kind = null;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
MemberDescriptor that = (MemberDescriptor) o;
if (kind != that.kind)
return false;
if (!name.equals(that.name))
return false;
return true;
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + (kind != null ? kind.hashCode() : 0);
return result;
}
}
final Map<MemberDescriptor, JSNamedElement> memberCandidates = new HashMap<>();
ResolveProcessor p = new ResolveProcessor(null) {
{
setToProcessHierarchy(true);
}
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
JSClass clazz = JSUtils.getMemberContainingClass(element);
if (clazz == null || JSResolveUtil.isObjectClass(clazz) || clazz == jsClass) {
return true;
}
if (element instanceof JSFunction) {
JSFunction method = (JSFunction) element;
if (memberCandidates.containsKey(method.getName())) {
return true;
}
JSAttributeList attributeList = method.getAttributeList();
if (attributeList.getAccessType() == JSAttributeList.AccessType.PRIVATE || attributeList.getAccessType() == JSAttributeList.AccessType.PROTECTED) {
return true;
}
if (!allowPackageLocal && attributeList.getNamespace() == null && attributeList.getAccessType() == JSAttributeList.AccessType.PACKAGE_LOCAL) {
return true;
}
if (method.getKind() == JSFunction.FunctionKind.CONSTRUCTOR) {
return true;
}
if (attributeList.hasModifier(JSAttributeList.ModifierType.STATIC)) {
return true;
}
if (JSInheritanceUtil.findMethodInClass(method, jsClass, true) != null) {
return true;
}
memberCandidates.put(new MemberDescriptor(method), method);
} else if (element instanceof JSVariable) {
JSVariable f = (JSVariable) element;
if (memberCandidates.containsKey(f.getName())) {
return true;
}
JSAttributeList attributeList = f.getAttributeList();
if (attributeList.getAccessType() == JSAttributeList.AccessType.PRIVATE || attributeList.getAccessType() == JSAttributeList.AccessType.PROTECTED) {
return true;
}
if (!allowPackageLocal && attributeList.getAccessType() == JSAttributeList.AccessType.PACKAGE_LOCAL) {
return true;
}
if (jsClass.findFunctionByName(f.getName()) != null) {
return true;
}
memberCandidates.put(new MemberDescriptor(f), f);
}
return true;
}
};
fieldClass.processDeclarations(p, ResolveState.initial(), fieldClass, fieldClass);
Collection<JSNamedElementNode> selected;
if (ApplicationManager.getApplication().isUnitTestMode()) {
LOG.assertTrue(!memberCandidates.isEmpty());
selected = wrap(memberCandidates.values());
} else {
final MemberChooser<JSNamedElementNode> methodsChooser = createMemberChooserDialog(project, jsClass, wrap(memberCandidates.values()), false, true, CodeInsightBundle.message("generate.delegate.method.chooser.title"));
methodsChooser.show();
if (methodsChooser.getExitCode() != DialogWrapper.OK_EXIT_CODE)
return;
selected = methodsChooser.getSelectedElements();
}
BaseCreateMethodsFix fix = new BaseCreateMethodsFix<JSNamedElement>(jsClass) {
final JavaScriptGenerateAccessorHandler.MyBaseCreateMethodsFix generateGetterFix = new JavaScriptGenerateAccessorHandler.MyBaseCreateMethodsFix(JSGetterSetterGenerationMode.Getter, jsClass, null, false, field.getName());
final JavaScriptGenerateAccessorHandler.MyBaseCreateMethodsFix generateSetterFix = new JavaScriptGenerateAccessorHandler.MyBaseCreateMethodsFix(JSGetterSetterGenerationMode.Setter, jsClass, null, false, field.getName());
@Override
protected void adjustAttributeList(JSAttributeListWrapper attributeListWrapper, JSNamedElement function) {
attributeListWrapper.overrideAccessType(JSAttributeList.AccessType.PUBLIC);
attributeListWrapper.overrideModifier(JSAttributeList.ModifierType.STATIC, field.getAttributeList().hasModifier(JSAttributeList.ModifierType.STATIC));
for (JSAttributeList.ModifierType modifierType : new JSAttributeList.ModifierType[] { JSAttributeList.ModifierType.NATIVE, JSAttributeList.ModifierType.DYNAMIC, JSAttributeList.ModifierType.FINAL, JSAttributeList.ModifierType.OVERRIDE, JSAttributeList.ModifierType.VIRTUAL }) {
attributeListWrapper.overrideModifier(modifierType, false);
}
}
@Override
protected void processElements(Project project, MultiMap<String, String> types, Set<JSNamedElement> elementsToProcess) {
for (JSNamedElement e : elementsToProcess) {
if (e instanceof JSFunction) {
anchor = doAddOneMethod(project, buildFunctionText(e, types), anchor);
} else {
anchor = doAddOneMethod(project, generateGetterFix.buildFunctionText(e, types), anchor);
anchor = doAddOneMethod(project, generateSetterFix.buildFunctionText(e, types), anchor);
}
}
}
@Override
protected String buildFunctionBodyText(final String retType, final JSParameterList parameterList, final JSNamedElement element) {
return OverrideMethodsFix.buildDelegatingText(retType, parameterList, ((JSFunction) element), field.getName(), anchor != null ? anchor : myJsClass);
}
};
doInvoke(project, editor, file, selected, fix);
}
Aggregations