use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class InlineSuperClassRefactoringProcessor method preprocessUsages.
@Override
protected boolean preprocessUsages(@NotNull final Ref<UsageInfo[]> refUsages) {
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final PushDownConflicts pushDownConflicts = new PushDownConflicts(mySuperClass, myMemberInfos, conflicts);
for (PsiClass targetClass : myTargetClasses) {
if (targetClass instanceof PsiAnonymousClass) {
conflicts.putValue(targetClass, "Cannot inline into anonymous class.");
} else if (PsiTreeUtil.isAncestor(mySuperClass, targetClass, false)) {
conflicts.putValue(targetClass, "Cannot inline into the inner class. Move \'" + targetClass.getName() + "\' to upper level");
} else {
for (MemberInfo info : myMemberInfos) {
final PsiMember member = info.getMember();
pushDownConflicts.checkMemberPlacementInTargetClassConflict(targetClass, member);
}
//todo check accessibility conflicts
}
}
if (myCurrentInheritor != null) {
ReferencesSearch.search(myCurrentInheritor).forEach(reference -> {
final PsiElement element = reference.getElement();
if (element != null) {
final PsiElement parent = element.getParent();
if (parent instanceof PsiNewExpression) {
final PsiClass aClass = PsiUtil.resolveClassInType(getPlaceExpectedType(parent));
if (aClass == mySuperClass) {
conflicts.putValue(parent, "Instance of target type is passed to a place where super class is expected.");
return false;
}
}
}
return true;
});
}
checkConflicts(refUsages, conflicts);
return showConflicts(conflicts, refUsages.get());
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class InlineSuperCallUsageInfo method getConflictMessage.
@Override
public String getConflictMessage() {
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final PsiElement element = getElement();
if (element instanceof PsiMethodCallExpression) {
PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) element;
final PsiMethod superConstructor = methodCallExpression.resolveMethod();
if (superConstructor != null) {
InlineMethodProcessor.addInaccessibleMemberConflicts(superConstructor, new UsageInfo[] { new UsageInfo(methodCallExpression.getMethodExpression()) }, new ReferencedElementsCollector() {
@Override
protected void checkAddMember(@NotNull PsiMember member) {
if (!PsiTreeUtil.isAncestor(superConstructor.getContainingClass(), member, false)) {
super.checkAddMember(member);
}
}
}, conflicts);
if (InlineMethodProcessor.checkBadReturns(superConstructor) && !InlineUtil.allUsagesAreTailCalls(superConstructor)) {
conflicts.putValue(superConstructor, CommonRefactoringUtil.capitalize(RefactoringBundle.message("refactoring.is.not.supported.when.return.statement.interrupts.the.execution.flow", "") + " of super constructor"));
}
}
}
//todo
return conflicts.isEmpty() ? null : conflicts.values().iterator().next();
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class CreateConstructorParameterFromFieldFix method addParameterToConstructor.
private static boolean addParameterToConstructor(final Project project, final PsiFile file, final Editor editor, final PsiMethod constructor, final PsiField[] fields, final List<SmartPsiElementPointer<PsiElement>> cleanupElements) throws IncorrectOperationException {
final PsiParameterList parameterList = constructor.getParameterList();
final PsiParameter[] parameters = parameterList.getParameters();
ParameterInfoImpl[] newParamInfos = new ParameterInfoImpl[parameters.length + fields.length];
final List<PsiVariable> params = new ArrayList<>(Arrays.asList(parameters));
Collections.addAll(params, fields);
Collections.sort(params, new FieldParameterComparator(parameterList));
int i = 0;
final Map<PsiField, String> usedFields = new HashMap<>();
final MultiMap<PsiType, PsiVariable> types = new MultiMap<>();
for (PsiVariable param : params) {
types.putValue(param.getType(), param);
}
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
final boolean preferLongerNames = settings.PREFER_LONGER_NAMES;
for (PsiVariable param : params) {
final PsiType paramType = param.getType();
if (param instanceof PsiParameter) {
newParamInfos[i++] = new ParameterInfoImpl(parameterList.getParameterIndex((PsiParameter) param), param.getName(), paramType, param.getName());
} else {
try {
settings.PREFER_LONGER_NAMES = preferLongerNames || types.get(paramType).size() > 1;
final String uniqueParameterName = getUniqueParameterName(parameters, param, usedFields);
usedFields.put((PsiField) param, uniqueParameterName);
newParamInfos[i++] = new ParameterInfoImpl(-1, uniqueParameterName, paramType, uniqueParameterName);
} finally {
settings.PREFER_LONGER_NAMES = preferLongerNames;
}
}
}
final SmartPointerManager manager = SmartPointerManager.getInstance(project);
final SmartPsiElementPointer constructorPointer = manager.createSmartPsiElementPointer(constructor);
final PsiMethod fromText = JavaPsiFacade.getElementFactory(project).createMethodFromText(createDummyMethod(constructor, newParamInfos), constructor);
final PsiClass containingClass = constructor.getContainingClass();
if (containingClass == null)
return false;
final int minUsagesNumber = containingClass.findMethodsBySignature(fromText, false).length > 0 ? 0 : 1;
final List<ParameterInfoImpl> parameterInfos = ChangeMethodSignatureFromUsageFix.performChange(project, editor, file, constructor, minUsagesNumber, newParamInfos, true, true);
if (parameterInfos == null)
return false;
final ParameterInfoImpl[] resultParams = parameterInfos.toArray(new ParameterInfoImpl[parameterInfos.size()]);
return ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return doCreate(project, editor, parameters, constructorPointer, resultParams, usedFields, cleanupElements);
}
});
}
use of com.intellij.util.containers.MultiMap in project intellij-plugins by JetBrains.
the class AngularJS2IndexingHandler method addImplicitElement.
private static JSElementIndexingDataImpl addImplicitElement(PsiElement element, JSElementIndexingDataImpl outData, String selector) {
if (selector == null)
return outData;
selector = selector.replace("\\n", "\n");
final MultiMap<String, String> attributesToElements = MultiMap.createSet();
PsiFile cssFile = PsiFileFactory.getInstance(element.getProject()).createFileFromText(JQueryCssLanguage.INSTANCE, selector);
CssSelectorList selectorList = PsiTreeUtil.findChildOfType(cssFile, CssSelectorList.class);
if (selectorList == null)
return outData;
for (CssSelector cssSelector : selectorList.getSelectors()) {
for (CssSimpleSelector simpleSelector : cssSelector.getSimpleSelectors()) {
String elementName = simpleSelector.getElementName();
boolean seenAttribute = false;
for (CssSelectorSuffix suffix : simpleSelector.getSelectorSuffixes()) {
if (!(suffix instanceof CssAttribute))
continue;
String name = ((CssAttribute) suffix).getAttributeName();
if (!StringUtil.isEmpty(name)) {
if (seenAttribute)
name = "[" + name + "]";
attributesToElements.putValue(name, elementName);
}
seenAttribute = true;
}
if (!seenAttribute)
attributesToElements.putValue("", elementName);
}
}
Set<String> added = new HashSet<>();
boolean template = isTemplate(element);
for (String elementName : attributesToElements.get("")) {
if (!added.add(elementName))
continue;
JSImplicitElementImpl.Builder elementBuilder = new JSImplicitElementImpl.Builder(elementName, element).setType(JSImplicitElement.Type.Class);
if (!attributesToElements.containsKey(elementName)) {
elementBuilder.setTypeString("E;;;");
} else {
Collection<String> elements = attributesToElements.get(elementName);
elementBuilder.setTypeString("AE;" + StringUtil.join(elements, ",") + ";;");
}
elementBuilder.setUserString(ANGULAR_DIRECTIVES_INDEX_USER_STRING);
if (outData == null)
outData = new JSElementIndexingDataImpl();
outData.addImplicitElement(elementBuilder.toImplicitElement());
}
for (Map.Entry<String, Collection<String>> entry : attributesToElements.entrySet()) {
JSImplicitElementImpl.Builder elementBuilder;
String attributeName = entry.getKey();
if (attributeName.isEmpty()) {
continue;
}
if (!added.add(attributeName))
continue;
if (outData == null)
outData = new JSElementIndexingDataImpl();
String elements = StringUtil.join(entry.getValue(), ",");
if (template && elements.isEmpty()) {
elementBuilder = new JSImplicitElementImpl.Builder(attributeName, element).setType(JSImplicitElement.Type.Class).setTypeString("A;template,ng-template;;");
elementBuilder.setUserString(ANGULAR_DIRECTIVES_INDEX_USER_STRING);
outData.addImplicitElement(elementBuilder.toImplicitElement());
}
final String prefix = isTemplate(element) && !attributeName.startsWith("[") ? "*" : "";
final String attr = prefix + attributeName;
elementBuilder = new JSImplicitElementImpl.Builder(attr, element).setType(JSImplicitElement.Type.Class).setTypeString("A;" + elements + ";;");
elementBuilder.setUserString(ANGULAR_DIRECTIVES_INDEX_USER_STRING);
outData.addImplicitElement(elementBuilder.toImplicitElement());
}
return outData;
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class CloudGitChooseAccountStepImpl method updateDataModel.
@Override
public void updateDataModel() {
super.updateDataModel();
final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
new RootIterator() {
CloudGitProjectRoot lastProjectRoot = null;
@Override
protected void processProjectRoot(CloudGitProjectRoot root) {
lastProjectRoot = root;
project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
}
@Override
protected void processJavaSourceRoot(DetectedSourceRoot root) {
project2sourceRoots.putValue(lastProjectRoot, root);
}
}.iterate();
List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
final File directory = projectRoot.getDirectory();
ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
final String applicationName = projectRoot.getApplicationName();
moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {
@Override
public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
final MessageBusConnection connection = module.getProject().getMessageBus().connect();
connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
if (addedModule == module) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
connection.disconnect();
}
}
});
}
private void onModuleAdded(Module module) {
createRunConfiguration(module, applicationName);
GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
}
});
modules.add(moduleDescriptor);
}
myProjectDescriptor.setModules(modules);
}
Aggregations