Program: 34404
Project: 34404
Buggy source:
private int getNewIndent(int startOffset,int endOffset) throws BadLocationException {
  LinkedList<? extends Tree> path=getPath(startOffset);
  if (path.isEmpty()) {
    return 0;
  }
  Tree last=path.getFirst();
  int lastPos=getStartPosition(last);
  int currentIndent=getCurrentIndent(last,path);
switch (last.getKind()) {
case COMPILATION_UNIT:
    break;
case MODULE:
  TokenSequence<JavaTokenId> token=findFirstNonWhitespaceToken(startOffset,endOffset);
JavaTokenId nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != null && nextTokenId == JavaTokenId.RBRACE) {
if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getModuleDeclBracePlacement()) {
case NEW_LINE_INDENTED:
    currentIndent+=cs.getIndentSize();
  break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else {
Tree t=null;
for (Tree member : ((ModuleTree)last).getDirectives()) {
if (sp.getEndPosition(cut,member) > startOffset) {
break;
}
t=member;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? currentIndent + (cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0) : i;
}
 else {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
JavaTokenId prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case LBRACE:
currentIndent+=cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0;
break;
case IDENTIFIER:
if (nextTokenId != null && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getModuleDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else {
currentIndent+=cs.getContinuationIndentSize();
}
break;
default :
currentIndent+=cs.getContinuationIndentSize();
}
}
}
}
break;
case CLASS:
case INTERFACE:
case ENUM:
case ANNOTATION_TYPE:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != null && nextTokenId == JavaTokenId.RBRACE) {
if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getClassDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else {
Tree t=null;
for (Tree member : ((ClassTree)last).getMembers()) {
if (getEndPosition(member) > startOffset) {
break;
}
t=member;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? currentIndent + (cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0) : i;
}
 else {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
JavaTokenId prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case LBRACE:
if (path.get(1).getKind() == Kind.NEW_CLASS && isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getClassDeclBracePlacement()) {
case SAME_LINE:
case NEW_LINE:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() - cs.getIndentSize() / 2);
break;
}
}
 else {
currentIndent+=cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0;
}
break;
case COMMA:
currentIndent=getMultilineIndent(((ClassTree)last).getImplementsClause(),path,token.offset(),currentIndent,cs.alignMultilineImplements(),true);
break;
case IDENTIFIER:
case GT:
case GTGT:
case GTGTGT:
if (nextTokenId != null && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getClassDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else {
currentIndent+=cs.getContinuationIndentSize();
}
break;
default :
currentIndent+=cs.getContinuationIndentSize();
}
}
}
}
break;
case METHOD:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
JavaTokenId prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case COMMA:
List<? extends ExpressionTree> thrws=((MethodTree)last).getThrows();
if (!thrws.isEmpty() && getStartPosition(thrws.get(0)) < token.offset()) {
currentIndent=getMultilineIndent(thrws,path,token.offset(),currentIndent,cs.alignMultilineThrows(),true);
}
 else {
currentIndent=getMultilineIndent(((MethodTree)last).getParameters(),path,token.offset(),currentIndent,cs.alignMultilineMethodParams(),true);
}
break;
case RPAREN:
case IDENTIFIER:
case GT:
case GTGT:
case GTGTGT:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token != null && token.token().id() == JavaTokenId.LBRACE) {
switch (cs.getMethodDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
break;
}
default :
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.RPAREN) {
currentIndent+=cs.getContinuationIndentSize();
}
}
}
break;
case VARIABLE:
Tree type=((VariableTree)last).getType();
if (type != null && type.getKind() != Kind.ERRONEOUS) {
ExpressionTree init=((VariableTree)last).getInitializer();
if (init == null || init.getKind() != Kind.NEW_ARRAY || (token=findFirstNonWhitespaceToken(startOffset,lastPos)) == null || token.token().id() != JavaTokenId.EQ || (token=findFirstNonWhitespaceToken(startOffset,endOffset)) == null || token.token().id() != JavaTokenId.LBRACE) {
if (cs.alignMultilineAssignment()) {
int c=getColumn(last);
if (c >= 0) {
currentIndent=c;
}
}
 else {
currentIndent+=cs.getContinuationIndentSize();
}
}
 else {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
break;
}
 else {
last=((VariableTree)last).getModifiers();
if (last == null) break;
}
case MODIFIERS:
Tree t=null;
for (Tree ann : ((ModifiersTree)last).getAnnotations()) {
if (getEndPosition(ann) > startOffset) {
break;
}
t=ann;
}
if (t == null || findFirstNonWhitespaceToken(startOffset,getEndPosition(t)) != null) {
currentIndent+=cs.getContinuationIndentSize();
}
break;
case DO_WHILE_LOOP:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && !EnumSet.of(JavaTokenId.RBRACE,JavaTokenId.SEMICOLON).contains(token.token().id())) {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.DO),lastPos,currentIndent);
}
break;
case ENHANCED_FOR_LOOP:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((EnhancedForLoopTree)last).getExpression()),currentIndent);
break;
case FOR_LOOP:
LinkedList<Tree> forTrees=new LinkedList<Tree>();
for (StatementTree st : ((ForLoopTree)last).getInitializer()) {
if (getEndPosition(st) > startOffset) {
break;
}
forTrees.add(st);
}
t=((ForLoopTree)last).getCondition();
if (t != null && getEndPosition(t) <= startOffset) {
forTrees.add(t);
}
for (ExpressionStatementTree est : ((ForLoopTree)last).getUpdate()) {
if (getEndPosition(est) > startOffset) {
break;
}
forTrees.add(est);
}
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.SEMICOLON) {
currentIndent=getMultilineIndent(forTrees,path,token.offset(),currentIndent,cs.alignMultilineFor(),true);
}
 else {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),forTrees.isEmpty() ? lastPos : getEndPosition(forTrees.getLast()),currentIndent);
}
break;
case IF:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.ELSE) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && !EnumSet.of(JavaTokenId.RBRACE,JavaTokenId.SEMICOLON).contains(token.token().id())) {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN,JavaTokenId.ELSE),getEndPosition(((IfTree)last).getCondition()) - 1,currentIndent);
}
}
break;
case SYNCHRONIZED:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((SynchronizedTree)last).getExpression()) - 1,currentIndent);
break;
case TRY:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || !EnumSet.of(JavaTokenId.CATCH,JavaTokenId.FINALLY).contains(token.token().id())) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() != JavaTokenId.RBRACE) {
t=null;
for (Tree res : ((TryTree)last).getResources()) {
if (getEndPosition(res) > startOffset) {
break;
}
t=res;
}
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.TRY,JavaTokenId.RPAREN,JavaTokenId.FINALLY),t != null ? getEndPosition(t) : lastPos,currentIndent);
}
}
break;
case CATCH:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),lastPos,currentIndent);
break;
case WHILE_LOOP:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((WhileLoopTree)last).getCondition()) - 1,currentIndent);
break;
case BLOCK:
boolean isStatic=((BlockTree)last).isStatic();
if (isStatic) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.STATIC && token.offset() == lastPos) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
break;
}
}
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId == null || nextTokenId != JavaTokenId.RBRACE) {
token=findFirstOtherToken(startOffset,lastPos + 1,EnumSet.of(JavaTokenId.WHITESPACE));
int prevTokenLineStartOffset=token != null ? context.lineStartOffset(token.offset()) : -1;
t=null;
boolean isNextLabeledStatement=false;
Iterator<? extends StatementTree> it=((BlockTree)last).getStatements().iterator();
while (it.hasNext()) {
StatementTree st=it.next();
if (getEndPosition(st) > startOffset) {
isNextLabeledStatement=st.getKind() == Kind.LABELED_STATEMENT;
break;
}
t=st;
}
if (isNextLabeledStatement && cs.absoluteLabelIndent()) {
currentIndent=0;
}
 else if (t != null) {
int i=-1;
if (getEndPosition(t) < prevTokenLineStartOffset) {
Integer newIndent=newIndents.get(prevTokenLineStartOffset);
i=newIndent != null ? newIndent : context.lineIndent(prevTokenLineStartOffset);
}
 else {
i=getCurrentIndent(t,path);
}
currentIndent=i < 0 ? currentIndent + cs.getIndentSize() : i;
}
 else if (isStatic) {
currentIndent+=cs.getIndentSize();
}
 else if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (path.get(1).getKind() == Kind.METHOD ? cs.getMethodDeclBracePlacement() : cs.getOtherBracePlacement()) {
case SAME_LINE:
case NEW_LINE:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() - cs.getIndentSize() / 2);
break;
}
}
 else if (prevTokenLineStartOffset >= 0 && prevTokenLineStartOffset > context.lineStartOffset(lastPos)) {
Integer newIndent=newIndents.get(prevTokenLineStartOffset);
currentIndent=newIndent != null ? newIndent : context.lineIndent(prevTokenLineStartOffset);
}
 else {
int i=path.size() > 1 ? getCurrentIndent(path.get(1),path) : -1;
currentIndent=(i < 0 ? currentIndent : i) + cs.getIndentSize();
}
if (nextTokenId != null && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else if (isStatic) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else if (!isLeftBraceOnNewLine(lastPos,startOffset)) {
int i=getCurrentIndent(path.get(1),path);
if (i >= 0) {
currentIndent=i;
}
}
break;
case SWITCH:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != null && nextTokenId == JavaTokenId.RBRACE) {
if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else {
t=null;
for (CaseTree ct : ((SwitchTree)last).getCases()) {
if (getEndPosition(ct) > startOffset) {
break;
}
t=ct;
}
if (t != null) {
CaseTree ct=(CaseTree)t;
if (nextTokenId == null || !EnumSet.of(JavaTokenId.CASE,JavaTokenId.DEFAULT).contains(nextTokenId)) {
t=null;
for (StatementTree st : ct.getStatements()) {
if (getEndPosition(st) > startOffset) {
break;
}
t=st;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(ct.getExpression()),currentIndent) : i;
}
 else {
int i=getCurrentIndent(ct,path);
currentIndent=i < 0 ? getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(ct.getExpression()),currentIndent) : i;
currentIndent+=cs.getIndentSize();
}
}
 else {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? currentIndent + (cs.indentCasesFromSwitch() ? cs.getIndentSize() : 0) : i;
}
}
 else {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.LBRACE) {
currentIndent+=(cs.indentCasesFromSwitch() ? cs.getIndentSize() : 0);
}
 else {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((SwitchTree)last).getExpression()) - 1,currentIndent);
}
}
}
break;
case CASE:
t=null;
for (StatementTree st : ((CaseTree)last).getStatements()) {
if (getEndPosition(st) > startOffset) {
break;
}
t=st;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(((CaseTree)last).getExpression()),currentIndent) : i;
}
 else {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(((CaseTree)last).getExpression()),currentIndent);
}
break;
case NEW_ARRAY:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != JavaTokenId.RBRACE) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case LBRACE:
currentIndent+=cs.getIndentSize();
break;
case COMMA:
currentIndent=getMultilineIndent(((NewArrayTree)last).getInitializers(),path,token.offset(),currentIndent,cs.alignMultilineArrayInit(),false);
break;
case RBRACKET:
if (nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
break;
}
default :
currentIndent+=cs.getContinuationIndentSize();
}
}
}
break;
case LAMBDA_EXPRESSION:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
token=findFirstNonWhitespaceToken(startOffset,lastPos);
prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId == JavaTokenId.ARROW && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else if (nextTokenId != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
break;
case NEW_CLASS:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
token=findFirstNonWhitespaceToken(startOffset,lastPos);
prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId == JavaTokenId.RPAREN && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getClassDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else if (nextTokenId != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
break;
case METHOD_INVOCATION:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.COMMA) {
currentIndent=getMultilineIndent(((MethodInvocationTree)last).getArguments(),path,token.offset(),currentIndent,cs.alignMultilineCallArgs(),true);
}
 else {
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
}
break;
case ANNOTATION:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.COMMA) {
currentIndent=getMultilineIndent(((AnnotationTree)last).getArguments(),path,token.offset(),currentIndent,cs.alignMultilineAnnotationArgs(),true);
}
 else {
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
}
break;
case LABELED_STATEMENT:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token == null || token.token().id() != JavaTokenId.COLON) {
currentIndent=getContinuationIndent(path,currentIndent);
}
 else {
currentIndent+=cs.getLabelIndent();
}
break;
default :
currentIndent=getContinuationIndent(path,currentIndent);
break;
}
return currentIndent;
}

