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 a15d39c..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,7 +36,9 @@ 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;
import net.sourceforge.phpdt.ui.IWorkingCopyManager;
import net.sourceforge.phpdt.ui.PreferenceConstants;
@@ -46,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;
@@ -64,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 {
@@ -75,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;
@@ -130,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;
@@ -156,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);
}
@@ -170,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);
@@ -179,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 {
@@ -195,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 };
@@ -210,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();
@@ -233,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
// */
@@ -243,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;
@@ -262,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;
@@ -292,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)
@@ -314,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;
@@ -326,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 {
@@ -335,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 };
@@ -352,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?
@@ -384,7 +408,7 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
private boolean fCollapseJavadoc = false;
-// private boolean fCollapseImportContainer = true;
+ // private boolean fCollapseImportContainer = true;
private boolean fCollapseInnerTypes = true;
@@ -426,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.
@@ -467,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) {
@@ -477,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) {
}
@@ -493,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);
}
}
@@ -515,17 +545,24 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
}
private void initializePreferences() {
- 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);
+ 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);
}
private Map computeAdditions(IParent parent) {
- Map map = new LinkedHashMap(); // use a linked map to maintain ordering of
- // comments
+ Map map = new LinkedHashMap(); // use a linked map to maintain ordering
+ // of
+ // comments
try {
computeAdditions(parent.getChildren(), map);
} catch (JavaModelException x) {
@@ -533,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];
@@ -553,12 +591,18 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
boolean collapse = false;
switch (element.getElementType()) {
-// case IJavaElement.IMPORT_CONTAINER:
-// collapse = fAllowCollapsing && fCollapseImportContainer;
-// createProjection = true;
-// break;
+ // case IJavaElement.IMPORT_CONTAINER:
+ // collapse = fAllowCollapsing && fCollapseImportContainer;
+ // 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:
@@ -572,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);
}
}
}
@@ -611,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) {
@@ -628,6 +680,7 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
return null;
List regions = new ArrayList();
+ // now add all comments first to the regions list
if (fFirstType == null && element instanceof IType) {
fFirstType = (IType) element;
IRegion headerComment = computeHeaderComment(fFirstType);
@@ -637,35 +690,41 @@ public class DefaultJavaFoldingStructureProvider implements IProjectionListener,
}
}
- IScanner scanner = ToolFactory.createScanner(true, false, false, false);
- scanner.setSource(contents.toCharArray());
final int shift = range.getOffset();
int start = shift;
- while (true) {
-
- int token = scanner.getNextToken();
- start = shift + scanner.getCurrentTokenStartPosition();
-
- switch (token) {
- case ITerminalSymbols.TokenNameCOMMENT_PHPDOC:
- case ITerminalSymbols.TokenNameCOMMENT_BLOCK: {
- int end = shift + scanner.getCurrentTokenEndPosition() + 1;
- regions.add(new Region(start, end - start));
- }
- case ITerminalSymbols.TokenNameCOMMENT_LINE:
- continue;
+ if (element instanceof IType) {
+ Scanner scanner = ToolFactory.createScanner(true, false,
+ false, false);
+ scanner.setSource(contents.toCharArray());
+ scanner.setPHPMode(true);
+
+ TokenName token = scanner.getNextToken();
+ while (token != ITerminalSymbols.TokenName.EOF) {
+
+ token = scanner.getNextToken();
+ start = shift + scanner.getCurrentTokenStartPosition();
+
+ switch (token) {
+ case COMMENT_PHPDOC:
+ case COMMENT_BLOCK: {
+ int end = shift
+ + scanner.getCurrentTokenEndPosition() + 1;
+ regions.add(new Region(start, end - start));
+ }
+ case COMMENT_LINE:
+ continue;
+ }
}
-
- break;
}
-
- regions.add(new Region(start, shift + range.getLength() - start));
+ // at the end add the element region
+ regions.add(new Region(range.getOffset(), range.getLength()));
if (regions.size() > 0) {
IRegion[] result = new IRegion[regions.size()];
regions.toArray(result);
return result;
}
+
}
} catch (JavaModelException e) {
} catch (InvalidInputException e) {
@@ -694,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;
}
@@ -731,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;
@@ -739,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);
}
@@ -769,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;
@@ -792,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();
@@ -855,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()))
@@ -869,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;
@@ -887,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);
}
@@ -905,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;
@@ -967,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();) {