use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class EclipseImportBuilder method validate.
@Override
public boolean validate(final Project currentProject, final Project dstProject) {
final Ref<Exception> refEx = new Ref<>();
final Set<String> variables = new THashSet<>();
final Map<String, String> naturesNames = new THashMap<>();
final List<String> projectsToConvert = getParameters().projectsToConvert;
final boolean oneProjectToConvert = projectsToConvert.size() == 1;
final String separator = oneProjectToConvert ? "<br>" : ", ";
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
try {
for (String path : projectsToConvert) {
File classPathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
if (classPathFile.exists()) {
EclipseClasspathReader.collectVariables(variables, JDOMUtil.load(classPathFile), path);
}
collectUnknownNatures(path, naturesNames, separator);
}
} catch (IOException | JDOMException e) {
refEx.set(e);
}
}, EclipseBundle.message("eclipse.import.converting"), false, currentProject);
if (!refEx.isNull()) {
Messages.showErrorDialog(dstProject, refEx.get().getMessage(), getTitle());
return false;
}
if (!ProjectMacrosUtil.checkNonIgnoredMacros(dstProject, variables)) {
return false;
}
if (!naturesNames.isEmpty()) {
final String title = "Unknown Natures Detected";
final String naturesByProject;
if (oneProjectToConvert) {
naturesByProject = naturesNames.values().iterator().next();
} else {
naturesByProject = StringUtil.join(naturesNames.keySet(), projectPath -> projectPath + "(" + naturesNames.get(projectPath) + ")", "<br>");
}
Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:<br>" + naturesByProject + "<br>" + "Some settings may be lost after import.", NotificationType.WARNING));
}
return true;
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class XmlLanguageInjector method getXmlAnnotatedElementsValue.
private Trinity<Long, Pattern, Collection<String>> getXmlAnnotatedElementsValue() {
Trinity<Long, Pattern, Collection<String>> index = myXmlIndex;
if (index == null || myConfiguration.getModificationCount() != index.first.longValue()) {
final Map<ElementPattern<?>, BaseInjection> map = new THashMap<>();
for (BaseInjection injection : myConfiguration.getInjections(XmlLanguageInjectionSupport.XML_SUPPORT_ID)) {
for (InjectionPlace place : injection.getInjectionPlaces()) {
if (!place.isEnabled() || place.getElementPattern() == null)
continue;
map.put(place.getElementPattern(), injection);
}
}
final Collection<String> stringSet = PatternValuesIndex.buildStringIndex(map.keySet());
index = Trinity.create(myConfiguration.getModificationCount(), buildPattern(stringSet), stringSet);
myXmlIndex = index;
}
return index;
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class ExtractMethodSignatureSuggester method detectTopLevelExpressionsToReplaceWithParameters.
@Nullable
private InputVariables detectTopLevelExpressionsToReplaceWithParameters(List<PsiExpression> copies) {
final PsiParameter[] parameters = myExtractedMethod.getParameterList().getParameters();
final List<PsiVariable> inputVariables = new ArrayList<>(Arrays.asList(parameters));
final PsiCodeBlock body = myExtractedMethod.getBody();
LOG.assertTrue(body != null);
final PsiStatement[] pattern = body.getStatements();
final List<PsiExpression> exprs = new ArrayList<>();
for (PsiStatement statement : pattern) {
if (statement instanceof PsiExpressionStatement) {
final PsiExpression expression = ((PsiExpressionStatement) statement).getExpression();
if (expression instanceof PsiIfStatement || expression instanceof PsiLoopStatement) {
continue;
}
}
statement.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitCallExpression(PsiCallExpression callExpression) {
final PsiExpressionList list = callExpression.getArgumentList();
if (list != null) {
for (PsiExpression expression : list.getExpressions()) {
if (expression instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression) expression).resolve();
if (resolve instanceof PsiField) {
exprs.add(expression);
}
} else {
exprs.add(expression);
}
}
}
}
});
}
if (exprs.isEmpty()) {
return null;
}
final UniqueNameGenerator uniqueNameGenerator = new UniqueNameGenerator();
for (PsiParameter parameter : parameters) {
uniqueNameGenerator.addExistingName(parameter.getName());
}
SyntaxTraverser.psiTraverser().withRoot(myExtractedMethod.getBody()).filter(element -> element instanceof PsiVariable).forEach(element -> uniqueNameGenerator.addExistingName(((PsiVariable) element).getName()));
final THashMap<PsiExpression, String> unique = new THashMap<>(ourEquivalenceStrategy);
final Map<PsiExpression, String> replacement = new HashMap<>();
for (PsiExpression expr : exprs) {
String name = unique.get(expr);
if (name == null) {
final PsiType type = GenericsUtil.getVariableTypeByExpressionType(expr.getType());
if (type == null || type == PsiType.NULL || PsiUtil.resolveClassInType(type) instanceof PsiAnonymousClass || LambdaUtil.notInferredType(type))
return null;
copies.add(myElementFactory.createExpressionFromText(expr.getText(), body));
final SuggestedNameInfo info = JavaCodeStyleManager.getInstance(myProject).suggestVariableName(VariableKind.PARAMETER, null, expr, null);
final String paramName = info.names.length > 0 ? info.names[0] : "p";
name = uniqueNameGenerator.generateUniqueName(paramName);
final PsiParameter parameter = (PsiParameter) myExtractedMethod.getParameterList().add(myElementFactory.createParameter(name, type));
inputVariables.add(parameter);
unique.put(expr, name);
}
replacement.put(expr, name);
}
for (PsiExpression expression : replacement.keySet()) {
expression.replace(myElementFactory.createExpressionFromText(replacement.get(expression), null));
}
return new InputVariables(inputVariables, myExtractedMethod.getProject(), new LocalSearchScope(myExtractedMethod), false);
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class UpdateHighlightersUtil method setHighlightersOutsideRange.
// set highlights inside startOffset,endOffset but outside priorityRange
static void setHighlightersOutsideRange(@NotNull final Project project, @NotNull final Document document, @NotNull final PsiFile psiFile, @NotNull final List<HighlightInfo> infos, @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used
final int startOffset, final int endOffset, @NotNull final ProperTextRange priorityRange, final int group) {
ApplicationManager.getApplication().assertIsDispatchThread();
final DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project);
if (startOffset == 0 && endOffset == document.getTextLength()) {
codeAnalyzer.cleanFileLevelHighlights(project, group, psiFile);
}
final MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
assertMarkupConsistent(markup, project);
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
final HighlightersRecycler infosToRemove = new HighlightersRecycler();
ContainerUtil.quickSort(infos, BY_START_OFFSET_NODUPS);
Set<HighlightInfo> infoSet = new THashSet<>(infos);
Processor<HighlightInfo> processor = info -> {
if (info.getGroup() == group) {
RangeHighlighter highlighter = info.getHighlighter();
int hiStart = highlighter.getStartOffset();
int hiEnd = highlighter.getEndOffset();
if (!info.isFromInjection() && hiEnd < document.getTextLength() && (hiEnd <= startOffset || hiStart >= endOffset)) {
return true;
}
boolean toRemove = infoSet.contains(info) || !priorityRange.containsRange(hiStart, hiEnd) && (hiEnd != document.getTextLength() || priorityRange.getEndOffset() != document.getTextLength());
if (toRemove) {
infosToRemove.recycleHighlighter(highlighter);
info.setHighlighter(null);
}
}
return true;
};
DaemonCodeAnalyzerEx.processHighlightsOverlappingOutside(document, project, null, priorityRange.getStartOffset(), priorityRange.getEndOffset(), processor);
final Map<TextRange, RangeMarker> ranges2markersCache = new THashMap<>(10);
final boolean[] changed = { false };
RangeMarkerTree.sweep((RangeMarkerTree.Generator<HighlightInfo>) processor1 -> ContainerUtil.process(infos, processor1), (offset, info, atStart, overlappingIntervals) -> {
if (!atStart)
return true;
// injections are oblivious to restricting range
if (!info.isFromInjection() && info.getEndOffset() < document.getTextLength() && (info.getEndOffset() <= startOffset || info.getStartOffset() >= endOffset))
return true;
if (info.isFileLevelAnnotation()) {
codeAnalyzer.addFileLevelHighlight(project, group, info, psiFile);
changed[0] = true;
return true;
}
if (isWarningCoveredByError(info, overlappingIntervals, severityRegistrar)) {
return true;
}
if (info.getStartOffset() < priorityRange.getStartOffset() || info.getEndOffset() > priorityRange.getEndOffset()) {
createOrReuseHighlighterFor(info, colorsScheme, document, group, psiFile, (MarkupModelEx) markup, infosToRemove, ranges2markersCache, severityRegistrar);
changed[0] = true;
}
return true;
});
for (RangeHighlighter highlighter : infosToRemove.forAllInGarbageBin()) {
highlighter.dispose();
changed[0] = true;
}
if (changed[0]) {
clearWhiteSpaceOptimizationFlag(document);
}
assertMarkupConsistent(markup, project);
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class UpdateHighlightersUtil method setHighlightersInRange.
static void setHighlightersInRange(@NotNull final Project project, @NotNull final Document document, @NotNull final TextRange range, // if null global scheme will be used
@Nullable final EditorColorsScheme colorsScheme, @NotNull final List<HighlightInfo> infos, @NotNull final MarkupModelEx markup, final int group) {
ApplicationManager.getApplication().assertIsDispatchThread();
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
final HighlightersRecycler infosToRemove = new HighlightersRecycler();
DaemonCodeAnalyzerEx.processHighlights(document, project, null, range.getStartOffset(), range.getEndOffset(), info -> {
if (info.getGroup() == group) {
RangeHighlighter highlighter = info.getHighlighter();
int hiStart = highlighter.getStartOffset();
int hiEnd = highlighter.getEndOffset();
boolean willBeRemoved = hiEnd == document.getTextLength() && range.getEndOffset() == document.getTextLength() || range.containsRange(hiStart, hiEnd);
if (willBeRemoved) {
infosToRemove.recycleHighlighter(highlighter);
info.setHighlighter(null);
}
}
return true;
});
ContainerUtil.quickSort(infos, BY_START_OFFSET_NODUPS);
final Map<TextRange, RangeMarker> ranges2markersCache = new THashMap<>(10);
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
final DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project);
final boolean[] changed = { false };
RangeMarkerTree.sweep((RangeMarkerTree.Generator<HighlightInfo>) processor -> ContainerUtil.process(infos, processor), (offset, info, atStart, overlappingIntervals) -> {
if (!atStart) {
return true;
}
if (info.isFileLevelAnnotation() && psiFile != null && psiFile.getViewProvider().isPhysical()) {
codeAnalyzer.addFileLevelHighlight(project, group, info, psiFile);
changed[0] = true;
return true;
}
if (isWarningCoveredByError(info, overlappingIntervals, severityRegistrar)) {
return true;
}
if (info.getStartOffset() >= range.getStartOffset() && info.getEndOffset() <= range.getEndOffset() && psiFile != null) {
createOrReuseHighlighterFor(info, colorsScheme, document, group, psiFile, markup, infosToRemove, ranges2markersCache, severityRegistrar);
changed[0] = true;
}
return true;
});
for (RangeHighlighter highlighter : infosToRemove.forAllInGarbageBin()) {
highlighter.dispose();
changed[0] = true;
}
if (changed[0]) {
clearWhiteSpaceOptimizationFlag(document);
}
assertMarkupConsistent(markup, project);
}
Aggregations