use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.
the class RearrangeCodeProcessor method prepareTask.
@NotNull
@Override
protected FutureTask<Boolean> prepareTask(@NotNull final PsiFile file, final boolean processChangedTextOnly) {
return new FutureTask<>(() -> {
try {
Collection<TextRange> ranges = getRangesToFormat(file, processChangedTextOnly);
Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);
if (document != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null) {
PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(document);
PsiDocumentManager.getInstance(myProject).commitDocument(document);
Runnable command = prepareRearrangeCommand(file, ranges);
try {
CommandProcessor.getInstance().executeCommand(myProject, command, COMMAND_NAME, null);
} finally {
PsiDocumentManager.getInstance(myProject).commitDocument(document);
}
}
return true;
} catch (FilesTooBigForDiffException e) {
handleFileTooBigException(LOG, e, file);
return false;
}
});
}
use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.
the class TestDiscoverySearchHelper method search.
public static Set<String> search(final Project project, final Pair<String, String> position, final String changeList, final String frameworkPrefix) {
final Set<String> patterns = new LinkedHashSet<>();
if (position != null) {
try {
collectPatterns(project, patterns, position.first, position.second, frameworkPrefix);
} catch (IOException ignore) {
}
}
final List<VirtualFile> files = getAffectedFiles(changeList, project);
final PsiManager psiManager = PsiManager.getInstance(project);
final TestDiscoveryIndex discoveryIndex = TestDiscoveryIndex.getInstance(project);
for (final VirtualFile file : files) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile instanceof PsiClassOwner) {
if (position != null) {
final PsiClass[] classes = ((PsiClassOwner) psiFile).getClasses();
if (classes.length == 0 || TestFrameworks.detectFramework(classes[0]) == null)
return;
}
try {
final List<TextRange> changedTextRanges = FormatChangedTextUtil.getInstance().getChangedTextRanges(project, psiFile);
for (TextRange textRange : changedTextRanges) {
final PsiElement start = psiFile.findElementAt(textRange.getStartOffset());
final PsiElement end = psiFile.findElementAt(textRange.getEndOffset());
final PsiElement parent = PsiTreeUtil.findCommonParent(new PsiElement[] { start, end });
final Collection<PsiMethod> methods = new ArrayList<>(PsiTreeUtil.findChildrenOfType(parent, PsiMethod.class));
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(parent, PsiMethod.class);
if (containingMethod != null) {
methods.add(containingMethod);
}
for (PsiMethod changedMethod : methods) {
final LinkedHashSet<String> detectedPatterns = position == null ? collectPatterns(changedMethod, frameworkPrefix) : null;
if (detectedPatterns != null) {
patterns.addAll(detectedPatterns);
}
final PsiClass containingClass = changedMethod.getContainingClass();
if (containingClass != null && containingClass.getParent() == psiFile) {
final String classQualifiedName = containingClass.getQualifiedName();
final String changedMethodName = changedMethod.getName();
try {
if (classQualifiedName != null && (position == null && TestFrameworks.detectFramework(containingClass) != null || position != null && !discoveryIndex.hasTestTrace(frameworkPrefix + classQualifiedName + "-" + changedMethodName))) {
patterns.add(classQualifiedName + "," + changedMethodName);
}
} catch (IOException ignore) {
}
}
}
}
} catch (FilesTooBigForDiffException ignore) {
}
}
});
}
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
return new HashSet<>(ContainerUtil.filter(patterns, fqn -> ReadAction.compute(() -> psiFacade.findClass(StringUtil.getPackageName(fqn, ','), searchScope) != null)));
}
use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.
the class PersistentRangeHighlighterImpl method translatedViaDiff.
private boolean translatedViaDiff(DocumentEvent e, DocumentEventImpl event) {
try {
myLine = event.translateLineViaDiff(myLine);
} catch (FilesTooBigForDiffException ignored) {
return false;
}
if (myLine < 0 || myLine >= getDocument().getLineCount()) {
invalidate(e);
} else {
DocumentEx document = getDocument();
setIntervalStart(document.getLineStartOffset(myLine));
setIntervalEnd(document.getLineEndOffset(myLine));
}
return true;
}
use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.
the class MergeList method create.
@NotNull
public static MergeList create(@Nullable Project project, @NotNull Document left, @NotNull Document base, @NotNull Document right) {
MergeList mergeList;
String leftText = left.getText();
String baseText = base.getText();
String rightText = right.getText();
@NonNls final Object[] data = { "Left\n", leftText, "\nBase\n", baseText, "\nRight\n", rightText };
ContextLogger logger = new ContextLogger(LOG, new ContextLogger.SimpleContext(data));
List<MergeFragment> fragmentList;
try {
fragmentList = processText(leftText, baseText, rightText, logger);
mergeList = new MergeList(project, left, base, right, null);
} catch (FilesTooBigForDiffException e) {
fragmentList = Collections.emptyList();
mergeList = new MergeList(project, left, base, right, e.getMessage());
}
ArrayList<Change> leftChanges = new ArrayList<>();
ArrayList<Change> rightChanges = new ArrayList<>();
for (MergeFragment mergeFragment : fragmentList) {
TextRange baseRange = mergeFragment.getBase();
TextRange leftRange = mergeFragment.getLeft();
TextRange rightRange = mergeFragment.getRight();
if (compareSubstring(leftText, leftRange, rightText, rightRange)) {
MergeNoConflict conflict = new MergeNoConflict(baseRange, leftRange, rightRange, mergeList);
assert conflict.getLeftChange() != null;
assert conflict.getRightChange() != null;
leftChanges.add(conflict.getLeftChange());
rightChanges.add(conflict.getRightChange());
} else if (compareSubstring(baseText, baseRange, leftText, leftRange)) {
rightChanges.add(SimpleChange.fromRanges(baseRange, rightRange, mergeList.myBaseToRightChangeList));
} else if (compareSubstring(baseText, baseRange, rightText, rightRange)) {
leftChanges.add(SimpleChange.fromRanges(baseRange, leftRange, mergeList.myBaseToLeftChangeList));
} else {
MergeConflict conflict = new MergeConflict(baseRange, leftRange, rightRange, mergeList);
assert conflict.getLeftChange() != null;
assert conflict.getRightChange() != null;
leftChanges.add(conflict.getLeftChange());
rightChanges.add(conflict.getRightChange());
}
}
mergeList.myBaseToLeftChangeList.setChanges(leftChanges);
mergeList.myBaseToRightChangeList.setChanges(rightChanges);
return mergeList;
}
use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.
the class TextCompareProcessor method process.
public List<LineFragment> process(@Nullable String text1, @Nullable String text2) throws FilesTooBigForDiffException {
if (myHighlightMode == HighlightMode.NO_HIGHLIGHTING) {
return Collections.emptyList();
}
text1 = StringUtil.notNullize(text1);
text2 = StringUtil.notNullize(text2);
if (text1.isEmpty() || text2.isEmpty()) {
return new DummyDiffFragmentsProcessor().process(text1, text2);
}
DiffString diffText1 = DiffString.create(text1);
DiffString diffText2 = DiffString.create(text2);
DiffFragment[] woFormattingBlocks = myDiffPolicy.buildFragments(diffText1, diffText2);
DiffFragment[] step1lineFragments = new DiffCorrection.TrueLineBlocks(myComparisonPolicy).correctAndNormalize(woFormattingBlocks);
ArrayList<LineFragment> lineBlocks = new DiffFragmentsProcessor().process(step1lineFragments);
int badLinesCount = 0;
if (myHighlightMode == HighlightMode.BY_WORD) {
for (LineFragment lineBlock : lineBlocks) {
if (lineBlock.isOneSide() || lineBlock.isEqual())
continue;
try {
DiffString subText1 = lineBlock.getText(diffText1, FragmentSide.SIDE1);
DiffString subText2 = lineBlock.getText(diffText2, FragmentSide.SIDE2);
ArrayList<LineFragment> subFragments = findSubFragments(subText1, subText2);
lineBlock.setChildren(new ArrayList<Fragment>(subFragments));
lineBlock.adjustTypeFromChildrenTypes();
} catch (FilesTooBigForDiffException ignore) {
// If we can't by-word compare two lines - this is not a reason to break entire diff.
badLinesCount++;
if (badLinesCount > FilesTooBigForDiffException.MAX_BAD_LINES)
break;
}
}
}
return lineBlocks;
}
Aggregations