Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2010-02-26 19:57:40 +0000
committerJeff Johnston2010-02-26 19:57:40 +0000
commit0b62bc1edb273395be565efafab3b504fe38529a (patch)
tree00cb6e293a9534470519e422629ce993b0d5cea7 /changelog/org.eclipse.linuxtools.changelog.core/src
parentd925a61196c240d531093f168bcc38c1ba204981 (diff)
downloadorg.eclipse.linuxtools-0b62bc1edb273395be565efafab3b504fe38529a.tar.gz
org.eclipse.linuxtools-0b62bc1edb273395be565efafab3b504fe38529a.tar.xz
org.eclipse.linuxtools-0b62bc1edb273395be565efafab3b504fe38529a.zip
2010-02-26 Jeff Johnston <jjohnstn@redhat.com>
Resolves #299974 * src/org/eclipse/linuxtools/changelog/core/actions/SourceEditorInput.java: New file. * src/org/eclipse/linuxtools/changelog/core/actions/StorageEditorInput.java: New file. * src/org/eclipse/linuxtools/changelog/core/actions/PatchFile.java (addLineRange): New parameter that reveals whether patch is to local file or ancestor. (getStorage): New method. (setStorage): Ditto. * src/org/eclipse/linuxtools/changelog/core/actions/PatchRangeElement.java (equals): Modified to compare local change field instead of patch field which is never used and has been removed. (PatchRangeElement): Add new boolean which is set to true if patch is to local file. Remove setting of patch text which is never used. (isLocalChange): New method. * src/org/eclipse/linuxtools/changelog/core/actions/PrepareChangeLogAction.java (guessFunctionNames): Add support for finding function names for changes to ancestor file which will be backed only by storage and not a local file. (MyStorageDocumentProvider): New private class. (getChangedLines): Add changes to ancestor file and save the storage we get back to later guess function names.
Diffstat (limited to 'changelog/org.eclipse.linuxtools.changelog.core/src')
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchFile.java21
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchRangeElement.java12
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PrepareChangeLogAction.java80
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/SourceEditorInput.java34
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/StorageEditorInput.java113
5 files changed, 219 insertions, 41 deletions
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchFile.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchFile.java
index 74794325c1..8fff90a685 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchFile.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchFile.java
@@ -15,6 +15,7 @@ package org.eclipse.linuxtools.changelog.core.actions;
import java.util.ArrayList;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -26,6 +27,7 @@ import org.eclipse.core.runtime.Path;
public class PatchFile {
private IPath fpath;
+ private IStorage storage;
private ArrayList<PatchRangeElement> pranges = new ArrayList<PatchRangeElement>();
private boolean newfile = false;
@@ -56,10 +58,10 @@ public class PatchFile {
public PatchFile(IPath filePath) {
fpath = filePath;
}
+
+ public void addLineRange(int from, int to, boolean localChange) {
- public void addLineRange(int from, int to) {
-
- pranges.add(new PatchRangeElement(from, to, ""));
+ pranges.add(new PatchRangeElement(from, to, localChange));
}
public PatchRangeElement[] getRanges() {
@@ -73,15 +75,18 @@ public class PatchFile {
}
- public void appendTxtToLastRange(String txt) {
-
- (pranges.get(pranges.size()-1)).appendTxt(txt);
- }
-
public IPath getPath() {
return fpath;
}
+ public IStorage getStorage() {
+ return storage;
+ }
+
+ public void setStorage(IStorage storage) {
+ this.storage = storage;
+ }
+
public void setResource(IResource resource) {
this.resource = resource;
}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchRangeElement.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchRangeElement.java
index 491cc7dd8b..04d211e565 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchRangeElement.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PatchRangeElement.java
@@ -20,23 +20,23 @@ public class PatchRangeElement {
public int ffromLine;
public int ftoLine;
- public String fpatch;
+ public boolean flocalChange;
- public PatchRangeElement(int from, int to, String txt) {
+ public PatchRangeElement(int from, int to, boolean localChange) {
ffromLine =from;
ftoLine= to;
- fpatch = txt;
+ flocalChange = localChange;
}
- public void appendTxt(String txt) {
- fpatch += txt + "\n";
+ public boolean isLocalChange() {
+ return flocalChange;
}
@Override
public boolean equals(Object o) {
if (o instanceof PatchRangeElement) {
PatchRangeElement b = (PatchRangeElement)o;
- return b.ffromLine == ffromLine && b.ftoLine == ftoLine && b.fpatch.equals(fpatch);
+ return b.ffromLine == ffromLine && b.ftoLine == ftoLine && b.flocalChange == flocalChange;
}
else
return this == o;
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PrepareChangeLogAction.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PrepareChangeLogAction.java
index 7fb30dcc50..22bb635c91 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PrepareChangeLogAction.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/PrepareChangeLogAction.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.changelog.core.actions;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Vector;
@@ -58,9 +59,11 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.editors.text.FileDocumentProvider;
+import org.eclipse.ui.editors.text.StorageDocumentProvider;
import org.eclipse.ui.part.FileEditorInput;
+
/**
* Action handler for prepare changelog.
*
@@ -84,6 +87,14 @@ public class PrepareChangeLogAction extends ChangeLogAction {
}
}
+ private class MyStorageDocumentProvider extends StorageDocumentProvider {
+
+ @Override
+ public IDocument createDocument(Object element) throws CoreException {
+ return super.createDocument(element);
+ }
+ }
+
public PrepareChangeLogAction(String name) {
super(name);
}
@@ -214,8 +225,10 @@ public class PrepareChangeLogAction extends ChangeLogAction {
String osEncoding = file.getCharset();
IFileRevision ancestorState = localDiff.getBeforeState();
IStorage ancestorStorage;
- if (ancestorState != null)
+ if (ancestorState != null) {
ancestorStorage = ancestorState.getStorage(monitor);
+ p.setStorage(ancestorStorage);
+ }
else
ancestorStorage = null;
@@ -227,8 +240,15 @@ public class PrepareChangeLogAction extends ChangeLogAction {
LineComparator right = new LineComparator(file.getContents(), osEncoding);
for (RangeDifference tmp: RangeDifferencer.findDifferences(left, right)) {
if (tmp.kind() == RangeDifference.CHANGE) {
+ // Right side of diff are all changes found in local file.
int rightLength = tmp.rightLength() > 0 ? tmp.rightLength() : tmp.rightLength() + 1;
- p.addLineRange(tmp.rightStart() + 1, tmp.rightStart() + rightLength);
+ // We also want to store left side of the diff which are changes to the ancestor as it may contain
+ // functions/methods that have been removed.
+ int leftLength = tmp.leftLength() > 0 ? tmp.leftLength() : tmp.leftLength() + 1;
+ // Only store left side changes if the storage exists and we add one to the start line number
+ if (p.getStorage() != null)
+ p.addLineRange(tmp.leftStart(), tmp.leftStart() + leftLength, false);
+ p.addLineRange(tmp.rightStart(), tmp.rightStart() + rightLength, true);
}
}
} catch (UnsupportedEncodingException e) {
@@ -492,44 +512,50 @@ public class PrepareChangeLogAction extends ChangeLogAction {
.getFileForLocation(
getWorkspaceRoot().getLocation().append(
patchFileInfo.getPath())));
+
+ SourceEditorInput sei = new SourceEditorInput(patchFileInfo.getStorage());
MyDocumentProvider mdp = new MyDocumentProvider();
+ MyStorageDocumentProvider msdp = new MyStorageDocumentProvider();
try {
- // get document for target file
+ // get document for target file (one for local file, one for repository storage)
IDocument doc = mdp.createDocument(fei);
+ IDocument olddoc = msdp.createDocument(sei);
HashMap<String, String> functionNamesMap = new HashMap<String, String>();
+ ArrayList<String> nameList = new ArrayList<String>();
// for all the ranges
for (PatchRangeElement tpre: patchFileInfo.getRanges()) {
- // for all the lines in a range
- for (int j = tpre.ffromLine; j <= tpre.ftoLine; j++) {
-
- if ((j <= 0) || (j >= doc.getNumberOfLines()))
- continue; // ignore out of bound lines
-
- // add func that determines type of file.
- // right now it assumes it's java file.
- String functionGuess = parseCurrentFunctionAtOffset(
- editorName, fei, doc.getLineOffset(j));
-
- // putting it in hashmap will eliminate duplicate
- // guesses.
- functionNamesMap.put(functionGuess, functionGuess);
-
- }
- }
-
- // dump all unique func. guesses
- fnames = new String[functionNamesMap.size()];
-
- int i = 0;
- for (String fnm: functionNamesMap.values()){
- fnames[i++] = fnm;
+ for (int j = tpre.ffromLine; j <= tpre.ftoLine; j++) {
+
+ if ((j < 0) || (j > doc.getNumberOfLines() - 1))
+ continue; // ignore out of bound lines
+
+ String functionGuess = "";
+ // add func that determines type of file.
+ // right now it assumes it's java file.
+ if (tpre.isLocalChange())
+ functionGuess = parseCurrentFunctionAtOffset(
+ editorName, fei, doc.getLineOffset(j));
+ else
+ functionGuess = parseCurrentFunctionAtOffset(
+ editorName, sei, olddoc.getLineOffset(j));
+
+ // putting it in hashmap will eliminate duplicate
+ // guesses. We use a list to keep track of ordering which
+ // is helpful when trying to document a large set of changes.
+ if (functionNamesMap.get(functionGuess) == null)
+ nameList.add(functionGuess);
+ functionNamesMap.put(functionGuess, functionGuess);
+ }
}
+ // dump all unique func. guesses in the order found
+ fnames = new String[nameList.size()];
+ fnames = nameList.toArray(fnames);
} catch (CoreException e) {
ChangelogPlugin.getDefault().getLog().log(
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/SourceEditorInput.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/SourceEditorInput.java
new file mode 100644
index 0000000000..f80c86a35c
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/SourceEditorInput.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Wind River Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.changelog.core.actions;
+
+import org.eclipse.core.resources.IStorage;
+
+/**
+ * SourceEditorInput
+ */
+public class SourceEditorInput extends StorageEditorInput {
+
+ /**
+ * @param storage that represents a source file
+ */
+ public SourceEditorInput(IStorage storage) {
+ super(storage);
+ }
+
+ /*
+ * @see org.eclipse.ui.IEditorInput#exists()
+ */
+ public boolean exists() {
+ return false;
+ }
+
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/StorageEditorInput.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/StorageEditorInput.java
new file mode 100644
index 0000000000..d36a5b53c7
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/actions/StorageEditorInput.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Wind River Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.changelog.core.actions;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IStorageEditorInput;
+
+
+/**
+ * Abstract implementation of <code>IStorageEditorInput</code>.
+ */
+abstract public class StorageEditorInput implements IStorageEditorInput {
+
+ /**
+ * Storage associated with this editor input
+ */
+ private IStorage fStorage;
+
+ /**
+ * Constructs an editor input on the given storage
+ */
+ public StorageEditorInput(IStorage storage) {
+ fStorage = storage;
+ }
+
+ /**
+ * @see IStorageEditorInput#getStorage()
+ */
+ public IStorage getStorage() {
+ return fStorage;
+ }
+
+ /**
+ * Set new storage. For subclasses only.
+ * @param storage
+ */
+ protected void setStorage(IStorage storage) {
+ assert storage != null;
+ fStorage = storage;
+ }
+
+ /**
+ * @see IStorageEditorInput#getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ /**
+ * @see IStorageEditorInput#getName()
+ */
+ public String getName() {
+ return getStorage().getName();
+ }
+
+ /**
+ * @see IStorageEditorInput#getPersistable()
+ */
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ /**
+ * @see IStorageEditorInput#getToolTipText()
+ */
+ public String getToolTipText() {
+ return getStorage().getFullPath().toOSString();
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+ try {
+ return object instanceof IStorageEditorInput
+ && getStorage().equals(((IStorageEditorInput)object).getStorage());
+ } catch (CoreException e) {
+ }
+ return false;
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return getStorage().hashCode();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+}

Back to the top