nus-yam/ex-repair huggingface dataset:
Program: 185868
Project: 185868
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.putNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185871
Project: 185871
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.putNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185874
Project: 185874
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.putNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185877
Project: 185877
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.putNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185880
Project: 185880
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.putNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185883
Project: 185883
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(getField(type,pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(getField(type,pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.putNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185894
Project: 185894
Buggy source:
/** 
 * Use a SearchEngine to look for the types. <p> NOTE: This will not find inner types.
 * @see OrganizeImportsOperation.TypeReferenceProcessor#process(org.eclipse.core.runtime.IProgressMonitor)
 */
public void searchForTypes(GroovyCompilationUnit unit,Map<String,UnresolvedTypeData> missingTypes,IProgressMonitor monitor) throws JavaModelException {
  char[][] allTypes=new char[missingTypes.size()][];
  int i=0;
  for (  String simpleName : missingTypes.keySet()) {
    allTypes[i++]=simpleName.toCharArray();
  }
  final List<TypeNameMatch> typesFound=new ArrayList<TypeNameMatch>();
  TypeNameMatchCollector collector=new TypeNameMatchCollector(typesFound);
  IJavaSearchScope scope=SearchEngine.createJavaSearchScope(new IJavaElement[]{unit.getJavaProject()});
  int policy=(monitor == null ? IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH : IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH);
  new SearchEngine().searchAllTypeNames(null,allTypes,scope,collector,policy,monitor);
  for (  TypeNameMatch match : typesFound) {
    UnresolvedTypeData data=missingTypes.get(match.getSimpleTypeName());
    if (data == null) {
      GroovyCore.logException("String_Node_Str" + match.getFullyQualifiedName(),new Exception());
      continue;
    }
    if (isOfKind(match,data.isAnnotation)) {
      data.addInfo(match);
    }
  }
}

Fixed version (ground truth):
/** 
 * Use a SearchEngine to look for the types. <p> NOTE: This will not find inner types.
 * @see OrganizeImportsOperation.TypeReferenceProcessor#process(org.eclipse.core.runtime.IProgressMonitor)
 */
public void searchForTypes(GroovyCompilationUnit unit,Map<String,UnresolvedTypeData> missingTypes,IProgressMonitor monitor) throws JavaModelException, OperationCanceledException {
  char[][] allTypes=new char[missingTypes.size()][];
  int i=0;
  for (  String simpleName : missingTypes.keySet()) {
    allTypes[i++]=simpleName.toCharArray();
  }
  final List<TypeNameMatch> typesFound=new ArrayList<TypeNameMatch>();
  TypeNameMatchCollector collector=new TypeNameMatchCollector(typesFound);
  IJavaSearchScope scope=SearchEngine.createJavaSearchScope(new IJavaElement[]{unit.getJavaProject()});
  int policy=(monitor == null ? IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH : IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH);
  new SearchEngine().searchAllTypeNames(null,allTypes,scope,collector,policy,monitor);
  for (  TypeNameMatch match : typesFound) {
    UnresolvedTypeData data=missingTypes.get(match.getSimpleTypeName());
    if (data == null) {
      GroovyCore.logException("String_Node_Str" + match.getFullyQualifiedName(),new Exception());
      continue;
    }
    if (isOfKind(match,data.isAnnotation)) {
      data.addInfo(match);
    }
  }
}
Program: 185895
Project: 185895
Buggy source:
private boolean hasScriptStatements(BlockStatement statements){
  return statements != null && statements.getStatements() != null && statements.getStatements().size() > 0;
}

Fixed version (ground truth):
private boolean hasScriptStatements(BlockStatement statement){
  return statement != null && statement.getStatements() != null && !statement.getStatements().isEmpty();
}
Program: 185896
Project: 185896
Buggy source:
private ASTNode getLast(BlockStatement statements,List<MethodNode> methods){
  Statement lastStatement=hasScriptStatements(statements) ? statements.getStatements().get(statements.getStatements().size() - 1) : null;
  MethodNode lastMethod=hasScriptMethods(methods) ? methods.get(methods.size() - 1) : null;
  if (lastMethod == null && (lastStatement == null || (lastStatement.getStart() == 0 && lastStatement.getLength() == 0))) {
    lastStatement=createSyntheticAfterImports();
  }
  int statementStart=lastStatement != null ? lastStatement.getEnd() : Integer.MIN_VALUE;
  int methodStart=lastMethod != null ? lastMethod.getStart() : Integer.MIN_VALUE;
  return statementStart >= methodStart ? lastStatement : lastMethod;
}

Fixed version (ground truth):
/** 
 * Returns the last ast node in the script, either a method or a statement. 
 */
private ASTNode getLast(BlockStatement statement,List<MethodNode> methods){
  Statement lastStatement=hasScriptStatements(statement) ? statement.getStatements().get(statement.getStatements().size() - 1) : null;
  MethodNode lastMethod=hasScriptMethods(methods) ? methods.get(methods.size() - 1) : null;
  if (lastMethod == null && (lastStatement == null || (lastStatement.getStart() == 0 && lastStatement.getLength() == 0))) {
    lastStatement=createSyntheticAfterImports();
  }
  int statementStart=lastStatement != null ? lastStatement.getEnd() : Integer.MIN_VALUE;
  int methodStart=lastMethod != null ? lastMethod.getStart() : Integer.MIN_VALUE;
  return statementStart >= methodStart ? lastStatement : lastMethod;
}
Program: 185897
Project: 185897
Buggy source:
private ASTNode getFirst(BlockStatement statements,List<MethodNode> methods){
  Statement firstStatement=hasScriptStatements(statements) ? statements.getStatements().get(0) : null;
  MethodNode firstMethod=hasScriptMethods(methods) ? methods.get(0) : null;
  if (firstMethod == null && (firstStatement == null || (firstStatement.getStart() == 0 && firstStatement.getLength() == 0))) {
    firstStatement=createSyntheticAfterImports();
  }
  int statementStart=firstStatement != null ? firstStatement.getStart() : Integer.MAX_VALUE;
  int methodStart=firstMethod != null ? firstMethod.getStart() : Integer.MAX_VALUE;
  return statementStart <= methodStart ? firstStatement : firstMethod;
}

Fixed version (ground truth):
/** 
 * Returns the first ast node in the script, either a method or a statement. 
 */
private ASTNode getFirst(BlockStatement statement,List<MethodNode> methods){
  Statement firstStatement=hasScriptStatements(statement) ? statement.getStatements().get(0) : null;
  MethodNode firstMethod=hasScriptMethods(methods) ? methods.get(0) : null;
  if (firstMethod == null && (firstStatement == null || (firstStatement.getStart() == 0 && firstStatement.getLength() == 0))) {
    firstStatement=createSyntheticAfterImports();
  }
  int statementStart=firstStatement != null ? firstStatement.getStart() : Integer.MAX_VALUE;
  int methodStart=firstMethod != null ? firstMethod.getStart() : Integer.MAX_VALUE;
  return statementStart <= methodStart ? firstStatement : firstMethod;
}
Program: 185898
Project: 185898
Buggy source:
private boolean hasScriptMethods(List<MethodNode> methods){
  return methods != null && methods.size() > 0;
}

Fixed version (ground truth):
private boolean hasScriptMethods(List<MethodNode> methods){
  return methods != null && !methods.isEmpty();
}
Program: 185900
Project: 185900
Buggy source:
private Statement createSyntheticAfterImports(){
  ASTNode target=null;
  Statement synthetic=ReturnStatement.RETURN_NULL_OR_VOID;
  if (output.getImports() != null && output.getImports().size() > 0) {
    target=output.getImports().get(output.getImports().size() - 1);
  }
 else   if (output.hasPackage()) {
    target=output.getPackage();
  }
  if (target != null) {
    synthetic=new ReturnStatement(ConstantExpression.NULL);
    synthetic.setStart(target.getEnd() + 1);
    synthetic.setEnd(target.getEnd() + 1);
    synthetic.setLineNumber(target.getLastLineNumber());
    synthetic.setLastLineNumber(target.getLineNumber());
    synthetic.setColumnNumber(target.getLastColumnNumber() + 1);
    synthetic.setLastColumnNumber(target.getColumnNumber() + 1);
  }
  return synthetic;
}

Fixed version (ground truth):
/** 
 * Creates a synthetic statement that starts after the last import or package statement. 
 */
private Statement createSyntheticAfterImports(){
  Statement synthetic=ReturnStatement.RETURN_NULL_OR_VOID;
  ASTNode target=null;
  if (output.getImports() != null && !output.getImports().isEmpty()) {
    target=output.getImports().get(output.getImports().size() - 1);
  }
 else   if (output.hasPackage()) {
    target=output.getPackage();
  }
  if (target != null) {
    int off=Math.min(locations.findOffset(target.getLastLineNumber() + 1,1),locations.getEnd() - 1);
    int[] row_col=locations.getRowCol(off);
    synthetic=new ReturnStatement(ConstantExpression.NULL);
    synthetic.setStart(off);
    synthetic.setEnd(off);
    synthetic.setLineNumber(row_col[0]);
    synthetic.setColumnNumber(row_col[1]);
    synthetic.setLastLineNumber(row_col[0]);
    synthetic.setLastColumnNumber(row_col[1]);
  }
  return synthetic;
}
Program: 185901
Project: 185901
Buggy source:
private boolean hasScriptStatements(BlockStatement statements){
  return statements != null && statements.getStatements() != null && statements.getStatements().size() > 0;
}

Fixed version (ground truth):
private boolean hasScriptStatements(BlockStatement statement){
  return statement != null && statement.getStatements() != null && !statement.getStatements().isEmpty();
}
Program: 185902
Project: 185902
Buggy source:
private ASTNode getLast(BlockStatement statements,List<MethodNode> methods){
  Statement lastStatement=hasScriptStatements(statements) ? statements.getStatements().get(statements.getStatements().size() - 1) : null;
  MethodNode lastMethod=hasScriptMethods(methods) ? methods.get(methods.size() - 1) : null;
  if (lastMethod == null && (lastStatement == null || (lastStatement.getStart() == 0 && lastStatement.getLength() == 0))) {
    lastStatement=createSyntheticAfterImports();
  }
  int statementStart=lastStatement != null ? lastStatement.getEnd() : Integer.MIN_VALUE;
  int methodStart=lastMethod != null ? lastMethod.getStart() : Integer.MIN_VALUE;
  return statementStart >= methodStart ? lastStatement : lastMethod;
}

Fixed version (ground truth):
/** 
 * Returns the last ast node in the script, either a method or a statement. 
 */
private ASTNode getLast(BlockStatement statement,List<MethodNode> methods){
  Statement lastStatement=hasScriptStatements(statement) ? statement.getStatements().get(statement.getStatements().size() - 1) : null;
  MethodNode lastMethod=hasScriptMethods(methods) ? methods.get(methods.size() - 1) : null;
  if (lastMethod == null && (lastStatement == null || (lastStatement.getStart() == 0 && lastStatement.getLength() == 0))) {
    lastStatement=createSyntheticAfterImports();
  }
  int statementStart=lastStatement != null ? lastStatement.getEnd() : Integer.MIN_VALUE;
  int methodStart=lastMethod != null ? lastMethod.getStart() : Integer.MIN_VALUE;
  return statementStart >= methodStart ? lastStatement : lastMethod;
}
Program: 185903
Project: 185903
Buggy source:
private ASTNode getFirst(BlockStatement statements,List<MethodNode> methods){
  Statement firstStatement=hasScriptStatements(statements) ? statements.getStatements().get(0) : null;
  MethodNode firstMethod=hasScriptMethods(methods) ? methods.get(0) : null;
  if (firstMethod == null && (firstStatement == null || (firstStatement.getStart() == 0 && firstStatement.getLength() == 0))) {
    firstStatement=createSyntheticAfterImports();
  }
  int statementStart=firstStatement != null ? firstStatement.getStart() : Integer.MAX_VALUE;
  int methodStart=firstMethod != null ? firstMethod.getStart() : Integer.MAX_VALUE;
  return statementStart <= methodStart ? firstStatement : firstMethod;
}

Fixed version (ground truth):
/** 
 * Returns the first ast node in the script, either a method or a statement. 
 */
private ASTNode getFirst(BlockStatement statement,List<MethodNode> methods){
  Statement firstStatement=hasScriptStatements(statement) ? statement.getStatements().get(0) : null;
  MethodNode firstMethod=hasScriptMethods(methods) ? methods.get(0) : null;
  if (firstMethod == null && (firstStatement == null || (firstStatement.getStart() == 0 && firstStatement.getLength() == 0))) {
    firstStatement=createSyntheticAfterImports();
  }
  int statementStart=firstStatement != null ? firstStatement.getStart() : Integer.MAX_VALUE;
  int methodStart=firstMethod != null ? firstMethod.getStart() : Integer.MAX_VALUE;
  return statementStart <= methodStart ? firstStatement : firstMethod;
}
Program: 185904
Project: 185904
Buggy source:
private boolean hasScriptMethods(List<MethodNode> methods){
  return methods != null && methods.size() > 0;
}

Fixed version (ground truth):
private boolean hasScriptMethods(List<MethodNode> methods){
  return methods != null && !methods.isEmpty();
}
Program: 185906
Project: 185906
Buggy source:
private Statement createSyntheticAfterImports(){
  ASTNode target=null;
  Statement synthetic=ReturnStatement.RETURN_NULL_OR_VOID;
  if (output.getImports() != null && output.getImports().size() > 0) {
    target=output.getImports().get(output.getImports().size() - 1);
  }
 else   if (output.hasPackage()) {
    target=output.getPackage();
  }
  if (target != null) {
    synthetic=new ReturnStatement(ConstantExpression.NULL);
    synthetic.setStart(target.getEnd() + 1);
    synthetic.setEnd(target.getEnd() + 1);
    synthetic.setLineNumber(target.getLastLineNumber());
    synthetic.setLastLineNumber(target.getLineNumber());
    synthetic.setColumnNumber(target.getLastColumnNumber() + 1);
    synthetic.setLastColumnNumber(target.getColumnNumber() + 1);
  }
  return synthetic;
}

Fixed version (ground truth):
/** 
 * Creates a synthetic statement that starts after the last import or package statement. 
 */
private Statement createSyntheticAfterImports(){
  Statement synthetic=ReturnStatement.RETURN_NULL_OR_VOID;
  ASTNode target=null;
  if (output.getImports() != null && !output.getImports().isEmpty()) {
    target=output.getImports().get(output.getImports().size() - 1);
  }
 else   if (output.hasPackage()) {
    target=output.getPackage();
  }
  if (target != null) {
    int off=Math.min(locations.findOffset(target.getLastLineNumber() + 1,1),locations.getEnd() - 1);
    int[] row_col=locations.getRowCol(off);
    synthetic=new ReturnStatement(ConstantExpression.NULL);
    synthetic.setStart(off);
    synthetic.setEnd(off);
    synthetic.setLineNumber(row_col[0]);
    synthetic.setColumnNumber(row_col[1]);
    synthetic.setLastLineNumber(row_col[0]);
    synthetic.setLastColumnNumber(row_col[1]);
  }
  return synthetic;
}
Program: 185907
Project: 185907
Buggy source:
protected String printProposals(ICompletionProposal[] proposals){
  StringBuilder sb=new StringBuilder();
  sb.append("String_Node_Str");
  for (  ICompletionProposal proposal : proposals) {
    sb.append(proposal.getDisplayString() + "String_Node_Str");
  }
  return sb.toString();
}

Fixed version (ground truth):
protected String printProposals(ICompletionProposal[] proposals){
  StringBuilder sb=new StringBuilder();
  for (  ICompletionProposal proposal : proposals) {
    sb.append('\n').append(proposal.getDisplayString());
    if (proposal instanceof IJavaCompletionProposal) {
      sb.append("String_Node_Str").append(((IJavaCompletionProposal)proposal).getRelevance()).append(')');
    }
  }
  return sb.toString();
}
Program: 185908
Project: 185908
Buggy source:
protected void proposalExists(ICompletionProposal[] proposals,String name,int expectedCount,boolean isType){
  int foundCount=0;
  for (  ICompletionProposal proposal : proposals) {
    String propName=proposal.getDisplayString();
    if (propName.startsWith(name + "String_Node_Str")) {
      foundCount+=1;
    }
 else     if (propName.startsWith(name + "String_Node_Str")) {
      foundCount+=1;
    }
 else     if (isType && propName.startsWith(name)) {
      foundCount+=1;
    }
  }
  if (foundCount != expectedCount) {
    StringBuffer sb=new StringBuffer();
    for (    ICompletionProposal proposal : proposals) {
      sb.append("String_Node_Str" + proposal.toString());
    }
    fail("String_Node_Str" + name + "String_Node_Str"+ expectedCount+ "String_Node_Str"+ foundCount+ "String_Node_Str"+ sb);
  }
}

Fixed version (ground truth):
protected void proposalExists(ICompletionProposal[] proposals,String name,int expectedCount,boolean isType){
  int foundCount=0;
  for (  ICompletionProposal proposal : proposals) {
    String propName=proposal.getDisplayString();
    if (propName.startsWith(name + "String_Node_Str")) {
      foundCount+=1;
    }
 else     if (propName.startsWith(name + "String_Node_Str")) {
      foundCount+=1;
    }
 else     if (isType && propName.startsWith(name)) {
      foundCount+=1;
    }
  }
  if (foundCount != expectedCount) {
    fail("String_Node_Str" + name + "String_Node_Str"+ expectedCount+ "String_Node_Str"+ foundCount+ "String_Node_Str"+ printProposals(proposals));
  }
}
Program: 185909
Project: 185909
Buggy source:
protected void assertProposalOrdering(ICompletionProposal[] proposals,String... order){
  int startFrom=0;
  for (  String propName : order) {
    startFrom=findProposal(proposals,propName,false,startFrom) + 1;
    if (startFrom == 0) {
      fail("String_Node_Str" + propName + "String_Node_Str"+ printProposals(proposals));
    }
  }
}

Fixed version (ground truth):
protected void assertProposalOrdering(ICompletionProposal[] proposals,String... order){
  int prev=-1;
  for (int i=0, n=order.length; i < n; i+=1) {
    int next=findProposal(proposals,order[i],false,prev + 1);
    String message;
    if (i == 0) {
      message=String.format("String_Node_Str",order[i]);
    }
 else {
      message=String.format("String_Node_Str",order[i - 1],order[i]);
    }
    assertTrue(message + printProposals(proposals),next > prev);
    prev=next;
  }
}
Program: 185910
Project: 185910
Buggy source:
protected void checkProposalApplication(String contents,int proposalLocation,String[] expecteds,String[] proposalNames) throws Exception {
  ICompletionProposal[] proposals=createProposalsAtOffset(contents,proposalLocation);
  for (int i=0; i < expecteds.length; i++) {
    ICompletionProposal firstProposal=findFirstProposal(proposals,proposalNames[i],false);
    if (firstProposal == null) {
      fail("String_Node_Str");
    }
    applyProposalAndCheck(new Document(contents),firstProposal,expecteds[i]);
  }
}

Fixed version (ground truth):
protected void checkProposalApplication(String contents,int proposalLocation,String[] expecteds,String[] proposalNames) throws Exception {
  ICompletionProposal[] proposals=createProposalsAtOffset(contents,proposalLocation);
  for (int i=0; i < expecteds.length; i++) {
    ICompletionProposal firstProposal=findFirstProposal(proposals,proposalNames[i],false);
    assertNotNull("String_Node_Str",firstProposal);
    applyProposalAndCheck(new Document(contents),firstProposal,expecteds[i]);
  }
}
Program: 185911
Project: 185911
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null)       return constant;
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185912
Project: 185912
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null)       return constant;
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185913
Project: 185913
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null)       return constant;
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185914
Project: 185914
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null)       return constant;
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185915
Project: 185915
Buggy source:
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null)       return constant;
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}

