use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class ConvertToInstanceMethodProcessor method preprocessUsages.
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
UsageInfo[] usagesIn = refUsages.get();
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final Set<PsiMember> methods = Collections.singleton((PsiMember) myMethod);
if (!myTargetClass.isInterface()) {
RefactoringConflictsUtil.analyzeAccessibilityConflicts(methods, myTargetClass, conflicts, myNewVisibility);
} else {
for (final UsageInfo usage : usagesIn) {
if (usage instanceof ImplementingClassUsageInfo) {
RefactoringConflictsUtil.analyzeAccessibilityConflicts(methods, ((ImplementingClassUsageInfo) usage).getPsiClass(), conflicts, PsiModifier.PUBLIC);
}
}
}
for (final UsageInfo usageInfo : usagesIn) {
if (usageInfo instanceof MethodCallUsageInfo) {
final PsiMethodCallExpression methodCall = ((MethodCallUsageInfo) usageInfo).getMethodCall();
final PsiExpression[] expressions = methodCall.getArgumentList().getExpressions();
final int index = myMethod.getParameterList().getParameterIndex(myTargetParameter);
if (index < expressions.length) {
PsiExpression instanceValue = expressions[index];
instanceValue = RefactoringUtil.unparenthesizeExpression(instanceValue);
if (instanceValue instanceof PsiLiteralExpression && ((PsiLiteralExpression) instanceValue).getValue() == null) {
String message = RefactoringBundle.message("0.contains.call.with.null.argument.for.parameter.1", RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(methodCall), true), CommonRefactoringUtil.htmlEmphasize(myTargetParameter.getName()));
conflicts.putValue(methodCall, message);
}
}
}
}
return showConflicts(conflicts, usagesIn);
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class EncapsulateFieldsProcessor method preprocessUsages.
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
checkExistingMethods(conflicts, true);
checkExistingMethods(conflicts, false);
final Collection<PsiClass> classes = ClassInheritorsSearch.search(myClass).findAll();
for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
final Set<PsiMethod> setters = new HashSet<>();
final Set<PsiMethod> getters = new HashSet<>();
for (PsiClass aClass : classes) {
final PsiMethod getterOverrider = myDescriptor.isToEncapsulateGet() ? aClass.findMethodBySignature(fieldDescriptor.getGetterPrototype(), false) : null;
if (getterOverrider != null) {
getters.add(getterOverrider);
}
final PsiMethod setterOverrider = myDescriptor.isToEncapsulateSet() ? aClass.findMethodBySignature(fieldDescriptor.getSetterPrototype(), false) : null;
if (setterOverrider != null) {
setters.add(setterOverrider);
}
}
if (!getters.isEmpty() || !setters.isEmpty()) {
final PsiField field = fieldDescriptor.getField();
for (PsiReference reference : ReferencesSearch.search(field)) {
final PsiElement place = reference.getElement();
if (place instanceof PsiReferenceExpression) {
final PsiExpression qualifierExpression = ((PsiReferenceExpression) place).getQualifierExpression();
final PsiClass ancestor;
if (qualifierExpression == null) {
ancestor = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
} else {
ancestor = PsiUtil.resolveClassInType(qualifierExpression.getType());
}
final boolean isGetter = !PsiUtil.isAccessedForWriting((PsiExpression) place);
for (PsiMethod overridden : isGetter ? getters : setters) {
if (InheritanceUtil.isInheritorOrSelf(myClass, ancestor, true)) {
conflicts.putValue(overridden, "There is already a " + RefactoringUIUtil.getDescription(overridden, true) + " which would hide generated " + (isGetter ? "getter" : "setter") + " for " + place.getText());
break;
}
}
}
}
}
}
UsageInfo[] infos = refUsages.get();
for (UsageInfo info : infos) {
PsiElement element = info.getElement();
if (element != null) {
PsiElement parent = element.getParent();
if (PsiUtil.isIncrementDecrementOperation(parent) && !(parent.getParent() instanceof PsiExpressionStatement)) {
conflicts.putValue(parent, "Unable to proceed with postfix/prefix expression when it's result type is used");
}
}
}
return showConflicts(conflicts, infos);
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class JpsLibraryTableSerializer method loadLibrary.
public static JpsLibrary loadLibrary(Element libraryElement, String name) {
String typeId = libraryElement.getAttributeValue(TYPE_ATTRIBUTE);
final JpsLibraryPropertiesSerializer<?> loader = getLibraryPropertiesSerializer(typeId);
JpsLibrary library = createLibrary(name, loader, libraryElement.getChild(PROPERTIES_TAG));
MultiMap<JpsOrderRootType, String> jarDirectories = new MultiMap<>();
MultiMap<JpsOrderRootType, String> recursiveJarDirectories = new MultiMap<>();
for (Element jarDirectory : JDOMUtil.getChildren(libraryElement, JAR_DIRECTORY_TAG)) {
String url = jarDirectory.getAttributeValue(URL_ATTRIBUTE);
String rootTypeId = jarDirectory.getAttributeValue(TYPE_ATTRIBUTE);
final JpsOrderRootType rootType = rootTypeId != null ? getRootType(rootTypeId) : JpsOrderRootType.COMPILED;
boolean recursive = Boolean.parseBoolean(jarDirectory.getAttributeValue(RECURSIVE_ATTRIBUTE));
jarDirectories.putValue(rootType, url);
if (recursive) {
recursiveJarDirectories.putValue(rootType, url);
}
}
for (Element rootsElement : libraryElement.getChildren()) {
final String rootTypeId = rootsElement.getName();
if (!rootTypeId.equals(JAR_DIRECTORY_TAG) && !rootTypeId.equals(PROPERTIES_TAG)) {
final JpsOrderRootType rootType = getRootType(rootTypeId);
for (Element rootElement : JDOMUtil.getChildren(rootsElement, ROOT_TAG)) {
String url = rootElement.getAttributeValue(URL_ATTRIBUTE);
JpsLibraryRoot.InclusionOptions options;
if (jarDirectories.get(rootType).contains(url)) {
final boolean recursive = recursiveJarDirectories.get(rootType).contains(url);
options = recursive ? JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY : JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT;
} else {
options = JpsLibraryRoot.InclusionOptions.ROOT_ITSELF;
}
library.addRoot(url, rootType, options);
}
}
}
return library;
}
use of com.intellij.util.containers.MultiMap in project intellij-plugins by JetBrains.
the class KnopflerfishRunner method setupParameters.
/**
* See <a href="http://www.knopflerfish.org/releases/current/docs/running.html">Running Knopflerfish</a>.
*/
@Override
protected void setupParameters(@NotNull JavaParameters parameters) {
ParametersList vmParameters = parameters.getVMParametersList();
ParametersList programParameters = parameters.getProgramParametersList();
// framework-specific options
vmParameters.addProperty("org.knopflerfish.framework.debug.errors", "true");
if (GenericRunProperties.isDebugMode(myAdditionalProperties)) {
// todo: more detailed settings in the dialog (?)
vmParameters.addProperty("org.knopflerfish.verbosity", "10");
vmParameters.addProperty("org.knopflerfish.framework.debug.startlevel", "true");
vmParameters.addProperty("org.knopflerfish.framework.debug.classloader", "true");
}
parameters.setMainClass(MAIN_CLASS);
programParameters.add("-init");
programParameters.add("-launch");
// 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);
if (bundle.isStartAfterInstallation() && !isFragment) {
int startLevel = getBundleStartLevel(bundle);
startBundles.putValue(startLevel, bundlePath);
} else {
installBundles.add(bundlePath);
}
}
if (!installBundles.isEmpty()) {
int defaultStartLevel = myRunConfiguration.getDefaultStartLevel();
programParameters.addAll("-initlevel", String.valueOf(defaultStartLevel));
for (String bundle : installBundles) {
programParameters.addAll("-install", bundle);
}
}
for (Integer startLevel : startBundles.keySet()) {
programParameters.addAll("-initlevel", String.valueOf(startLevel));
for (String bundle : startBundles.get(startLevel)) {
programParameters.addAll("-install", bundle);
}
}
int frameworkStartLevel = getFrameworkStartLevel();
programParameters.addAll("-startlevel", String.valueOf(frameworkStartLevel));
for (Integer startLevel : startBundles.keySet()) {
for (String bundle : startBundles.get(startLevel)) {
programParameters.addAll("-start", bundle);
}
}
}
use of com.intellij.util.containers.MultiMap in project intellij-plugins by JetBrains.
the class ConciergeRunner method setupParameters.
/**
* See <a href="http://concierge.sourceforge.net/properties.html">Concierge Startup 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("osgi.auto.start." + startLevel, StringUtil.join(startBundles.get(startLevel), " "));
}
if (!installBundles.isEmpty()) {
vmParameters.addProperty("osgi.auto.install", StringUtil.join(installBundles, " "));
}
int startLevel = getFrameworkStartLevel();
vmParameters.addProperty("osgi.startlevel.framework", String.valueOf(startLevel));
int defaultStartLevel = myRunConfiguration.getDefaultStartLevel();
vmParameters.addProperty("osgi.startlevel.bundle", String.valueOf(defaultStartLevel));
// framework-specific options
vmParameters.addProperty("osgi.init", "true");
if (GenericRunProperties.isDebugMode(myAdditionalProperties)) {
vmParameters.addProperty("ch.ethz.iks.concierge.debug", "true");
}
parameters.setMainClass(MAIN_CLASS);
}
Aggregations