DiffManagerImpl should be persistent component, don't save defaults (COMPARISON_POLICY="Default")

This commit is contained in:
Vladimir Krivosheev
2015-02-23 12:29:27 +01:00
parent 392d15f11b
commit f9174b74f0
17 changed files with 238 additions and 201 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util.config;
import com.intellij.openapi.util.Comparing;
@@ -28,17 +27,28 @@ public abstract class AbstractProperty<T> {
}
};
@NonNls public abstract String getName();
@NonNls
public abstract String getName();
public abstract T getDefault(AbstractPropertyContainer container);
public abstract T copy(T value);
public boolean areEqual(T value1, T value2) {
return Comparing.equal(value1, value2);
}
public T get(AbstractPropertyContainer container) { return (T) container.getValueOf(this); }
public void set(AbstractPropertyContainer container, T value) { container.setValueOf(this, value); }
public final T cast(Object value) { return (T) value; }
public T get(AbstractPropertyContainer container) {
return (T)container.getValueOf(this);
}
public void set(AbstractPropertyContainer container, T value) {
container.setValueOf(this, value);
}
public final T cast(Object value) {
return (T)value;
}
public String toString() {
return getName();
@@ -60,7 +70,9 @@ public abstract class AbstractProperty<T> {
};
protected abstract Object getValueOf(PropertyImpl property);
protected abstract void setValueOf(PropertyImpl property, Object value);
public abstract boolean hasProperty(AbstractProperty property);
/**
@@ -73,7 +85,7 @@ public abstract class AbstractProperty<T> {
/**
* Only containers can delegate to another.
* Other clients should use {@link AbstractProperty#get AbstractProperty.get}
* Other clients should use {@link AbstractProperty#get AbstractProperty.get}
*/
protected final <T> T delegateGet(AbstractPropertyContainer container, AbstractProperty<T> property) {
return (T)container.getValueOf(property);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,20 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util.config;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Factory;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.util.SmartList;
import gnu.trove.THashMap;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPropertyContainer implements JDOMExternalizable {
public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPropertyContainer {
private static final Logger LOG = Logger.getInstance(ExternalizablePropertyContainer.class);
private final Map<AbstractProperty, Object> myValues = new HashMap<AbstractProperty, Object>();
private final Map<AbstractProperty, Externalizer> myExternalizers = new HashMap<AbstractProperty, Externalizer>();
private final Map<AbstractProperty, Object> myValues = new THashMap<AbstractProperty, Object>();
private final Map<AbstractProperty, Externalizer> myExternalizers = new THashMap<AbstractProperty, Externalizer>();
public <T> void registerProperty(AbstractProperty<T> property, Externalizer<T> externalizer) {
String name = property.getName();
@@ -66,37 +74,34 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
registerProperty(property, itemTagName, Externalizer.FactoryBased.create(factory));
}
private <T> Externalizer<List<T>> createListExternalizer(final Externalizer<T> itemExternalizer, final String itemTagName) {
private static <T> Externalizer<List<T>> createListExternalizer(final Externalizer<T> itemExternalizer, final String itemTagName) {
return new ListExternalizer(itemExternalizer, itemTagName);
}
@Override
public void readExternal(Element element) throws InvalidDataException {
HashMap<String, AbstractProperty> propertyByName = new HashMap<String, AbstractProperty>();
public void readExternal(@NotNull Element element) {
Map<String, AbstractProperty> propertyByName = new THashMap<String, AbstractProperty>();
for (AbstractProperty abstractProperty : myExternalizers.keySet()) {
propertyByName.put(abstractProperty.getName(), abstractProperty);
}
final List<Element> children = element.getChildren();
for (Element child : children) {
for (Element child : element.getChildren()) {
AbstractProperty property = propertyByName.get(child.getName());
if (property == null) {
continue;
}
final Externalizer externalizer = myExternalizers.get(property);
Externalizer externalizer = myExternalizers.get(property);
if (externalizer == null) {
continue;
}
try {
myValues.put(property, externalizer.readValue(child));
}
catch (InvalidDataException e) {
catch (Exception e) {
LOG.info(e);
}
}
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
public void writeExternal(@NotNull Element element) {
if (myExternalizers.isEmpty()) {
return;
}
@@ -147,12 +152,12 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
}
@Override
public List<T> readValue(Element dataElement) throws InvalidDataException {
ArrayList<T> list = new ArrayList<T>();
List<Element> children = dataElement.getChildren();
for (Iterator<Element> iterator = children.iterator(); iterator.hasNext();) {
Element element = iterator.next();
if (NULL_ELEMENT.equals(element.getName())) list.add(null);
public List<T> readValue(Element dataElement) {
List<T> list = new SmartList<T>();
for (Element element : dataElement.getChildren()) {
if (NULL_ELEMENT.equals(element.getName())) {
list.add(null);
}
else if (myItemTagName.equals(element.getName())) {
T item = myItemExternalizer.readValue(element);
if (item == null) {
@@ -166,17 +171,17 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr
}
@Override
public void writeValue(Element dataElement, List<T> value) throws WriteExternalException {
for (Iterator<T> iterator = value.iterator(); iterator.hasNext();) {
T item = iterator.next();
if (item != null) {
public void writeValue(Element dataElement, List<T> value) {
for (T item : value) {
if (item == null) {
dataElement.addContent(new Element(NULL_ELEMENT));
}
else {
Element element = new Element(myItemTagName);
myItemExternalizer.writeValue(element, item);
dataElement.addContent(element);
}
else dataElement.addContent(new Element(NULL_ELEMENT));
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import java.util.Iterator;
import java.util.List;
public interface Externalizer<T> {
@NonNls String VALUE_ATTRIBUTE = "value";
@@ -60,9 +59,9 @@ public interface Externalizer<T> {
}
};
T readValue(Element dataElement) throws InvalidDataException;
T readValue(Element dataElement);
void writeValue(Element dataElement, T value) throws WriteExternalException;
void writeValue(Element dataElement, T value);
class FactoryBased<T extends JDOMExternalizable> implements Externalizer<T> {
private final Factory<T> myFactory;
@@ -72,15 +71,25 @@ public interface Externalizer<T> {
}
@Override
public T readValue(Element dataElement) throws InvalidDataException {
public T readValue(Element dataElement) {
T data = myFactory.create();
data.readExternal(dataElement);
try {
data.readExternal(dataElement);
}
catch (InvalidDataException e) {
throw new RuntimeException(e);
}
return data;
}
@Override
public void writeValue(Element dataElement, T value) throws WriteExternalException {
value.writeExternal(dataElement);
public void writeValue(Element dataElement, T value) {
try {
value.writeExternal(dataElement);
}
catch (WriteExternalException e) {
throw new RuntimeException(e);
}
}
public static <T extends JDOMExternalizable> FactoryBased<T> create(Factory<T> factory) {
@@ -94,25 +103,25 @@ public interface Externalizer<T> {
@NonNls private static final String VALUE_ATTR = "value";
@Override
public Storage readValue(Element dataElement) throws InvalidDataException {
public Storage readValue(Element dataElement) {
Storage.MapStorage storage = new Storage.MapStorage();
List<Element> children = dataElement.getChildren(ITEM_TAG);
for (Iterator<Element> iterator = children.iterator(); iterator.hasNext();) {
Element element = iterator.next();
for (Element element : dataElement.getChildren(ITEM_TAG)) {
storage.put(element.getAttributeValue(KEY_ATTR), element.getAttributeValue(VALUE_ATTR));
}
return storage;
}
@Override
public void writeValue(Element dataElement, Storage storage) throws WriteExternalException {
public void writeValue(Element dataElement, Storage storage) {
Iterator<String> keys = ((Storage.MapStorage)storage).getKeys();
while (keys.hasNext()) {
String key = keys.next();
String value = storage.get(key);
Element element = new Element(ITEM_TAG);
element.setAttribute(KEY_ATTR, key);
if (value != null) element.setAttribute(VALUE_ATTR, value);
if (value != null) {
element.setAttribute(VALUE_ATTR, value);
}
dataElement.addContent(element);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ public interface DiffPanelEx extends DiffPanel, Disposable {
DiffPanelOptions getOptions();
void setComparisonPolicy(ComparisonPolicy comparisonPolicy);
void setComparisonPolicy(@NotNull ComparisonPolicy comparisonPolicy);
ComparisonPolicy getComparisonPolicy();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -180,17 +180,16 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid
myDataProvider = new MyGenericDataProvider(this);
myPanel.setDataProvider(myDataProvider);
final ComparisonPolicy comparisonPolicy = getComparisonPolicy();
final ComparisonPolicy defaultComparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy();
final HighlightMode highlightMode = getHighlightMode();
final HighlightMode defaultHighlightMode = DiffManagerImpl.getInstanceEx().getHighlightMode();
ComparisonPolicy comparisonPolicy = getComparisonPolicy();
if (comparisonPolicy != DiffManagerImpl.getInstanceEx().getComparisonPolicy()) {
setComparisonPolicy(comparisonPolicy);
}
if (defaultComparisonPolicy != null && comparisonPolicy != defaultComparisonPolicy) {
setComparisonPolicy(defaultComparisonPolicy);
}
if (defaultHighlightMode != null && highlightMode != defaultHighlightMode) {
setHighlightMode(defaultHighlightMode);
HighlightMode highlightMode = getHighlightMode();
if (highlightMode != DiffManagerImpl.getInstanceEx().getHighlightMode()) {
setHighlightMode(highlightMode);
}
myVisibleAreaListener = new VisibleAreaListener() {
@Override
public void visibleAreaChanged(VisibleAreaEvent e) {
@@ -504,11 +503,11 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid
return myData.getComparisonPolicy();
}
public void setComparisonPolicy(ComparisonPolicy comparisonPolicy) {
public void setComparisonPolicy(@NotNull ComparisonPolicy comparisonPolicy) {
setComparisonPolicy(comparisonPolicy, true);
}
private void setComparisonPolicy(ComparisonPolicy policy, boolean notifyManager) {
private void setComparisonPolicy(@NotNull ComparisonPolicy policy, boolean notifyManager) {
myData.setComparisonPolicy(policy);
rediff();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,10 @@ package com.intellij.openapi.diff.impl.external;
import com.intellij.ide.highlighter.ArchiveFileType;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.*;
import com.intellij.openapi.diff.DiffContent;
import com.intellij.openapi.diff.DiffRequest;
import com.intellij.openapi.diff.DiffTool;
import com.intellij.openapi.diff.DiffViewer;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.UIBasedFileType;
import org.jetbrains.annotations.NotNull;
@@ -26,16 +29,21 @@ import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class CompositeDiffTool implements DiffTool {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.external.CompositeDiffTool");
private final List<DiffTool> myTools;
public CompositeDiffTool(List<DiffTool> tools) {
public CompositeDiffTool(@NotNull List<DiffTool> tools) {
myTools = new ArrayList<DiffTool>(tools);
}
public CompositeDiffTool(@NotNull DiffTool[] tools) {
myTools = Arrays.asList(tools);
}
public void show(DiffRequest data) {
checkDiffData(data);
DiffTool tool = chooseTool(data);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,10 @@
package com.intellij.openapi.diff.impl.external;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.DiffManager;
import com.intellij.openapi.diff.DiffPanel;
@@ -29,8 +33,11 @@ import com.intellij.openapi.diff.impl.processing.HighlightMode;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.MarkupEditorFilter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.util.SmartList;
import com.intellij.util.config.*;
import com.intellij.util.containers.ContainerUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -39,8 +46,16 @@ import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
@State(
name = "DiffManager",
storages = {
@Storage(file = StoragePathMacros.APP_CONFIG + "/diff.xml"),
@Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml", deprecated = true)
}
)
public class DiffManagerImpl extends DiffManager implements PersistentStateComponent<Element> {
public static final int FULL_DIFF_DIVIDER_POLYGONS_OFFSET = 3;
private static final Logger LOG = Logger.getInstance(DiffManagerImpl.class);
@@ -50,7 +65,10 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
@Override
public String readValue(Element dataElement) {
String path = dataElement.getAttributeValue(NEW_VALUE);
if (path != null) return path;
if (path != null) {
return path;
}
String prevValue = dataElement.getAttributeValue(VALUE_ATTRIBUTE);
return prevValue != null ? prevValue.trim() : null;
}
@@ -70,9 +88,8 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
public static final BooleanProperty ENABLE_FILES = new BooleanProperty("enableFiles", false);
public static final BooleanProperty ENABLE_MERGE = new BooleanProperty("enableMerge", false);
private final ExternalizablePropertyContainer myProperties;
private final ArrayList<DiffTool> myAdditionTools = new ArrayList<DiffTool>();
private final List<DiffTool> myAdditionTools = new SmartList<DiffTool>();
public static final DiffTool INTERNAL_DIFF = new FrameDiffTool();
public static final Key<Boolean> EDITOR_IS_DIFF_KEY = new Key<Boolean>("EDITOR_IS_DIFF_KEY");
@@ -82,8 +99,9 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
return DiffUtil.isDiffEditor(editor);
}
};
private ComparisonPolicy myComparisonPolicy;
private HighlightMode myHighlightMode;
private ComparisonPolicy myComparisonPolicy = ComparisonPolicy.DEFAULT;
private HighlightMode myHighlightMode = HighlightMode.BY_WORD;
@NonNls public static final String COMPARISON_POLICY_ATTR_NAME = "COMPARISON_POLICY";
@NonNls public static final String HIGHLIGHT_MODE_ATTR_NAME = "HIGHLIGHT_MODE";
@@ -100,13 +118,15 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
}
@Override
public DiffTool getIdeaDiffTool() { return INTERNAL_DIFF; }
public DiffTool getIdeaDiffTool() {
return INTERNAL_DIFF;
}
@Override
public DiffTool getDiffTool() {
DiffTool[] standardTools;
// there is inner check in multiple tool for external viewers as well
if (! ENABLE_FILES.value(myProperties) || ! ENABLE_FOLDERS.value(myProperties) || !ENABLE_MERGE.value(myProperties)) {
if (!ENABLE_FILES.value(myProperties) || !ENABLE_FOLDERS.value(myProperties) || !ENABLE_MERGE.value(myProperties)) {
DiffTool[] embeddableTools = {
INTERNAL_DIFF,
new MergeTool(),
@@ -121,7 +141,8 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
new MergeTool(),
BinaryDiffTool.INSTANCE
};
} else {
}
else {
standardTools = new DiffTool[]{
ExtCompareFolders.INSTANCE,
ExtCompareFiles.INSTANCE,
@@ -131,14 +152,22 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
BinaryDiffTool.INSTANCE
};
}
ArrayList<DiffTool> allTools = new ArrayList<DiffTool>(myAdditionTools);
allTools.addAll(Arrays.asList(standardTools));
return new CompositeDiffTool(allTools);
if (myAdditionTools.isEmpty()) {
return new CompositeDiffTool(standardTools);
}
else {
List<DiffTool> allTools = new ArrayList<DiffTool>(myAdditionTools);
ContainerUtil.addAll(allTools, standardTools);
return new CompositeDiffTool(allTools);
}
}
@Override
public boolean registerDiffTool(@NotNull DiffTool tool) throws NullPointerException {
if (myAdditionTools.contains(tool)) return false;
if (myAdditionTools.contains(tool)) {
return false;
}
myAdditionTools.add(tool);
return true;
}
@@ -149,7 +178,7 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
LOG.assertTrue(!myAdditionTools.contains(tool));
}
public ArrayList<DiffTool> getAdditionTools() {
public List<DiffTool> getAdditionTools() {
return myAdditionTools;
}
@@ -174,28 +203,35 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
return (DiffManagerImpl)DiffManager.getInstance();
}
@Nullable
@Override
public void readExternal(@NotNull Element element) throws InvalidDataException {
myProperties.readExternal(element);
readPolicy(element);
readMode(element);
public Element getState() {
Element state = new Element("state");
myProperties.writeExternal(state);
if (myComparisonPolicy != ComparisonPolicy.DEFAULT) {
state.setAttribute(COMPARISON_POLICY_ATTR_NAME, myComparisonPolicy.getName());
}
if (myHighlightMode != HighlightMode.BY_WORD) {
state.setAttribute(HIGHLIGHT_MODE_ATTR_NAME, myHighlightMode.name());
}
return state;
}
private void readPolicy(@NotNull final Element element) {
final String policyName = element.getAttributeValue(COMPARISON_POLICY_ATTR_NAME);
@Override
public void loadState(Element state) {
myProperties.readExternal(state);
String policyName = state.getAttributeValue(COMPARISON_POLICY_ATTR_NAME);
if (policyName != null) {
ComparisonPolicy[] policies = ComparisonPolicy.getAllInstances();
for (ComparisonPolicy policy : policies) {
for (ComparisonPolicy policy : ComparisonPolicy.getAllInstances()) {
if (policy.getName().equals(policyName)) {
myComparisonPolicy = policy;
break;
}
}
}
}
private void readMode(@NotNull final Element element) {
final String modeName = element.getAttributeValue(HIGHLIGHT_MODE_ATTR_NAME);
String modeName = state.getAttributeValue(HIGHLIGHT_MODE_ATTR_NAME);
if (modeName != null) {
try {
myHighlightMode = HighlightMode.valueOf(modeName);
@@ -205,19 +241,10 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
}
}
@Override
public void writeExternal(@NotNull Element element) throws WriteExternalException {
myProperties.writeExternal(element);
if (myComparisonPolicy != null) {
element.setAttribute(COMPARISON_POLICY_ATTR_NAME, myComparisonPolicy.getName());
}
if (myHighlightMode != null) {
element.setAttribute(HIGHLIGHT_MODE_ATTR_NAME, myHighlightMode.name());
}
public AbstractProperty.AbstractPropertyContainer getProperties() {
return myProperties;
}
public AbstractProperty.AbstractPropertyContainer getProperties() { return myProperties; }
static DiffPanel createDiffPanel(DiffRequest data, Window window, @NotNull Disposable parentDisposable, FrameDiffTool tool) {
DiffPanel diffPanel = null;
try {
@@ -236,21 +263,21 @@ public class DiffManagerImpl extends DiffManager implements JDOMExternalizable {
}
}
public void setComparisonPolicy(final ComparisonPolicy p) {
myComparisonPolicy = p;
}
@Nullable
@NotNull
public ComparisonPolicy getComparisonPolicy() {
return myComparisonPolicy;
}
public void setHighlightMode(HighlightMode highlightMode) {
myHighlightMode = highlightMode;
public void setComparisonPolicy(@NotNull ComparisonPolicy value) {
myComparisonPolicy = value;
}
@Nullable
@NotNull
public HighlightMode getHighlightMode() {
return myHighlightMode;
}
public void setHighlightMode(@NotNull HighlightMode highlightMode) {
myHighlightMode = highlightMode;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.FrameWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ex.MessagesEx;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
@@ -40,8 +39,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
// Author: dyoma
public class FrameDiffTool implements DiffTool {
public void show(DiffRequest request) {
Collection hints = request.getHints();
@@ -161,27 +158,27 @@ public class FrameDiffTool implements DiffTool {
// TODO remove check?
private boolean checkNoDifferenceAndNotify(DiffPanel diffPanel, DiffRequest data, final Window window, final boolean showMessage) {
if (!diffPanel.hasDifferences() && !data.getHints().contains(HINT_ALLOW_NO_DIFFERENCES)) {
DiffManagerImpl manager = (DiffManagerImpl) DiffManager.getInstance();
if (!Comparing.equal(manager.getComparisonPolicy(), ComparisonPolicy.DEFAULT)) {
ComparisonPolicy oldPolicy = manager.getComparisonPolicy();
manager.setComparisonPolicy(ComparisonPolicy.DEFAULT);
Disposable parentDisposable = Disposer.newDisposable();
DiffPanel maybeDiffPanel = DiffManagerImpl.createDiffPanel(data, window, parentDisposable, this);
manager.setComparisonPolicy(oldPolicy);
boolean hasDiffs = maybeDiffPanel.hasDifferences();
Disposer.dispose(parentDisposable);
if (hasDiffs) return false;
}
if (! showMessage) {
return true;
}
return !askForceOpenDiff(data);
if (diffPanel.hasDifferences() || data.getHints().contains(HINT_ALLOW_NO_DIFFERENCES)) {
return false;
}
return false;
DiffManagerImpl manager = (DiffManagerImpl)DiffManager.getInstance();
ComparisonPolicy oldPolicy = manager.getComparisonPolicy();
if (oldPolicy != ComparisonPolicy.DEFAULT) {
manager.setComparisonPolicy(ComparisonPolicy.DEFAULT);
Disposable parentDisposable = Disposer.newDisposable();
DiffPanel maybeDiffPanel = DiffManagerImpl.createDiffPanel(data, window, parentDisposable, this);
manager.setComparisonPolicy(oldPolicy);
boolean hasDiffs = maybeDiffPanel.hasDifferences();
Disposer.dispose(parentDisposable);
if (hasDiffs) {
return false;
}
}
return !showMessage || !askForceOpenDiff(data);
}
private static boolean askForceOpenDiff(DiffRequest data) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,10 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diff.impl.ComparisonPolicy;
import com.intellij.openapi.diff.impl.ContentChangeListener;
import com.intellij.openapi.diff.impl.fragments.*;
import com.intellij.openapi.diff.impl.fragments.FragmentHighlighterImpl;
import com.intellij.openapi.diff.impl.fragments.FragmentList;
import com.intellij.openapi.diff.impl.fragments.FragmentListImpl;
import com.intellij.openapi.diff.impl.fragments.LineFragment;
import com.intellij.openapi.diff.impl.processing.DiffPolicy;
import com.intellij.openapi.diff.impl.processing.HighlightMode;
import com.intellij.openapi.diff.impl.processing.TextCompareProcessor;
@@ -58,7 +61,7 @@ public abstract class SimpleDiffPanelState implements Disposable {
return editorWrapper;
}
public void setComparisonPolicy(ComparisonPolicy comparisonPolicy) {
public void setComparisonPolicy(@NotNull ComparisonPolicy comparisonPolicy) {
myComparisonPolicy = comparisonPolicy;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,16 @@
package com.intellij.openapi.diff.impl;
import com.intellij.CommonBundle;
import com.intellij.openapi.diff.impl.string.DiffString;
import com.intellij.openapi.diff.ex.DiffFragment;
import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
import com.intellij.openapi.diff.impl.highlighting.Util;
import com.intellij.openapi.diff.impl.processing.DiffCorrection;
import com.intellij.openapi.diff.impl.processing.Formatting;
import com.intellij.openapi.diff.impl.processing.Word;
import com.intellij.openapi.diff.impl.string.DiffString;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.diff.Diff;
import com.intellij.util.diff.FilesTooBigForDiffException;
import org.jetbrains.annotations.NotNull;
@@ -241,8 +242,7 @@ public abstract class ComparisonPolicy {
if (fragment.isOneSide()) {
FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString text = side.getText(fragment);
DiffString trimed = text.trim();
if (trimed.isEmpty()) {
if (StringUtil.isEmptyOrSpaces(text)) {
collector.add(side.createFragment(text, DiffString.EMPTY, false));
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package com.intellij.openapi.vcs.changes;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.impl.ComparisonPolicy;
import com.intellij.openapi.diff.impl.external.DiffManagerImpl;
import com.intellij.openapi.diff.impl.fragments.LineFragment;
import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
@@ -87,11 +86,10 @@ public class FragmentedDiffRequestFromChange {
filePath.hardRefresh();
file = filePath.getVirtualFile();
}
final PreparedFragmentedContent preparedFragmentedContent = new PreparedFragmentedContent(myProject, fragmentedContent,
return new PreparedFragmentedContent(myProject, fragmentedContent,
filePath.getName(), filePath.getFileType(),
change.getBeforeRevision() == null ? null : change.getBeforeRevision().getRevisionNumber(),
change.getAfterRevision() == null ? null : change.getAfterRevision().getRevisionNumber(), filePath, file);
return preparedFragmentedContent;
}
private static class RangesCalculator {
@@ -138,12 +136,8 @@ public class FragmentedDiffRequestFromChange {
}
}
ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy();
if (comparisonPolicy == null) {
comparisonPolicy = ComparisonPolicy.DEFAULT;
}
final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
final List<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
TextCompareProcessor processor = new TextCompareProcessor(DiffManagerImpl.getInstanceEx().getComparisonPolicy());
List<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size());
for (LineFragment lineFragment : lineFragments) {
if (!lineFragment.isEqual()) {
@@ -174,7 +168,7 @@ public class FragmentedDiffRequestFromChange {
}
}
private int correctRangeEnd(final int end, final Document document) {
private static int correctRangeEnd(final int end, final Document document) {
if (end == 0) return end;
return "\n".equals(document.getText(new TextRange(end - 1, end))) ? end - 1 : end;
}
@@ -187,7 +181,7 @@ public class FragmentedDiffRequestFromChange {
return myException;
}
private Document documentFromRevision(final ContentRevision cr) throws VcsException {
private static Document documentFromRevision(final ContentRevision cr) throws VcsException {
final Document oldDocument = new DocumentImpl(StringUtil.convertLineSeparators(notNullContentRevision(cr)),true);
// todo !!! a question how to show line separators in diff etc
// todo currently document doesn't allow to put \r as separator
@@ -195,7 +189,7 @@ public class FragmentedDiffRequestFromChange {
return oldDocument;
}
private String notNullContentRevision(final ContentRevision cr) throws VcsException {
private static String notNullContentRevision(final ContentRevision cr) throws VcsException {
if (cr == null) return "";
String content = cr.getContent();
return content == null ? "" : content;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.roots.ui.CellAppearanceEx;
import com.intellij.openapi.roots.ui.FileAppearanceService;
import com.intellij.openapi.roots.ui.ModifiableCellAppearanceEx;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
@@ -55,7 +54,7 @@ public class AllJarsUnderDirEntry implements AntClasspathEntry {
this(new File(osPath));
}
public void writeExternal(final Element dataElement) throws WriteExternalException {
public void writeExternal(final Element dataElement) {
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, myDir.getAbsolutePath().replace(File.separatorChar, '/'));
dataElement.setAttribute(DIR, url);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,9 +18,7 @@ package com.intellij.lang.ant.config.impl;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.roots.ui.CellAppearanceEx;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.NullableFactory;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Function;
import com.intellij.util.PathUtil;
@@ -35,23 +33,25 @@ import java.util.List;
public interface AntClasspathEntry {
Externalizer<AntClasspathEntry> EXTERNALIZER = new Externalizer<AntClasspathEntry>() {
@Override
public AntClasspathEntry readValue(Element dataElement) throws InvalidDataException {
public AntClasspathEntry readValue(Element dataElement) {
String pathUrl = dataElement.getAttributeValue(SinglePathEntry.PATH);
if (pathUrl != null)
if (pathUrl != null) {
return new SinglePathEntry(PathUtil.toPresentableUrl(pathUrl));
}
String dirUrl = dataElement.getAttributeValue(AllJarsUnderDirEntry.DIR);
if (dirUrl != null)
if (dirUrl != null) {
return new AllJarsUnderDirEntry(PathUtil.toPresentableUrl(dirUrl));
throw new InvalidDataException();
}
throw new IllegalStateException();
}
@Override
public void writeValue(Element dataElement, AntClasspathEntry entry) throws WriteExternalException {
public void writeValue(Element dataElement, AntClasspathEntry entry) {
entry.writeExternal(dataElement);
}
};
void writeExternal(Element dataElement) throws WriteExternalException;
void writeExternal(Element dataElement);
void addFilesTo(List<File> files);
@@ -60,7 +60,7 @@ public interface AntClasspathEntry {
abstract class AddEntriesFactory implements NullableFactory<List<AntClasspathEntry>> {
private final JComponent myParentComponent;
private final FileChooserDescriptor myDescriptor;
private final Function<VirtualFile,AntClasspathEntry> myMapper;
private final Function<VirtualFile, AntClasspathEntry> myMapper;
public AddEntriesFactory(final JComponent parentComponent,
final FileChooserDescriptor descriptor,
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@ package com.intellij.lang.ant.config.impl;
import com.intellij.lang.ant.AntBundle;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.JarUtil;
import com.intellij.util.config.*;
import com.intellij.util.containers.Convertor;
@@ -62,18 +60,18 @@ public class AntInstallation {
}
public static final Externalizer<AntInstallation> EXTERNALIZER = new Externalizer<AntInstallation>() {
public AntInstallation readValue(Element dataElement) throws InvalidDataException {
public AntInstallation readValue(Element dataElement) {
AntInstallation antInstallation = new AntInstallation();
antInstallation.readExternal(dataElement);
return antInstallation;
}
public void writeValue(Element dataElement, AntInstallation antInstallation) throws WriteExternalException {
public void writeValue(Element dataElement, AntInstallation antInstallation) {
antInstallation.myProperties.writeExternal(dataElement);
}
};
private void readExternal(Element dataElement) throws InvalidDataException {
private void readExternal(Element dataElement) {
myProperties.readExternal(dataElement);
File antJar = new File(HOME_DIR.get(myProperties), PATH_TO_ANT_JAR);
updateVersion(antJar);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ import com.intellij.execution.CantRunException;
import com.intellij.lang.ant.AntBundle;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.util.config.AbstractProperty;
import com.intellij.util.config.Externalizer;
import org.jdom.Element;
@@ -35,11 +34,13 @@ public abstract class AntReference {
@NonNls private static final String BUNDLED_ANT_ATTR = "bundledAnt";
public static final Externalizer<AntReference> EXTERNALIZER = new Externalizer<AntReference>() {
public AntReference readValue(Element dataElement) throws InvalidDataException {
public AntReference readValue(Element dataElement) {
if (Boolean.valueOf(dataElement.getAttributeValue(PROJECT_DEFAULT_ATTR)).booleanValue()) return PROJECT_DEFAULT;
if (Boolean.valueOf(dataElement.getAttributeValue(BUNDLED_ANT_ATTR)).booleanValue()) return BUNDLED_ANT;
String name = dataElement.getAttributeValue(NAME_ATTR);
if (name == null) throw new InvalidDataException();
if (name == null) {
throw new IllegalStateException("no name");
}
return new MissingAntReference(name);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,8 +31,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.config.*;
@@ -102,24 +100,13 @@ public class GlobalAntConfiguration implements PersistentStateComponent<Element>
@Override
public Element getState() {
Element element = new Element("state");
try {
myProperties.writeExternal(element);
}
catch (WriteExternalException e) {
LOG.error(e);
return null;
}
myProperties.writeExternal(element);
return element;
}
@Override
public void loadState(Element state) {
try {
myProperties.readExternal(state);
}
catch (InvalidDataException e) {
LOG.error(e);
}
myProperties.readExternal(state);
}
public static GlobalAntConfiguration getInstance() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@ package com.intellij.lang.ant.config.impl;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.roots.ui.CellAppearanceEx;
import com.intellij.openapi.roots.ui.FileAppearanceService;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
@@ -51,12 +49,12 @@ public class SinglePathEntry implements AntClasspathEntry {
this(new File(osPath));
}
public void readExternal(final Element element) throws InvalidDataException {
public void readExternal(final Element element) {
String value = element.getAttributeValue(PATH);
myFile = new File(PathUtil.toPresentableUrl(value));
}
public void writeExternal(final Element element) throws WriteExternalException {
public void writeExternal(final Element element) {
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, myFile.getAbsolutePath().replace(File.separatorChar, '/'));
element.setAttribute(PATH, url);
}