Fixed version (ground truth):
private Expression transformInlineConstants(Expression exp){
  if (exp instanceof PropertyExpression) {
    PropertyExpression pe=(PropertyExpression)exp;
    if (pe.getObjectExpression() instanceof ClassExpression) {
      ClassExpression ce=(ClassExpression)pe.getObjectExpression();
      ClassNode type=ce.getType();
      if (type.isEnum())       return exp;
      Expression constant=findConstant(type.getField(pe.getPropertyAsString()));
      if (constant != null) {
        String name=pe.getText().replace('$','.');
        Object alias=pe.getNodeMetaData("String_Node_Str");
        if (alias != null && !alias.equals(pe.getPropertyAsString())) {
          name+="String_Node_Str" + alias;
        }
        constant.setNodeMetaData("String_Node_Str",name);
        return constant;
      }
    }
  }
 else   if (exp instanceof ListExpression) {
    ListExpression le=(ListExpression)exp;
    ListExpression result=new ListExpression();
    for (    Expression e : le.getExpressions()) {
      result.addExpression(transformInlineConstants(e));
    }
    return result;
  }
  return exp;
}
Program: 185922
Project: 185922
Buggy source:
public ClassNode lookupClassNodeForBinary(String typename,JDTResolver jdtResolver){
  char[][] compoundName=CharOperation.splitOn('.',typename.toCharArray());
  TypeBinding jdtBinding=getType(compoundName,compoundName.length);
  if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) {
    ClassNode classNode=jdtResolver.convertToClassNode(jdtBinding);
    return classNode;
  }
  if (jdtBinding != null && (jdtBinding instanceof ProblemReferenceBinding)) {
    ProblemReferenceBinding prBinding=(ProblemReferenceBinding)jdtBinding;
    if (prBinding.problemId() == ProblemReasons.InternalNameProvided) {
      jdtBinding=prBinding.closestMatch();
      if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) {
        return jdtResolver.convertToClassNode(jdtBinding);
      }
    }
  }
  return null;
}

