Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 125905 Details for
Bug 183226
[Apply Patch] API to instantiate and apply arbitrary IHunks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch_v01
183226_v01.txt (text/plain), 6.67 KB, created by
Pawel Pogorzelski
on 2009-02-17 11:04:13 EST
(
hide
)
Description:
Patch_v01
Filename:
MIME Type:
Creator:
Pawel Pogorzelski
Created:
2009-02-17 11:04:13 EST
Size:
6.67 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.compare >Index: compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java,v >retrieving revision 1.2 >diff -u -r1.2 FileDiffWrapper.java >--- compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java 16 Feb 2009 14:08:14 -0000 1.2 >+++ compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java 17 Feb 2009 15:50:47 -0000 >@@ -75,4 +75,12 @@ > return fileDiff.getHunks(); > } > >+ public void addHunk(IHunk hunk) { >+ fileDiff.addHunk(hunk); >+ } >+ >+ public void removeHunk(IHunk hunk) { >+ fileDiff.removeHunk(hunk); >+ } >+ > } >#P org.eclipse.compare.core >Index: src/org/eclipse/compare/internal/core/patch/FileDiff.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiff.java,v >retrieving revision 1.3 >diff -u -r1.3 FileDiff.java >--- src/org/eclipse/compare/internal/core/patch/FileDiff.java 16 Feb 2009 14:08:16 -0000 1.3 >+++ src/org/eclipse/compare/internal/core/patch/FileDiff.java 17 Feb 2009 15:50:48 -0000 >@@ -112,7 +112,11 @@ > fHunks.add(hunk); > hunk.setParent(this); > } >- >+ >+ public void addHunk(IHunk hunk) { >+ add((Hunk)hunk); >+ } >+ > /** > * Remove the hunk from this file diff > * @param hunk the hunk >@@ -120,7 +124,11 @@ > protected void remove(Hunk hunk) { > fHunks.remove(hunk); > } >- >+ >+ public void removeHunk(IHunk hunk) { >+ remove((Hunk)hunk); >+ } >+ > /** > * Return the hunks associated with this file diff. > * @return the hunks associated with this file diff >Index: src/org/eclipse/compare/patch/IFilePatch2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatch2.java,v >retrieving revision 1.2 >diff -u -r1.2 IFilePatch2.java >--- src/org/eclipse/compare/patch/IFilePatch2.java 16 Feb 2009 14:08:16 -0000 1.2 >+++ src/org/eclipse/compare/patch/IFilePatch2.java 17 Feb 2009 15:50:50 -0000 >@@ -87,4 +87,22 @@ > */ > public IHunk[] getHunks(); > >+ /** >+ * Adds a hunk. >+ * >+ * @param hunk >+ * hunk to add >+ * @since org.eclipse.compare.core 1.0 >+ */ >+ public void addHunk(IHunk hunk); >+ >+ /** >+ * Removes a hunk. >+ * >+ * @param hunk >+ * hunk to add >+ * @since org.eclipse.compare.core 1.0 >+ */ >+ public void removeHunk(IHunk hunk); >+ > } >Index: src/org/eclipse/compare/patch/PatchFactory.java >=================================================================== >RCS file: src/org/eclipse/compare/patch/PatchFactory.java >diff -N src/org/eclipse/compare/patch/PatchFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/compare/patch/PatchFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,113 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.compare.patch; >+ >+import org.eclipse.compare.internal.core.patch.FileDiff; >+import org.eclipse.compare.internal.core.patch.Hunk; >+import org.eclipse.core.runtime.IPath; >+ >+/** >+ * Factory for creating IFilePatch2 and IHunk objects. >+ * >+ * @since org.eclipse.compare.core 1.0.0 >+ */ >+public class PatchFactory { >+ >+ /** >+ * Create a file diff for the given path and date information. >+ * >+ * @param oldPath >+ * the path of the before state of the file >+ * @param oldDate >+ * the timestamp of the before state >+ * @param newPath >+ * the path of the after state >+ * @param newDate >+ * the timestamp of the after state >+ * @return IFilePatch2 instance >+ */ >+ public IFilePatch2 createFilePatch(IPath oldPath, long oldDate, >+ IPath newPath, long newDate) { >+ return new FileDiff(oldPath, oldDate, newPath, newDate); >+ } >+ >+ /** >+ * @param oldStart >+ * the start position in the before file >+ * @param oldLength >+ * the length in the before file >+ * @param newStart >+ * the start position in the after file >+ * @param newLength >+ * the length in the after file >+ * @param lines >+ * content of the hunk. Each line starts with a control >+ * character. Their meaning is as follows: >+ * <ul> >+ * <li> >+ * '+': add the line >+ * <li> >+ * '-': delete the line >+ * <li> >+ * ' ': no change, context line >+ * </ul> >+ * @return IHunk instance >+ */ >+ public IHunk createHunk(int oldStart, int oldLength, int newStart, >+ int newLength, String[] lines) { >+ int hunkType = getHunkType(lines); >+ return new Hunk(null, hunkType, oldStart, oldLength, newStart, >+ newLength, lines); >+ } >+ >+ /** >+ * Returns hunk type given the hunk content. >+ * >+ * @param lines >+ * content of the hunk >+ * @return hunk type >+ */ >+ private int getHunkType(String[] lines) { >+ boolean hasContextLines = anyBeginsWith(" ", lines); >+ boolean hasLineAdditions = anyBeginsWith("+ ", lines); >+ boolean hasLineDeletions = anyBeginsWith("- ", lines); >+ if (!hasContextLines) { >+ if (hasLineAdditions && !hasLineDeletions) { >+ return FileDiff.ADDITION; >+ } else if (!hasLineAdditions && hasLineDeletions) { >+ return FileDiff.DELETION; >+ } >+ } >+ return FileDiff.CHANGE; >+ } >+ >+ /** >+ * Check if any of the passed lines starts with a given prefix. >+ * >+ * @param prefix >+ * the prefix to search for >+ * @param lines >+ * the array of lines to be searched for prefix >+ * @return if any of the passed lines starts with a given prefix >+ */ >+ private boolean anyBeginsWith(String prefix, String[] lines) { >+ for (int i = 0; i < lines.length; i++) { >+ if (lines[i].length() >= prefix.length()) { >+ for (int j = 0; j < prefix.length(); j++) { >+ if (prefix.charAt(j) == lines[i].charAt(j)) { >+ return true; >+ } >+ } >+ } >+ } >+ return false; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 183226
:
125904
|
125905
|
126312
|
126453
|
126468