X-Git-Url: http://git.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingStructureProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingStructureProvider.java
index 48be71c..074e4e9 100644
--- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingStructureProvider.java
+++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingStructureProvider.java
@@ -36,6 +36,7 @@ import net.sourceforge.phpdt.core.JavaModelException;
import net.sourceforge.phpdt.core.ToolFactory;
import net.sourceforge.phpdt.core.compiler.IScanner;
import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
+import net.sourceforge.phpdt.core.compiler.ITerminalSymbols.TokenName;
import net.sourceforge.phpdt.core.compiler.InvalidInputException;
import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
import net.sourceforge.phpdt.internal.ui.text.DocumentCharacterIterator;
@@ -47,7 +48,9 @@ import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
import net.sourceforge.phpeclipse.phpeditor.PHPUnitEditor;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.Assert;
+//incastrix
+//import org.eclipse.jface.text.Assert;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
@@ -65,10 +68,11 @@ import org.eclipse.ui.texteditor.ITextEditor;
/**
* Updates the projection model of a class file or compilation unit.
- *
+ *
* @since 3.0
*/
-public class DefaultJavaFoldingStructureProvider implements IProjectionListener, IJavaFoldingStructureProvider {
+public class DefaultJavaFoldingStructureProvider implements
+ IProjectionListener, IJavaFoldingStructureProvider {
private static class JavaProjectionAnnotation extends ProjectionAnnotation {
@@ -76,7 +80,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
private boolean fIsComment;
- public JavaProjectionAnnotation(IJavaElement element, boolean isCollapsed, boolean isComment) {
+ public JavaProjectionAnnotation(IJavaElement element,
+ boolean isCollapsed, boolean isComment) {
super(isCollapsed);
fJavaElement = element;
fIsComment = isComment;
@@ -131,7 +136,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
processDelta(delta);
}
- private IJavaElementDelta findElement(IJavaElement target, IJavaElementDelta delta) {
+ private IJavaElementDelta findElement(IJavaElement target,
+ IJavaElementDelta delta) {
if (delta == null || target == null)
return null;
@@ -157,13 +163,14 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
}
/**
- * Projection position that will return two foldable regions: one folding away
- * the region from after the '/**' to the beginning of the content, the other
- * from after the first content line until after the comment.
- *
+ * Projection position that will return two foldable regions: one folding
+ * away the region from after the '/**' to the beginning of the content, the
+ * other from after the first content line until after the comment.
+ *
* @since 3.1
*/
- private static final class CommentPosition extends Position implements IProjectionPosition {
+ private static final class CommentPosition extends Position implements
+ IProjectionPosition {
CommentPosition(int offset, int length) {
super(offset, length);
}
@@ -171,8 +178,10 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
/*
* @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeFoldingRegions(org.eclipse.jface.text.IDocument)
*/
- public IRegion[] computeProjectionRegions(IDocument document) throws BadLocationException {
- DocumentCharacterIterator sequence = new DocumentCharacterIterator(document, offset, offset + length);
+ public IRegion[] computeProjectionRegions(IDocument document)
+ throws BadLocationException {
+ DocumentCharacterIterator sequence = new DocumentCharacterIterator(
+ document, offset, offset + length);
int prefixEnd = 0;
int contentStart = findFirstContent(sequence, prefixEnd);
@@ -180,14 +189,18 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
int captionLine = document.getLineOfOffset(offset + contentStart);
int lastLine = document.getLineOfOffset(offset + length);
- Assert.isTrue(firstLine <= captionLine, "first folded line is greater than the caption line"); //$NON-NLS-1$
- Assert.isTrue(captionLine <= lastLine, "caption line is greater than the last folded line"); //$NON-NLS-1$
+ Assert.isTrue(firstLine <= captionLine,
+ "first folded line is greater than the caption line"); //$NON-NLS-1$
+ Assert.isTrue(captionLine <= lastLine,
+ "caption line is greater than the last folded line"); //$NON-NLS-1$
IRegion preRegion;
if (firstLine < captionLine) {
- // preRegion= new Region(offset + prefixEnd, contentStart - prefixEnd);
+ // preRegion= new Region(offset + prefixEnd, contentStart -
+ // prefixEnd);
int preOffset = document.getLineOffset(firstLine);
- IRegion preEndLineInfo = document.getLineInformation(captionLine);
+ IRegion preEndLineInfo = document
+ .getLineInformation(captionLine);
int preEnd = preEndLineInfo.getOffset();
preRegion = new Region(preOffset, preEnd - preOffset);
} else {
@@ -196,7 +209,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
if (captionLine < lastLine) {
int postOffset = document.getLineOffset(captionLine + 1);
- IRegion postRegion = new Region(postOffset, offset + length - postOffset);
+ IRegion postRegion = new Region(postOffset, offset + length
+ - postOffset);
if (preRegion == null)
return new IRegion[] { postRegion };
@@ -211,13 +225,13 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
}
/**
- * Finds the offset of the first identifier part within content
.
- * Returns 0 if none is found.
- *
+ * Finds the offset of the first identifier part within
+ * content
. Returns 0 if none is found.
+ *
* @param content
- * the content to search
- * @return the first index of a unicode identifier part, or zero if none can
- * be found
+ * the content to search
+ * @return the first index of a unicode identifier part, or zero if none
+ * can be found
*/
private int findFirstContent(final CharSequence content, int prefixEnd) {
int lenght = content.length();
@@ -234,7 +248,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
// * Returns 0 if none is found.
// *
// * @param content the content to search
- // * @return the first index of a unicode identifier part, or zero if none
+ // * @return the first index of a unicode identifier part, or zero if
+ // none
// can
// * be found
// */
@@ -244,7 +259,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
// int i= 0;
// while (i < len && isWhiteSpace(content.charAt(i)))
// i++;
- // if (len >= i + 2 && content.charAt(i) == '/' && content.charAt(i + 1) ==
+ // if (len >= i + 2 && content.charAt(i) == '/' && content.charAt(i + 1)
+ // ==
// '*')
// if (len >= i + 3 && content.charAt(i + 2) == '*')
// return i + 3;
@@ -263,19 +279,21 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
*/
public int computeCaptionOffset(IDocument document) {
// return 0;
- DocumentCharacterIterator sequence = new DocumentCharacterIterator(document, offset, offset + length);
+ DocumentCharacterIterator sequence = new DocumentCharacterIterator(
+ document, offset, offset + length);
return findFirstContent(sequence, 0);
}
}
/**
- * Projection position that will return two foldable regions: one folding away
- * the lines before the one containing the simple name of the java element,
- * one folding away any lines after the caption.
- *
+ * Projection position that will return two foldable regions: one folding
+ * away the lines before the one containing the simple name of the java
+ * element, one folding away any lines after the caption.
+ *
* @since 3.1
*/
- private static final class JavaElementPosition extends Position implements IProjectionPosition {
+ private static final class JavaElementPosition extends Position implements
+ IProjectionPosition {
private IMember fMember;
@@ -293,14 +311,16 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
/*
* @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeFoldingRegions(org.eclipse.jface.text.IDocument)
*/
- public IRegion[] computeProjectionRegions(IDocument document) throws BadLocationException {
+ public IRegion[] computeProjectionRegions(IDocument document)
+ throws BadLocationException {
int nameStart = offset;
try {
/*
- * The member's name range may not be correct. However, reconciling
- * would trigger another element delta which would lead to reentrant
- * situations. Therefore, we optimistically assume that the name range
- * is correct, but double check the received lines below.
+ * The member's name range may not be correct. However,
+ * reconciling would trigger another element delta which would
+ * lead to reentrant situations. Therefore, we optimistically
+ * assume that the name range is correct, but double check the
+ * received lines below.
*/
ISourceRange nameRange = fMember.getNameRange();
if (nameRange != null)
@@ -315,9 +335,9 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
int lastLine = document.getLineOfOffset(offset + length);
/*
- * see comment above - adjust the caption line to be inside the entire
- * folded region, and rely on later element deltas to correct the name
- * range.
+ * see comment above - adjust the caption line to be inside the
+ * entire folded region, and rely on later element deltas to correct
+ * the name range.
*/
if (captionLine < firstLine)
captionLine = firstLine;
@@ -327,7 +347,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
IRegion preRegion;
if (firstLine < captionLine) {
int preOffset = document.getLineOffset(firstLine);
- IRegion preEndLineInfo = document.getLineInformation(captionLine);
+ IRegion preEndLineInfo = document
+ .getLineInformation(captionLine);
int preEnd = preEndLineInfo.getOffset();
preRegion = new Region(preOffset, preEnd - preOffset);
} else {
@@ -336,7 +357,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
if (captionLine < lastLine) {
int postOffset = document.getLineOffset(captionLine + 1);
- IRegion postRegion = new Region(postOffset, offset + length - postOffset);
+ IRegion postRegion = new Region(postOffset, offset + length
+ - postOffset);
if (preRegion == null)
return new IRegion[] { postRegion };
@@ -353,7 +375,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
/*
* @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeCaptionOffset(org.eclipse.jface.text.IDocument)
*/
- public int computeCaptionOffset(IDocument document) throws BadLocationException {
+ public int computeCaptionOffset(IDocument document)
+ throws BadLocationException {
int nameStart = offset;
try {
// need a reconcile here?
@@ -427,7 +450,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
*/
public void projectionEnabled() {
// http://home.ott.oti.com/teams/wswb/anon/out/vms/index.html
- // projectionEnabled messages are not always paired with projectionDisabled
+ // projectionEnabled messages are not always paired with
+ // projectionDisabled
// i.e. multiple enabled messages may be sent out.
// we have to make sure that we disable first when getting an enable
// message.
@@ -468,7 +492,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
fHasHeaderComment = false;
if (fEditor instanceof PHPUnitEditor) {
- IWorkingCopyManager manager = PHPeclipsePlugin.getDefault().getWorkingCopyManager();
+ IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
+ .getWorkingCopyManager();
fInput = manager.getWorkingCopy(fEditor.getEditorInput());
}
// else if (fEditor instanceof ClassFileEditor) {
@@ -478,14 +503,16 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
// }
if (fInput != null) {
- ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor.getAdapter(ProjectionAnnotationModel.class);
+ ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor
+ .getAdapter(ProjectionAnnotationModel.class);
if (model != null) {
fCachedModel = model;
if (fInput instanceof ICompilationUnit) {
ICompilationUnit unit = (ICompilationUnit) fInput;
synchronized (unit) {
try {
- // unit.reconcile(ICompilationUnit.NO_AST, false, null, null);
+ // unit.reconcile(ICompilationUnit.NO_AST,
+ // false, null, null);
unit.reconcile();
} catch (JavaModelException x) {
}
@@ -494,14 +521,16 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
Map additions = computeAdditions((IParent) fInput);
/*
- * Minimize the events being sent out - as this happens in the UI
- * thread merge everything into one call.
+ * Minimize the events being sent out - as this happens in
+ * the UI thread merge everything into one call.
*/
List removals = new LinkedList();
Iterator existing = model.getAnnotationIterator();
while (existing.hasNext())
removals.add(existing.next());
- model.replaceAnnotations((Annotation[]) removals.toArray(new Annotation[removals.size()]), additions);
+ model.replaceAnnotations((Annotation[]) removals
+ .toArray(new Annotation[removals.size()]),
+ additions);
}
}
@@ -516,17 +545,23 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
}
private void initializePreferences() {
- IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
- fCollapseInnerTypes = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_INNERTYPES);
+ IPreferenceStore store = PHPeclipsePlugin.getDefault()
+ .getPreferenceStore();
+ fCollapseInnerTypes = store
+ .getBoolean(PreferenceConstants.EDITOR_FOLDING_INNERTYPES);
// fCollapseImportContainer =
// store.getBoolean(PreferenceConstants.EDITOR_FOLDING_IMPORTS);
- fCollapseJavadoc = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_JAVADOC);
- fCollapseMethods = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_METHODS);
- fCollapseHeaderComments = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_HEADERS);
+ fCollapseJavadoc = store
+ .getBoolean(PreferenceConstants.EDITOR_FOLDING_JAVADOC);
+ fCollapseMethods = store
+ .getBoolean(PreferenceConstants.EDITOR_FOLDING_METHODS);
+ fCollapseHeaderComments = store
+ .getBoolean(PreferenceConstants.EDITOR_FOLDING_HEADERS);
}
private Map computeAdditions(IParent parent) {
- Map map = new LinkedHashMap(); // use a linked map to maintain ordering of
+ Map map = new LinkedHashMap(); // use a linked map to maintain ordering
+ // of
// comments
try {
computeAdditions(parent.getChildren(), map);
@@ -535,7 +570,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
return map;
}
- private void computeAdditions(IJavaElement[] elements, Map map) throws JavaModelException {
+ private void computeAdditions(IJavaElement[] elements, Map map)
+ throws JavaModelException {
for (int i = 0; i < elements.length; i++) {
IJavaElement element = elements[i];
@@ -560,7 +596,13 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
// createProjection = true;
// break;
case IJavaElement.TYPE:
- collapse = fAllowCollapsing && fCollapseInnerTypes && isInnerType((IType) element);
+ collapse = fAllowCollapsing;
+ if (isInnerType((IType) element)) {
+ collapse = collapse && fCollapseInnerTypes;
+ } else {
+ collapse = false; // don't allow the most outer type to be
+ // folded, may be changed in future versions
+ }
createProjection = true;
break;
case IJavaElement.METHOD:
@@ -574,21 +616,28 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
if (regions != null) {
// comments
for (int i = 0; i < regions.length - 1; i++) {
- Position position = createProjectionPosition(regions[i], null);
+ Position position = createProjectionPosition(regions[i],
+ null);
boolean commentCollapse;
if (position != null) {
- if (i == 0 && (regions.length > 2 || fHasHeaderComment) && element == fFirstType) {
- commentCollapse = fAllowCollapsing && fCollapseHeaderComments;
+ if (i == 0 && (regions.length > 2 || fHasHeaderComment)
+ && element == fFirstType) {
+ commentCollapse = fAllowCollapsing
+ && fCollapseHeaderComments;
} else {
- commentCollapse = fAllowCollapsing && fCollapseJavadoc;
+ commentCollapse = fAllowCollapsing
+ && fCollapseJavadoc;
}
- map.put(new JavaProjectionAnnotation(element, commentCollapse, true), position);
+ map.put(new JavaProjectionAnnotation(element,
+ commentCollapse, true), position);
}
}
// code
- Position position = createProjectionPosition(regions[regions.length - 1], element);
+ Position position = createProjectionPosition(
+ regions[regions.length - 1], element);
if (position != null)
- map.put(new JavaProjectionAnnotation(element, collapse, false), position);
+ map.put(new JavaProjectionAnnotation(element, collapse,
+ false), position);
}
}
}
@@ -613,10 +662,11 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
* More than one range may be returned if the element has a leading comment
* which gets folded separately. If there are no foldable regions,
* null
is returned.
- *
+ *
* @param element
- * the java element that can be folded
- * @return the regions to be folded, or null
if there are none
+ * the java element that can be folded
+ * @return the regions to be folded, or null
if there are
+ * none
*/
private IRegion[] computeProjectionRanges(IJavaElement element) {
@@ -643,23 +693,25 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
final int shift = range.getOffset();
int start = shift;
if (element instanceof IType) {
- Scanner scanner = ToolFactory.createScanner(true, false, false, false);
+ Scanner scanner = ToolFactory.createScanner(true, false,
+ false, false);
scanner.setSource(contents.toCharArray());
scanner.setPHPMode(true);
- int token = scanner.getNextToken();
- while (token != ITerminalSymbols.TokenNameEOF) {
+ TokenName token = scanner.getNextToken();
+ while (token != ITerminalSymbols.TokenName.EOF) {
token = scanner.getNextToken();
start = shift + scanner.getCurrentTokenStartPosition();
switch (token) {
- case ITerminalSymbols.TokenNameCOMMENT_PHPDOC:
- case ITerminalSymbols.TokenNameCOMMENT_BLOCK: {
- int end = shift + scanner.getCurrentTokenEndPosition() + 1;
+ case COMMENT_PHPDOC:
+ case COMMENT_BLOCK: {
+ int end = shift
+ + scanner.getCurrentTokenEndPosition() + 1;
regions.add(new Region(start, end - start));
}
- case ITerminalSymbols.TokenNameCOMMENT_LINE:
+ case COMMENT_LINE:
continue;
}
}
@@ -701,26 +753,31 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
}
/*
- * code adapted from CommentFormattingStrategy: scan the header content up
- * to the first type. Once a comment is found, accumulate any additional
- * comments up to the stop condition. The stop condition is reaching a
- * package declaration, import container, or the end of the input.
+ * code adapted from CommentFormattingStrategy: scan the header
+ * content up to the first type. Once a comment is found, accumulate
+ * any additional comments up to the stop condition. The stop
+ * condition is reaching a package declaration, import container, or
+ * the end of the input.
*/
- IScanner scanner = ToolFactory.createScanner(true, false, false, false);
+ IScanner scanner = ToolFactory.createScanner(true, false, false,
+ false);
scanner.setSource(content.toCharArray());
int headerStart = -1;
int headerEnd = -1;
try {
boolean foundComment = false;
- int terminal = scanner.getNextToken();
- while (terminal != ITerminalSymbols.TokenNameEOF
- && !(terminal == ITerminalSymbols.TokenNameclass || terminal == ITerminalSymbols.TokenNameinterface || foundComment)) {
-
- if (terminal == ITerminalSymbols.TokenNameCOMMENT_PHPDOC || terminal == ITerminalSymbols.TokenNameCOMMENT_BLOCK
- || terminal == ITerminalSymbols.TokenNameCOMMENT_LINE) {
+ TokenName terminal = scanner.getNextToken();
+ while (terminal != ITerminalSymbols.TokenName.EOF
+ && !(terminal == ITerminalSymbols.TokenName.CLASS
+ || terminal == ITerminalSymbols.TokenName.INTERFACE || foundComment)) {
+
+ if (terminal == ITerminalSymbols.TokenName.COMMENT_PHPDOC
+ || terminal == ITerminalSymbols.TokenName.COMMENT_BLOCK
+ || terminal == ITerminalSymbols.TokenName.COMMENT_LINE) {
if (!foundComment)
- headerStart = scanner.getCurrentTokenStartPosition();
+ headerStart = scanner
+ .getCurrentTokenStartPosition();
headerEnd = scanner.getCurrentTokenEndPosition();
foundComment = true;
}
@@ -738,7 +795,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
return null;
}
- private Position createProjectionPosition(IRegion region, IJavaElement element) {
+ private Position createProjectionPosition(IRegion region,
+ IJavaElement element) {
if (fCachedDocument == null)
return null;
@@ -746,18 +804,21 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
try {
int start = fCachedDocument.getLineOfOffset(region.getOffset());
- int end = fCachedDocument.getLineOfOffset(region.getOffset() + region.getLength());
+ int end = fCachedDocument.getLineOfOffset(region.getOffset()
+ + region.getLength());
if (start != end) {
int offset = fCachedDocument.getLineOffset(start);
int endOffset;
if (fCachedDocument.getNumberOfLines() > end + 1)
endOffset = fCachedDocument.getLineOffset(end + 1);
else if (end > start)
- endOffset = fCachedDocument.getLineOffset(end) + fCachedDocument.getLineLength(end);
+ endOffset = fCachedDocument.getLineOffset(end)
+ + fCachedDocument.getLineLength(end);
else
return null;
if (element instanceof IMember)
- return new JavaElementPosition(offset, endOffset - offset, (IMember) element);
+ return new JavaElementPosition(offset, endOffset - offset,
+ (IMember) element);
else
return new CommentPosition(offset, endOffset - offset);
}
@@ -776,7 +837,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
if ((delta.getFlags() & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_CHILDREN)) == 0)
return;
- ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor.getAdapter(ProjectionAnnotationModel.class);
+ ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor
+ .getAdapter(ProjectionAnnotationModel.class);
if (model == null)
return;
@@ -799,39 +861,49 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
Iterator e = updated.keySet().iterator();
while (e.hasNext()) {
- JavaProjectionAnnotation newAnnotation = (JavaProjectionAnnotation) e.next();
- IJavaElement element = newAnnotation.getElement();
+ JavaProjectionAnnotation newAnnotation = (JavaProjectionAnnotation) e
+ .next();
+//+
Position newPosition = (Position) updated.get(newAnnotation);
-
- List annotations = (List) previous.get(element);
- if (annotations == null) {
-
- additions.put(newAnnotation, newPosition);
-
- } else {
- Iterator x = annotations.iterator();
- boolean matched = false;
- while (x.hasNext()) {
- Tuple tuple = (Tuple) x.next();
- JavaProjectionAnnotation existingAnnotation = tuple.annotation;
- Position existingPosition = tuple.position;
- if (newAnnotation.isComment() == existingAnnotation.isComment()) {
- if (existingPosition != null && (!newPosition.equals(existingPosition))) {
- existingPosition.setOffset(newPosition.getOffset());
- existingPosition.setLength(newPosition.getLength());
- updates.add(existingAnnotation);
- }
- matched = true;
- x.remove();
- break;
- }
- }
- if (!matched)
- additions.put(newAnnotation, newPosition);
-
- if (annotations.isEmpty())
- previous.remove(element);
- }
+ additions.put(newAnnotation, newPosition);
+//-
+// IJavaElement element = newAnnotation.getElement();
+// Position newPosition = (Position) updated.get(newAnnotation);
+//
+// List annotations = (List) previous.get(element);
+// if (annotations == null) {
+//
+// additions.put(newAnnotation, newPosition);
+//
+// } else {
+// Iterator x = annotations.iterator();
+// boolean matched = false;
+// while (x.hasNext()) {
+// Tuple tuple = (Tuple) x.next();
+// JavaProjectionAnnotation existingAnnotation = tuple.annotation;
+// Position existingPosition = tuple.position;
+// if (newAnnotation.isComment() == existingAnnotation
+// .isComment()) {
+// if (existingPosition != null
+// && (!newPosition.equals(existingPosition))) {
+// existingPosition.setOffset(newPosition
+// .getOffset());
+// existingPosition.setLength(newPosition
+// .getLength());
+// updates.add(existingAnnotation);
+// }
+// matched = true;
+// x.remove();
+// break;
+// }
+// }
+// if (!matched)
+// additions.put(newAnnotation, newPosition);
+//
+// if (annotations.isEmpty())
+// previous.remove(element);
+// }
+//-
}
e = previous.values().iterator();
@@ -862,10 +934,10 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
/**
* Matches deleted annotations to changed or added ones. A deleted
- * annotation/position tuple that has a matching addition / change is updated
- * and marked as changed. The matching tuple is not added (for additions) or
- * marked as deletion instead (for changes). The result is that more
- * annotations are changed and fewer get deleted/re-added.
+ * annotation/position tuple that has a matching addition / change is
+ * updated and marked as changed. The matching tuple is not added (for
+ * additions) or marked as deletion instead (for changes). The result is
+ * that more annotations are changed and fewer get deleted/re-added.
*/
private void match(List deletions, Map additions, List changes) {
if (deletions.isEmpty() || (additions.isEmpty() && changes.isEmpty()))
@@ -876,7 +948,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
Iterator deletionIterator = deletions.iterator();
while (deletionIterator.hasNext()) {
- JavaProjectionAnnotation deleted = (JavaProjectionAnnotation) deletionIterator.next();
+ JavaProjectionAnnotation deleted = (JavaProjectionAnnotation) deletionIterator
+ .next();
Position deletedPosition = fCachedModel.getPosition(deleted);
if (deletedPosition == null)
continue;
@@ -894,7 +967,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
IJavaElement element = match.annotation.getElement();
deleted.setElement(element);
deletedPosition.setLength(match.position.getLength());
- if (deletedPosition instanceof JavaElementPosition && element instanceof IMember) {
+ if (deletedPosition instanceof JavaElementPosition
+ && element instanceof IMember) {
JavaElementPosition jep = (JavaElementPosition) deletedPosition;
jep.setMember((IMember) element);
}
@@ -912,35 +986,38 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
}
/**
- * Finds a match for tuple
in a collection of annotations. The
- * positions for the JavaProjectionAnnotation
instances in
- * annotations
can be found in the passed
+ * Finds a match for tuple
in a collection of annotations.
+ * The positions for the JavaProjectionAnnotation
instances
+ * in annotations
can be found in the passed
* positionMap
or fCachedModel
if
* positionMap
is null
.
*
- * A tuple is said to match another if their annotations have the same comment - * flag and their position offsets are equal. + * A tuple is said to match another if their annotations have the same + * comment flag and their position offsets are equal. *
*
* If a match is found, the annotation gets removed from
* annotations
.
*
JavaProjectionAnnotation
+ * collection of JavaProjectionAnnotation
* @param positionMap
- * a Map<Annotation, Position>
or
- * null
+ * a Map<Annotation, Position>
or
+ * null
* @return a matching tuple or null
for no match
*/
private Tuple findMatch(Tuple tuple, Collection annotations, Map positionMap) {
Iterator it = annotations.iterator();
while (it.hasNext()) {
- JavaProjectionAnnotation annotation = (JavaProjectionAnnotation) it.next();
+ JavaProjectionAnnotation annotation = (JavaProjectionAnnotation) it
+ .next();
if (tuple.annotation.isComment() == annotation.isComment()) {
- Position position = positionMap == null ? fCachedModel.getPosition(annotation) : (Position) positionMap.get(annotation);
+ Position position = positionMap == null ? fCachedModel
+ .getPosition(annotation) : (Position) positionMap
+ .get(annotation);
if (position == null)
continue;
@@ -974,7 +1051,8 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
Comparator comparator = new Comparator() {
public int compare(Object o1, Object o2) {
- return ((Tuple) o1).position.getOffset() - ((Tuple) o2).position.getOffset();
+ return ((Tuple) o1).position.getOffset()
+ - ((Tuple) o2).position.getOffset();
}
};
for (Iterator it = map.values().iterator(); it.hasNext();) {