Fixed version (ground truth):
public ClassNode lookupClassNodeForBinary(String typename,JDTResolver jdtResolver){
  char[][] compoundName=CharOperation.splitOn('.',typename.toCharArray());
  TypeBinding jdtBinding=getType(compoundName,compoundName.length);
  if (jdtBinding instanceof BinaryTypeBinding) {
    return jdtResolver.convertToClassNode(jdtBinding);
  }
  if (jdtBinding instanceof ProblemReferenceBinding) {
    ProblemReferenceBinding prBinding=(ProblemReferenceBinding)jdtBinding;
    if (prBinding.problemId() == ProblemReasons.InternalNameProvided) {
      jdtBinding=prBinding.closestMatch();
      if (jdtBinding instanceof BinaryTypeBinding) {
        return jdtResolver.convertToClassNode(jdtBinding);
      }
    }
  }
  return null;
}
Program: 185923
Project: 185923
Buggy source:
/** 
 * Look in the local cache, if we don't find it then ask JDT. If JDT responds with a SourceTypeBinding then it has been found. If JDT responds with some other kind of binding, we consider that 'not found as source' and return null. Not quite the right name for this method, because on an incremental build it will find BinaryTypeBindings for types that were SourceTypeBindings during the full build
 */
public ClassNode lookupClassNodeForSource(String typename,JDTResolver jdtResolver){
  ClassNode node=typenameToClassNodeCache.get(typename);
  if (node != null) {
    return node;
  }
  char[][] compoundName=CharOperation.splitOn('.',typename.toCharArray());
  TypeBinding jdtBinding=null;
  try {
    jdtBinding=getType(compoundName,compoundName.length);
  }
 catch (  AbortCompilation t) {
    if (t.silentException instanceof AbortIncrementalBuildException) {
      jdtBinding=null;
    }
 else {
      throw t;
    }
  }
  if (jdtBinding != null) {
    if (jdtBinding instanceof SourceTypeBinding) {
      ClassNode classNode=jdtResolver.convertToClassNode(jdtBinding);
      if (classNode != null) {
        typenameToClassNodeCache.put(typename,classNode);
      }
      return classNode;
    }
 else     if (jdtBinding instanceof BinaryTypeBinding) {
      ClassNode newNode=jdtResolver.convertToClassNode(jdtBinding);
      if (newNode != null) {
        typenameToClassNodeCache.put(typename,newNode);
      }
      return newNode;
    }
  }
  if (jdtBinding != null && (jdtBinding instanceof ProblemReferenceBinding)) {
    ProblemReferenceBinding prBinding=(ProblemReferenceBinding)jdtBinding;
    if (prBinding.problemId() == ProblemReasons.InternalNameProvided) {
      jdtBinding=prBinding.closestMatch();
      if (jdtBinding != null && (jdtBinding instanceof SourceTypeBinding)) {
        return jdtResolver.convertToClassNode(jdtBinding);
      }
      if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) {
        return jdtResolver.convertToClassNode(jdtBinding);
      }
    }
  }
  return null;
}