Fixed version (ground truth):
private int getNewIndent(int startOffset,int endOffset) throws BadLocationException {
  LinkedList<? extends Tree> path=getPath(startOffset);
  if (path.isEmpty()) {
    return 0;
  }
  Tree last=path.getFirst();
  int lastPos=getStartPosition(last);
  int currentIndent=getCurrentIndent(last,path);
switch (last.getKind()) {
case COMPILATION_UNIT:
    break;
case MODULE:
  TokenSequence<JavaTokenId> token=findFirstNonWhitespaceToken(startOffset,endOffset);
JavaTokenId nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != null && nextTokenId == JavaTokenId.RBRACE) {
if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getModuleDeclBracePlacement()) {
case NEW_LINE_INDENTED:
    currentIndent+=cs.getIndentSize();
  break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else {
Tree t=null;
for (Tree member : ((ModuleTree)last).getDirectives()) {
if (sp.getEndPosition(cut,member) > startOffset) {
break;
}
t=member;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? currentIndent + (cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0) : i;
}
 else {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
JavaTokenId prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case LBRACE:
currentIndent+=cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0;
break;
case IDENTIFIER:
if (nextTokenId != null && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getModuleDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else {
currentIndent+=cs.getContinuationIndentSize();
}
break;
default :
currentIndent+=cs.getContinuationIndentSize();
}
}
}
}
break;
case CLASS:
case INTERFACE:
case ENUM:
case ANNOTATION_TYPE:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != null && nextTokenId == JavaTokenId.RBRACE) {
if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getClassDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else {
Tree t=null;
for (Tree member : ((ClassTree)last).getMembers()) {
if (getEndPosition(member) > startOffset) {
break;
}
t=member;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? currentIndent + (cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0) : i;
}
 else {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
JavaTokenId prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case LBRACE:
if (path.size() > 1 && path.get(1).getKind() == Kind.NEW_CLASS && isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getClassDeclBracePlacement()) {
case SAME_LINE:
case NEW_LINE:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() - cs.getIndentSize() / 2);
break;
}
}
 else {
currentIndent+=cs.indentTopLevelClassMembers() ? cs.getIndentSize() : 0;
}
break;
case COMMA:
currentIndent=getMultilineIndent(((ClassTree)last).getImplementsClause(),path,token.offset(),currentIndent,cs.alignMultilineImplements(),true);
break;
case IDENTIFIER:
case GT:
case GTGT:
case GTGTGT:
if (nextTokenId != null && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getClassDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else {
currentIndent+=cs.getContinuationIndentSize();
}
break;
default :
currentIndent+=cs.getContinuationIndentSize();
}
}
}
}
break;
case METHOD:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
JavaTokenId prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case COMMA:
List<? extends ExpressionTree> thrws=((MethodTree)last).getThrows();
if (!thrws.isEmpty() && getStartPosition(thrws.get(0)) < token.offset()) {
currentIndent=getMultilineIndent(thrws,path,token.offset(),currentIndent,cs.alignMultilineThrows(),true);
}
 else {
currentIndent=getMultilineIndent(((MethodTree)last).getParameters(),path,token.offset(),currentIndent,cs.alignMultilineMethodParams(),true);
}
break;
case RPAREN:
case IDENTIFIER:
case GT:
case GTGT:
case GTGTGT:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token != null && token.token().id() == JavaTokenId.LBRACE) {
switch (cs.getMethodDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
break;
}
default :
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.RPAREN) {
currentIndent+=cs.getContinuationIndentSize();
}
}
}
break;
case VARIABLE:
Tree type=((VariableTree)last).getType();
if (type != null && type.getKind() != Kind.ERRONEOUS) {
ExpressionTree init=((VariableTree)last).getInitializer();
if (init == null || init.getKind() != Kind.NEW_ARRAY || (token=findFirstNonWhitespaceToken(startOffset,lastPos)) == null || token.token().id() != JavaTokenId.EQ || (token=findFirstNonWhitespaceToken(startOffset,endOffset)) == null || token.token().id() != JavaTokenId.LBRACE) {
if (cs.alignMultilineAssignment()) {
int c=getColumn(last);
if (c >= 0) {
currentIndent=c;
}
}
 else {
currentIndent+=cs.getContinuationIndentSize();
}
}
 else {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
break;
}
 else {
last=((VariableTree)last).getModifiers();
if (last == null) break;
}
case MODIFIERS:
Tree t=null;
for (Tree ann : ((ModifiersTree)last).getAnnotations()) {
if (getEndPosition(ann) > startOffset) {
break;
}
t=ann;
}
if (t == null || findFirstNonWhitespaceToken(startOffset,getEndPosition(t)) != null) {
currentIndent+=cs.getContinuationIndentSize();
}
break;
case DO_WHILE_LOOP:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && !EnumSet.of(JavaTokenId.RBRACE,JavaTokenId.SEMICOLON).contains(token.token().id())) {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.DO),lastPos,currentIndent);
}
break;
case ENHANCED_FOR_LOOP:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((EnhancedForLoopTree)last).getExpression()),currentIndent);
break;
case FOR_LOOP:
LinkedList<Tree> forTrees=new LinkedList<Tree>();
for (StatementTree st : ((ForLoopTree)last).getInitializer()) {
if (getEndPosition(st) > startOffset) {
break;
}
forTrees.add(st);
}
t=((ForLoopTree)last).getCondition();
if (t != null && getEndPosition(t) <= startOffset) {
forTrees.add(t);
}
for (ExpressionStatementTree est : ((ForLoopTree)last).getUpdate()) {
if (getEndPosition(est) > startOffset) {
break;
}
forTrees.add(est);
}
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.SEMICOLON) {
currentIndent=getMultilineIndent(forTrees,path,token.offset(),currentIndent,cs.alignMultilineFor(),true);
}
 else {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),forTrees.isEmpty() ? lastPos : getEndPosition(forTrees.getLast()),currentIndent);
}
break;
case IF:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.ELSE) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && !EnumSet.of(JavaTokenId.RBRACE,JavaTokenId.SEMICOLON).contains(token.token().id())) {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN,JavaTokenId.ELSE),getEndPosition(((IfTree)last).getCondition()) - 1,currentIndent);
}
}
break;
case SYNCHRONIZED:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((SynchronizedTree)last).getExpression()) - 1,currentIndent);
break;
case TRY:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || !EnumSet.of(JavaTokenId.CATCH,JavaTokenId.FINALLY).contains(token.token().id())) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() != JavaTokenId.RBRACE) {
t=null;
for (Tree res : ((TryTree)last).getResources()) {
if (getEndPosition(res) > startOffset) {
break;
}
t=res;
}
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.TRY,JavaTokenId.RPAREN,JavaTokenId.FINALLY),t != null ? getEndPosition(t) : lastPos,currentIndent);
}
}
break;
case CATCH:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),lastPos,currentIndent);
break;
case WHILE_LOOP:
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((WhileLoopTree)last).getCondition()) - 1,currentIndent);
break;
case BLOCK:
boolean isStatic=((BlockTree)last).isStatic();
if (isStatic) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.STATIC && token.offset() == lastPos) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
break;
}
}
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId == null || nextTokenId != JavaTokenId.RBRACE) {
token=findFirstOtherToken(startOffset,lastPos + 1,EnumSet.of(JavaTokenId.WHITESPACE));
int prevTokenLineStartOffset=token != null ? context.lineStartOffset(token.offset()) : -1;
t=null;
boolean isNextLabeledStatement=false;
Iterator<? extends StatementTree> it=((BlockTree)last).getStatements().iterator();
while (it.hasNext()) {
StatementTree st=it.next();
if (getEndPosition(st) > startOffset) {
isNextLabeledStatement=st.getKind() == Kind.LABELED_STATEMENT;
break;
}
t=st;
}
if (isNextLabeledStatement && cs.absoluteLabelIndent()) {
currentIndent=0;
}
 else if (t != null) {
int i=-1;
if (getEndPosition(t) < prevTokenLineStartOffset) {
Integer newIndent=newIndents.get(prevTokenLineStartOffset);
i=newIndent != null ? newIndent : context.lineIndent(prevTokenLineStartOffset);
}
 else {
i=getCurrentIndent(t,path);
}
currentIndent=i < 0 ? currentIndent + cs.getIndentSize() : i;
}
 else if (isStatic) {
currentIndent+=cs.getIndentSize();
}
 else if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (path.size() > 1 && path.get(1).getKind() == Kind.METHOD ? cs.getMethodDeclBracePlacement() : cs.getOtherBracePlacement()) {
case SAME_LINE:
case NEW_LINE:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() - cs.getIndentSize() / 2);
break;
}
}
 else if (prevTokenLineStartOffset >= 0 && prevTokenLineStartOffset > context.lineStartOffset(lastPos)) {
Integer newIndent=newIndents.get(prevTokenLineStartOffset);
currentIndent=newIndent != null ? newIndent : context.lineIndent(prevTokenLineStartOffset);
}
 else {
int i=path.size() > 1 ? getCurrentIndent(path.get(1),path) : -1;
currentIndent=(i < 0 ? currentIndent : i) + cs.getIndentSize();
}
if (nextTokenId != null && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else if (isStatic) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else if (!isLeftBraceOnNewLine(lastPos,startOffset)) {
int i=path.size() > 1 ? getCurrentIndent(path.get(1),path) : -1;
currentIndent=i < 0 ? currentIndent + cs.getIndentSize() : i;
}
break;
case SWITCH:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != null && nextTokenId == JavaTokenId.RBRACE) {
if (isLeftBraceOnNewLine(lastPos,startOffset)) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
}
 else {
t=null;
for (CaseTree ct : ((SwitchTree)last).getCases()) {
if (getEndPosition(ct) > startOffset) {
break;
}
t=ct;
}
if (t != null) {
CaseTree ct=(CaseTree)t;
if (nextTokenId == null || !EnumSet.of(JavaTokenId.CASE,JavaTokenId.DEFAULT).contains(nextTokenId)) {
t=null;
for (StatementTree st : ct.getStatements()) {
if (getEndPosition(st) > startOffset) {
break;
}
t=st;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(ct.getExpression()),currentIndent) : i;
}
 else {
int i=getCurrentIndent(ct,path);
currentIndent=i < 0 ? getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(ct.getExpression()),currentIndent) : i;
currentIndent+=cs.getIndentSize();
}
}
 else {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? currentIndent + (cs.indentCasesFromSwitch() ? cs.getIndentSize() : 0) : i;
}
}
 else {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.LBRACE) {
currentIndent+=(cs.indentCasesFromSwitch() ? cs.getIndentSize() : 0);
}
 else {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.RPAREN),getEndPosition(((SwitchTree)last).getExpression()) - 1,currentIndent);
}
}
}
break;
case CASE:
t=null;
for (StatementTree st : ((CaseTree)last).getStatements()) {
if (getEndPosition(st) > startOffset) {
break;
}
t=st;
}
if (t != null) {
int i=getCurrentIndent(t,path);
currentIndent=i < 0 ? getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(((CaseTree)last).getExpression()),currentIndent) : i;
}
 else {
currentIndent=getStmtIndent(startOffset,endOffset,EnumSet.of(JavaTokenId.COLON),getEndPosition(((CaseTree)last).getExpression()),currentIndent);
}
break;
case NEW_ARRAY:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
if (nextTokenId != JavaTokenId.RBRACE) {
token=findFirstNonWhitespaceToken(startOffset,lastPos);
prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId != null) {
switch (prevTokenId) {
case LBRACE:
currentIndent+=cs.getIndentSize();
break;
case COMMA:
currentIndent=getMultilineIndent(((NewArrayTree)last).getInitializers(),path,token.offset(),currentIndent,cs.alignMultilineArrayInit(),false);
break;
case RBRACKET:
if (nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
break;
}
default :
currentIndent+=cs.getContinuationIndentSize();
}
}
}
break;
case LAMBDA_EXPRESSION:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
token=findFirstNonWhitespaceToken(startOffset,lastPos);
prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId == JavaTokenId.ARROW && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getOtherBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else if (nextTokenId != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
break;
case NEW_CLASS:
token=findFirstNonWhitespaceToken(startOffset,endOffset);
nextTokenId=token != null ? token.token().id() : null;
token=findFirstNonWhitespaceToken(startOffset,lastPos);
prevTokenId=token != null ? token.token().id() : null;
if (prevTokenId == JavaTokenId.RPAREN && nextTokenId == JavaTokenId.LBRACE) {
switch (cs.getClassDeclBracePlacement()) {
case NEW_LINE_INDENTED:
currentIndent+=cs.getIndentSize();
break;
case NEW_LINE_HALF_INDENTED:
currentIndent+=(cs.getIndentSize() / 2);
break;
}
}
 else if (nextTokenId != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
break;
case METHOD_INVOCATION:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.COMMA) {
currentIndent=getMultilineIndent(((MethodInvocationTree)last).getArguments(),path,token.offset(),currentIndent,cs.alignMultilineCallArgs(),true);
}
 else {
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
}
break;
case ANNOTATION:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token != null && token.token().id() == JavaTokenId.COMMA) {
currentIndent=getMultilineIndent(((AnnotationTree)last).getArguments(),path,token.offset(),currentIndent,cs.alignMultilineAnnotationArgs(),true);
}
 else {
token=findFirstNonWhitespaceToken(startOffset,endOffset);
if (token == null || token.token().id() != JavaTokenId.RPAREN) {
currentIndent=getContinuationIndent(path,currentIndent);
}
}
break;
case LABELED_STATEMENT:
token=findFirstNonWhitespaceToken(startOffset,lastPos);
if (token == null || token.token().id() != JavaTokenId.COLON) {
currentIndent=getContinuationIndent(path,currentIndent);
}
 else {
currentIndent+=cs.getLabelIndent();
}
break;
default :
currentIndent=getContinuationIndent(path,currentIndent);
break;
}
return currentIndent;
}