Search in sources :

Example 61 with MultiMap

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);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) UsageInfo(com.intellij.usageView.UsageInfo)

Example 62 with MultiMap

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);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) UsageInfo(com.intellij.usageView.UsageInfo)

Example 63 with MultiMap

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;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) Element(org.jdom.Element)

Example 64 with MultiMap

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);
        }
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ParametersList(com.intellij.execution.configurations.ParametersList) SelectedBundle(org.osmorc.run.ui.SelectedBundle)

Example 65 with MultiMap

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);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ParametersList(com.intellij.execution.configurations.ParametersList) SelectedBundle(org.osmorc.run.ui.SelectedBundle)

Aggregations

MultiMap (com.intellij.util.containers.MultiMap)138 NotNull (org.jetbrains.annotations.NotNull)37 UsageInfo (com.intellij.usageView.UsageInfo)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Project (com.intellij.openapi.project.Project)18 PsiElement (com.intellij.psi.PsiElement)18 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)16 Collection (java.util.Collection)16 Nullable (org.jetbrains.annotations.Nullable)15 Map (java.util.Map)14 File (java.io.File)11 HashSet (com.intellij.util.containers.HashSet)10 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 THashSet (gnu.trove.THashSet)9 java.util (java.util)9 Module (com.intellij.openapi.module.Module)8 com.intellij.psi (com.intellij.psi)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 ArrayList (java.util.ArrayList)7