Fixed version (ground truth):
public ClassNode lookupClassNodeForSource(String typename,JDTResolver jdtResolver){
  char[][] compoundName=CharOperation.splitOn('.',typename.toCharArray());
  TypeBinding jdtBinding=null;
  try {
    jdtBinding=getType(compoundName,compoundName.length);
  }
 catch (  AbortCompilation t) {
    if (t.silentException instanceof AbortIncrementalBuildException) {
      jdtBinding=null;
    }
 else {
      throw t;
    }
  }
  if (jdtBinding instanceof SourceTypeBinding || jdtBinding instanceof BinaryTypeBinding) {
    return jdtResolver.convertToClassNode(jdtBinding);
  }
  if (jdtBinding instanceof ProblemReferenceBinding) {
    ProblemReferenceBinding prBinding=(ProblemReferenceBinding)jdtBinding;
    if (prBinding.problemId() == ProblemReasons.InternalNameProvided) {
      jdtBinding=prBinding.closestMatch();
      if (jdtBinding instanceof SourceTypeBinding || jdtBinding instanceof BinaryTypeBinding) {
        return jdtResolver.convertToClassNode(jdtBinding);
      }
    }
  }
  return null;
}
Program: 185924
Project: 185924
Buggy source:
/** 
 * Grabs the explicit declaring type of the   {@link AnnotatedNode}.  This will not return the expected value for   {@link MethodCallExpression}s.
 */
