int f = scan.offset;
marker.end(f);
marker.start(f);
RegionHandle openingBraceRegion = marker.end(++f);
marker.start(f);
/* // 'public'
scan.seek(TokenNamepublic);
f = scan.endOffset + 1;
marker.end(f);
marker.start(f);
RegionHandle afterOpeningBraceWhitespace = marker.end(++f);
*/
// show(document, afterOpeningBraceWhitespace);
// Seek parenthese opening parameter list
scan.seekCorresponding(TokenNameLPAREN);
int parameterListOpenParenOffset = scan.offset;
marker.end(parameterListOpenParenOffset);
marker.start(parameterListOpenParenOffset);
RegionHandle parameterListOpenParen = marker.end(parameterListOpenParenOffset + 1);
marker.start(parameterListOpenParenOffset + 1);
// assert scan.identifier != null;
//
// int methodNameIdentifierOffset = scan.identifierOffset;
//
// marker.end(methodNameIdentifierOffset - 1);
// // marker.start(methodNameIdentifierOffset - 1);
// // marker.end(methodNameIdentifierOffset);
//
// marker.start(methodNameIdentifierOffset);
int paramsCount = 0;
for (;;) {
int t = scan.seekCorrespondingWithTypeParameterBrackets(TokenNameCOMMA,
TokenNameRPAREN);
if (scan.identifier != null) {
paramsCount++;
marker.end(scan.identifierOffset);
if (editables != null) {
editables.start(scan.identifierOffset);
editables.end(scan.identifierOffset + scan.identifier.length);
}
if (t == TokenNameCOMMA) {
scan.seekAnyExcept(TokenNameWHITESPACE);
marker.start(scan.offset);
}
}
if (t == TokenNameRPAREN || t < 0) {
break;
}
}
int rparenOffset = scan.offset;
boolean allWhitespaceBetweenRParenAndFunctionToken = anomymousTypeSource.substring(
rparenOffset + 1, functionTokenIndex).trim().length() == 0;
if (!allWhitespaceBetweenRParenAndFunctionToken)
throw new UnsupportedOperationException("Token " + FUNCTION_RELATION_TOKEN +
" after parameter list right parenthese");
if (!marker.started)
marker.start(rparenOffset);
RegionHandle parameterListClosingParen = marker.end(rparenOffset + 1);
marker.start(rparenOffset + 1);
// To show functional arrow `=>`
int arrowIndex = functionTokenIndex + 2;
RegionHandle preArrowRegion = marker.end(arrowIndex);
marker.start(arrowIndex);
RegionHandle arrowRegion = marker.end(functionTokenIndex + 6);
marker.start(functionTokenIndex + 6);
// annotationDecorationDrawingOffsets.put((IType) fMember, anonymousTypeOffset +
// functionTokenIndex + 3);
scan.seekCorresponding(TokenNameLBRACE);
// // Start searching for lines a new
// scan.lineEnds.clear();
int methodOpeningBraceOffset = scan.offset;
int lastPreMethodOffset = functionTokenIndex + FUNCTION_RELATION_TOKEN.length();
// find where we go past all throws declaration if any
if (scan.identifierOffset > lastPreMethodOffset) {
lastPreMethodOffset = scan.identifierOffset + scan.identifier.length;
while (anomymousTypeSource.charAt(lastPreMethodOffset) == ' ') {
lastPreMethodOffset++;
}
}
// and hide it
boolean hasPreBraceRegion = lastPreMethodOffset < methodOpeningBraceOffset;
if (hasPreBraceRegion) {
marker.end(lastPreMethodOffset);
marker.start(lastPreMethodOffset);
// preBraceRegion = marker.end(methodOpeningBraceOffset);
// marker.start(methodOpeningBraceOffset);
}
RegionHandle preBraceRegion = marker.end(methodOpeningBraceOffset);
marker.start(methodOpeningBraceOffset);
RegionHandle methodOpeningBrace = marker.end(methodOpeningBraceOffset + 1);
int methodCloseBraceOffset = -1;
int returnOffset = -1;
boolean singleStatement = true;
int statementTerminator = -1;
int firstNonWhitespace = -1;
int lastBraceBlockEnd = -1;
bodyScanLoop: for (;;) {
int t = scan
.seekCorresponding(TokenNameSEMICOLON, TokenNameRBRACE, TokenNamereturn);
if (scan.wasFlowControlStatement)
singleStatement = false;
lastBraceBlockEnd = scan.lastBraceBlockEnd;
if (firstNonWhitespace < 0)
firstNonWhitespace = scan.firstNonWhitespace;
swicher: switch (t) {
case TokenNameSEMICOLON:
if (statementTerminator > 0 && singleStatement)
singleStatement = false;
statementTerminator = scan.offset;
continue bodyScanLoop;
case TokenNamereturn:
returnOffset = scan.offset;
continue bodyScanLoop;
case TokenNameRBRACE:
methodCloseBraceOffset = scan.offset;
}
break;
}
if (lastBraceBlockEnd > statementTerminator) {
statementTerminator = lastBraceBlockEnd;
singleStatement = false;
}
boolean useClauseFolding = false;
if (!singleStatement) {
useClauseFolding = wheretherAnonymousTypeIsSingleParameterToHigherOrderMethod(
document, anonymousTypeOffset, anonymousTypeLength);
}
// case 1: single statement returning value function with no or one parameter
// No curly braces, no return keyword, no semicolon at end
if (singleStatement && returnOffset > 0 && paramsCount <= 1) {
// afterOpeningBraceWhitespace.remove();
marker.start(methodOpeningBraceOffset); // from after opening of method body
// cutTab(anomymousTypeSource, marker, returnOffset - 1);
marker.end(returnOffset + 7); // to end of return keyword
if (!(statementTerminator > returnOffset + 7)) {
System.out.println(anomymousTypeSource);
}
marker.start(statementTerminator);// From before last semicolon
marker.end(anonymousTypeLength);// to end on anonymous type definition
if (editables != null) {
editables.start(returnOffset + 7);
editables.end(statementTerminator);
}
}
// case 2: single statement returning value function with more than one parameter
// With parameter parentheses, no return keyword, no semicolon at end
if (singleStatement && returnOffset > 0 && paramsCount > 1) {
parameterListOpenParen.reveal();// Show opening parameter paren
parameterListClosingParen.reveal();// Show closing parameter paren
// openingBraceRegion.reveal();// Show up openingBrace
marker.start(methodOpeningBraceOffset); // from after opening of method body
// brace
// cutTab(anomymousTypeSource, marker, returnOffset - 1);
marker.end(returnOffset + 7); // to end of return keyword
if (statementTerminator <= returnOffset + 7)
throw new UnsupportedOperationException("Statement terminator offset " +
statementTerminator + "; return end at " + (returnOffset + 7));
marker.start(statementTerminator);// From before last semicolon
marker.end(anonymousTypeLength);// to end on anonymous type definition
if (editables != null) {
editables.start(returnOffset + 7);
editables.end(statementTerminator);
}
}
// case 3: single statement void function with any parameters.
// With or without parameter parentheses and no semicolon at end
if (singleStatement && returnOffset < 0) {
if (paramsCount > 1) {
parameterListOpenParen.reveal();// Show opening parameter paren
parameterListClosingParen.reveal();// Show closing parameter paren
}
boolean emptyBody = lastBraceBlockEnd < 0 && statementTerminator < 0;
boolean singleEmptyStatement = lastBraceBlockEnd < 0 &&
statementTerminator > 0 &&
anomymousTypeSource.substring(methodOpeningBraceOffset + 1,
methodCloseBraceOffset).trim().equals(";");
if (emptyBody) {
methodOpeningBrace.reveal();// Show up openingBrace
marker.start(methodOpeningBraceOffset + 1); // from after opening of method body
marker.end(anonymousTypeLength - 1);// to end on anonymous type definition
} else if (singleEmptyStatement) {
methodOpeningBrace.reveal();// Show up openingBrace
marker.start(methodOpeningBraceOffset + 1); // from after opening of method body
// cutTab(anomymousTypeSource, marker, fnw - 1);
marker.end(statementTerminator);// to begin of statement
marker.start(statementTerminator + 1);// From before last semicolon
marker.end(anonymousTypeLength - 1);// to end on anonymous type definition
} else {
marker.start(methodOpeningBraceOffset); // from after opening of method body
// cutTab(anomymousTypeSource, marker, fnw - 1);
marker.end(firstNonWhitespace);// to begin of statement
marker.start(statementTerminator);// From before last semicolon
marker.end(anonymousTypeLength);// to end on anonymous type definition
// marker.start(statementTerminator + 1);// From after last semicolon
// marker.end(anonymousTypeLength - 1); // to before final closing brace
if (editables != null) {
editables.start(firstNonWhitespace);
editables.end(statementTerminator);
}
}
}
// case 4; multiline function with any parameters, with preserved body
// (maybe? with return keyword hidden and no semicolon at and for non-void function)
if (!singleStatement) {
if (paramsCount > 0) {
parameterListOpenParen.reveal();// Show opening parameter paren
parameterListClosingParen.reveal();// Show closing parameter paren
}
if (hasPreBraceRegion && !isOneLinerToken) {
preBraceRegion.reveal();
}
// Show up method openingBrace
methodOpeningBrace.reveal();
// marker.start(methodOpeningBraceOffset); // from before opening of method body
// marker.end(methodOpeningBraceOffset + 1);
// int methodRightBraceLine = document.getLineOfOffset(anonymousTypeOffset +
// methodCloseBraceOffset);
//
// int anonymousTypeBraceLine = document.getLineOfOffset(anonymousTypeOffset +
// anonymousTypeLength);
if (statementTerminator < 0) {
statementTerminator = methodCloseBraceOffset - 2;
}
if (editables != null) {
editables.start(methodOpeningBraceOffset + 1);
editables.end(statementTerminator + 1);
}
marker.start(statementTerminator + 1); // hide lines from body end
// to anonymous class end (exclusive)
RegionHandle closureEnd = marker.end(methodCloseBraceOffset + 1);
eatUpExtraTabsOnEachLine(anomymousTypeSource, marker, scan, lastPreMethodOffset,
methodCloseBraceOffset);
try {