* @return the regions to be folded
*/
protected final IRegion[] computeProjectionRanges(ISourceReference reference,
FoldingStructureComputationContext ctx) {
try {
ISourceRange range = reference.getSourceRange();
if (!SourceRange.isAvailable(range))
return new IRegion[0];
String contents = reference.getSource();
if (contents == null)
return new IRegion[0];
List<IRegion> regions = new ArrayList<IRegion>();
if (!ctx.hasFirstType() && reference instanceof IType) {
ctx.setFirstType((IType) reference);
IRegion headerComment = computeHeaderComment(ctx);
if (headerComment != null) {
regions.add(headerComment);
ctx.setHasHeaderComment();
}
}
final int shift = range.getOffset();
IScanner scanner = ctx.getScanner();
scanner.resetTo(shift, shift + range.getLength());
int start = shift;
while (true) {
int token = scanner.getNextToken();
start = scanner.getCurrentTokenStartPosition();
switch (token) {
case ITerminalSymbols.TokenNameCOMMENT_JAVADOC:
case ITerminalSymbols.TokenNameCOMMENT_BLOCK: {
int end = scanner.getCurrentTokenEndPosition() + 1;
regions.add(new Region(start, end - start));
continue;
}
case ITerminalSymbols.TokenNameCOMMENT_LINE:
continue;
}
break;
}
regions.add(new Region(start, shift + range.getLength() - start));
return regions.toArray(new IRegion[regions.size()]);
} catch (JavaModelException e) {} catch (InvalidInputException e) {}
return new IRegion[0];