@Override protected Collection<ClassNode> explodeObject(Object toMatch){
  if (toMatch instanceof AnnotatedNode) {
    return Collections.singleton(((AnnotatedNode)toMatch).getDeclaringClass());
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Grabs the explicit declaring type of the   {@link AnnotatedNode}. This will not return the expected value for   {@link MethodCallExpression}s.
 */
@Override protected Collection<ClassNode> explodeObject(Object toMatch){
  if (toMatch instanceof AnnotatedNode) {
    return Collections.singleton(((AnnotatedNode)toMatch).getDeclaringClass());
  }
  return null;
}
Program: 185925
Project: 185925
Buggy source:
private String readClassDeclaration(ClassNode node){
  String code=(String)node.getNodeMetaData("String_Node_Str");
  if (code == null) {
    code=String.valueOf(GroovyUtils.readSourceRange(module.getContext(),node.getStart(),node.getLength()));
    node.setNodeMetaData("String_Node_Str",code);
  }
  return code.substring(0,code.indexOf('{'));
}

Fixed version (ground truth):
private String readClassDeclaration(ClassNode node){
  String code=(String)node.getNodeMetaData("String_Node_Str");
  if (code == null) {
    code=String.valueOf(GroovyUtils.readSourceRange(module.getContext(),node.getStart(),node.getLength()));
    node.putNodeMetaData("String_Node_Str",code);
  }
  return code.substring(0,code.indexOf('{'));
}