Program: 185887
Project: 185887
Buggy source:
public Type convertType(TypeReference typeReference){
  if (typeReference instanceof Wildcard) {
    final Wildcard wildcard=(Wildcard)typeReference;
    final WildcardType wildcardType=new WildcardType(this.ast);
    if (wildcard.bound != null) {
      final Type bound=convertType(wildcard.bound);
      wildcardType.setBound(bound,wildcard.kind == Wildcard.EXTENDS);
      int start=wildcard.sourceStart;
      wildcardType.setSourceRange(start,bound.getStartPosition() + bound.getLength() - start);
    }
 else {
      final int start=wildcard.sourceStart;
      final int end=wildcard.sourceEnd;
      wildcardType.setSourceRange(start,end - start + 1);
    }
    if (this.resolveBindings) {
      recordNodes(wildcardType,typeReference);
    }
    return wildcardType;
  }
  Type type=null;
  int sourceStart=-1;
  int length=0;
  int dimensions=typeReference.dimensions();
  if (typeReference instanceof org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) {
    char[] name=((org.eclipse.jdt.internal.compiler.ast.SingleTypeReference)typeReference).getTypeName()[0];
    sourceStart=typeReference.sourceStart;
    length=typeReference.sourceEnd - typeReference.sourceStart + 1;
    if (isPrimitiveType(name)) {
      int end=retrieveEndOfElementTypeNamePosition(sourceStart,sourceStart + length);
      if (end == -1) {
        end=sourceStart + length - 1;
      }
      final PrimitiveType primitiveType=new PrimitiveType(this.ast);
      primitiveType.setPrimitiveTypeCode(getPrimitiveTypeCode(name));
      primitiveType.setSourceRange(sourceStart,end - sourceStart + 1);
      type=primitiveType;
    }
 else     if (typeReference instanceof ParameterizedSingleTypeReference) {
      ParameterizedSingleTypeReference parameterizedSingleTypeReference=(ParameterizedSingleTypeReference)typeReference;
      final SimpleName simpleName=new SimpleName(this.ast);
      simpleName.internalSetIdentifier(new String(name));
      int end=retrieveEndOfElementTypeNamePosition(sourceStart,sourceStart + length);
      if (end == -1) {
        end=sourceStart + length - 1;
      }
      simpleName.setSourceRange(sourceStart,end - sourceStart + 1);
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
        SimpleType simpleType=new SimpleType(this.ast);
      simpleType.setName(simpleName);
    simpleType.setFlags(simpleType.getFlags() | ASTNode.MALFORMED);
  simpleType.setSourceRange(sourceStart,end - sourceStart + 1);
type=simpleType;
if (this.resolveBindings) {
this.recordNodes(simpleName,typeReference);
}
break;
default :
simpleType=new SimpleType(this.ast);
simpleType.setName(simpleName);
simpleType.setSourceRange(simpleName.getStartPosition(),simpleName.getLength());
final ParameterizedType parameterizedType=new ParameterizedType(this.ast);
parameterizedType.setType(simpleType);
type=parameterizedType;
TypeReference[] typeArguments=parameterizedSingleTypeReference.typeArguments;
if (typeArguments != null) {
Type type2=null;
for (int i=0, max=typeArguments.length; i < max; i++) {
type2=convertType(typeArguments[i]);
((ParameterizedType)type).typeArguments().add(type2);
end=type2.getStartPosition() + type2.getLength() - 1;
}
end=retrieveClosingAngleBracketPosition(end + 1);
type.setSourceRange(sourceStart,end - sourceStart + 1);
}
 else {
type.setSourceRange(sourceStart,end - sourceStart + 1);
}
if (this.resolveBindings) {
this.recordNodes(simpleName,typeReference);
this.recordNodes(simpleType,typeReference);
}
}
}
 else {
final SimpleName simpleName=new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(name));
int end=retrieveEndOfElementTypeNamePosition(sourceStart,sourceStart + length);
if (end == -1) {
end=sourceStart + length - 1;
}
simpleName.setSourceRange(sourceStart,end - sourceStart + 1);
final SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(simpleName);
type=simpleType;
type.setSourceRange(sourceStart,end - sourceStart + 1);
type=simpleType;
if (this.resolveBindings) {
this.recordNodes(simpleName,typeReference);
}
}
if (dimensions != 0) {
type=this.ast.newArrayType(type,dimensions);
type.setSourceRange(sourceStart,length);
ArrayType subarrayType=(ArrayType)type;
int index=dimensions - 1;
while (index > 0) {
subarrayType=(ArrayType)subarrayType.getComponentType();
int end=retrieveProperRightBracketPosition(index,sourceStart);
subarrayType.setSourceRange(sourceStart,end - sourceStart + 1);
index--;
}
if (this.resolveBindings) {
completeRecord((ArrayType)type,typeReference);
}
}
}
 else {
if (typeReference instanceof ParameterizedQualifiedTypeReference) {
ParameterizedQualifiedTypeReference parameterizedQualifiedTypeReference=(ParameterizedQualifiedTypeReference)typeReference;
char[][] tokens=parameterizedQualifiedTypeReference.tokens;
TypeReference[][] typeArguments=parameterizedQualifiedTypeReference.typeArguments;
long[] positions=parameterizedQualifiedTypeReference.sourcePositions;
sourceStart=(int)(positions[0] >>> 32);
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
{
char[][] name=((org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)typeReference).getTypeName();
int nameLength=name.length;
sourceStart=(int)(positions[0] >>> 32);
length=(int)(positions[nameLength - 1] & 0xFFFFFFFF) - sourceStart + 1;
Name qualifiedName=this.setQualifiedNameNameAndSourceRanges(name,positions,typeReference);
final SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(qualifiedName);
simpleType.setSourceRange(sourceStart,length);
type=simpleType;
}
break;
default :
if (typeArguments != null) {
int numberOfEnclosingType=0;
int startingIndex=0;
int endingIndex=0;
for (int i=0, max=typeArguments.length; i < max; i++) {
if (typeArguments[i] != null) {
numberOfEnclosingType++;
}
 else if (numberOfEnclosingType == 0) {
endingIndex++;
}
}
Name name=null;
if (endingIndex - startingIndex == 0) {
final SimpleName simpleName=new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(tokens[startingIndex]));
recordPendingNameScopeResolution(simpleName);
int start=(int)(positions[startingIndex] >>> 32);
int end=(int)positions[startingIndex];
simpleName.setSourceRange(start,end - start + 1);
simpleName.index=1;
name=simpleName;
if (this.resolveBindings) {
recordNodes(simpleName,typeReference);
}
}
 else {
name=this.setQualifiedNameNameAndSourceRanges(tokens,positions,endingIndex,typeReference);
}
SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(name);
int start=(int)(positions[startingIndex] >>> 32);
int end=(int)positions[endingIndex];
simpleType.setSourceRange(start,end - start + 1);
ParameterizedType parameterizedType=new ParameterizedType(this.ast);
parameterizedType.setType(simpleType);
if (this.resolveBindings) {
recordNodes(simpleType,typeReference);
recordNodes(parameterizedType,typeReference);
}
start=simpleType.getStartPosition();
end=start + simpleType.getLength() - 1;
for (int i=0, max=typeArguments[endingIndex].length; i < max; i++) {
final Type type2=convertType(typeArguments[endingIndex][i]);
parameterizedType.typeArguments().add(type2);
end=type2.getStartPosition() + type2.getLength() - 1;
}
int indexOfEnclosingType=1;
parameterizedType.index=indexOfEnclosingType;
end=retrieveClosingAngleBracketPosition(end + 1);
length=end + 1;
parameterizedType.setSourceRange(start,end - start + 1);
startingIndex=endingIndex + 1;
Type currentType=parameterizedType;
while (startingIndex < typeArguments.length) {
SimpleName simpleName=new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(tokens[startingIndex]));
simpleName.index=startingIndex + 1;
start=(int)(positions[startingIndex] >>> 32);
end=(int)positions[startingIndex];
simpleName.setSourceRange(start,end - start + 1);
recordPendingNameScopeResolution(simpleName);
QualifiedType qualifiedType=new QualifiedType(this.ast);
qualifiedType.setQualifier(currentType);
qualifiedType.setName(simpleName);
if (this.resolveBindings) {
recordNodes(simpleName,typeReference);
recordNodes(qualifiedType,typeReference);
}
start=currentType.getStartPosition();
end=simpleName.getStartPosition() + simpleName.getLength() - 1;
qualifiedType.setSourceRange(start,end - start + 1);
indexOfEnclosingType++;
if (typeArguments[startingIndex] != null) {
qualifiedType.index=indexOfEnclosingType;
ParameterizedType parameterizedType2=new ParameterizedType(this.ast);
parameterizedType2.setType(qualifiedType);
parameterizedType2.index=indexOfEnclosingType;
if (this.resolveBindings) {
recordNodes(parameterizedType2,typeReference);
}
for (int i=0, max=typeArguments[startingIndex].length; i < max; i++) {
final Type type2=convertType(typeArguments[startingIndex][i]);
parameterizedType2.typeArguments().add(type2);
end=type2.getStartPosition() + type2.getLength() - 1;
}
end=retrieveClosingAngleBracketPosition(end + 1);
length=end + 1;
parameterizedType2.setSourceRange(start,end - start + 1);
currentType=parameterizedType2;
}
 else {
currentType=qualifiedType;
qualifiedType.index=indexOfEnclosingType;
}
startingIndex++;
}
if (this.resolveBindings) {
this.recordNodes(currentType,typeReference);
}
type=currentType;
length-=sourceStart;
}
}
}
 else if (typeReference instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) {
char[][] name=((org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)typeReference).getTypeName();
int nameLength=name.length;
long[] positions=((org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)typeReference).sourcePositions;
sourceStart=(int)(positions[0] >>> 32);
length=(int)(positions[nameLength - 1] & 0xFFFFFFFF) - sourceStart + 1;
final Name qualifiedName=this.setQualifiedNameNameAndSourceRanges(name,positions,typeReference);
final SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(qualifiedName);
type=simpleType;
type.setSourceRange(sourceStart,length);
}
 else {
TypeReference[] typeReferences=((org.eclipse.jdt.internal.compiler.ast.UnionTypeReference)typeReference).typeReferences;
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
case AST.JLS3_INTERNAL:
type=this.convertType(typeReferences[0]);
int start=typeReference.sourceStart;
int endPosition=typeReference.sourceEnd;
length=endPosition - start + 1;
type.setSourceRange(start,length);
type.setFlags(type.getFlags() | ASTNode.MALFORMED);
break;
default :
final UnionType unionType=new UnionType(this.ast);
for (int i=0, max=typeReferences.length; i < max; i++) {
unionType.types().add(this.convertType(typeReferences[i]));
}
type=unionType;
List types=unionType.types();
int size=types.size();
start=((Type)types.get(0)).getStartPosition();
Type lastType=(Type)types.get(size - 1);
endPosition=lastType.getStartPosition() + lastType.getLength();
length=endPosition - start;
type.setSourceRange(start,length);
}
}
length=typeReference.sourceEnd - sourceStart + 1;
if (dimensions != 0) {
type=this.ast.newArrayType(type,dimensions);
if (this.resolveBindings) {
completeRecord((ArrayType)type,typeReference);
}
int end=retrieveEndOfDimensionsPosition(sourceStart + length,this.compilationUnitSourceLength);
if (end != -1) {
type.setSourceRange(sourceStart,end - sourceStart + 1);
}
 else {
type.setSourceRange(sourceStart,length);
}
ArrayType subarrayType=(ArrayType)type;
int index=dimensions - 1;
while (index > 0) {
subarrayType=(ArrayType)subarrayType.getComponentType();
end=retrieveProperRightBracketPosition(index,sourceStart);
subarrayType.setSourceRange(sourceStart,end - sourceStart + 1);
index--;
}
}
}
if (this.resolveBindings) {
this.recordNodes(type,typeReference);
}
boolean sawDiamond=false;
if (typeReference instanceof ParameterizedSingleTypeReference) {
ParameterizedSingleTypeReference pstr=(ParameterizedSingleTypeReference)typeReference;
if (pstr.typeArguments == TypeReference.NO_TYPE_ARGUMENTS) {
sawDiamond=true;
}
}
 else if (typeReference instanceof ParameterizedQualifiedTypeReference) {
ParameterizedQualifiedTypeReference pqtr=(ParameterizedQualifiedTypeReference)typeReference;
for (int i=0, len=pqtr.typeArguments.length; i < len; i++) {
if (pqtr.typeArguments[i] == TypeReference.NO_TYPE_ARGUMENTS) {
sawDiamond=true;
break;
}
}
}
if (sawDiamond) {
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
case AST.JLS3_INTERNAL:
type.setFlags(type.getFlags() | ASTNode.MALFORMED);
}
}
return type;
}

Fixed version (ground truth):
public Type convertType(TypeReference typeReference){
  if (typeReference instanceof Wildcard) {
    final Wildcard wildcard=(Wildcard)typeReference;
    final WildcardType wildcardType=new WildcardType(this.ast);
    if (wildcard.bound != null) {
      final Type bound=convertType(wildcard.bound);
      wildcardType.setBound(bound,wildcard.kind == Wildcard.EXTENDS);
      int start=wildcard.sourceStart;
      wildcardType.setSourceRange(start,bound.getStartPosition() + bound.getLength() - start);
    }
 else {
      final int start=wildcard.sourceStart;
      final int end=wildcard.sourceEnd;
      wildcardType.setSourceRange(start,end - start + 1);
    }
    if (this.resolveBindings) {
      recordNodes(wildcardType,typeReference);
    }
    return wildcardType;
  }
  Type type=null;
  int sourceStart=-1;
  int length=0;
  int dimensions=typeReference.dimensions();
  if (typeReference instanceof org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) {
    char[] name=((org.eclipse.jdt.internal.compiler.ast.SingleTypeReference)typeReference).getTypeName()[0];
    sourceStart=typeReference.sourceStart;
    length=typeReference.sourceEnd - typeReference.sourceStart + 1;
    if (isPrimitiveType(name)) {
      int end=retrieveEndOfElementTypeNamePosition(sourceStart,sourceStart + length);
      if (end == -1) {
        end=sourceStart + length - 1;
      }
      final PrimitiveType primitiveType=new PrimitiveType(this.ast);
      primitiveType.setPrimitiveTypeCode(getPrimitiveTypeCode(name));
      primitiveType.setSourceRange(sourceStart,end - sourceStart + 1);
      type=primitiveType;
    }
 else     if (typeReference instanceof ParameterizedSingleTypeReference) {
      ParameterizedSingleTypeReference parameterizedSingleTypeReference=(ParameterizedSingleTypeReference)typeReference;
      final SimpleName simpleName=new SimpleName(this.ast);
      simpleName.internalSetIdentifier(new String(name));
      int end=retrieveEndOfElementTypeNamePosition(sourceStart,sourceStart + length);
      if (end == -1) {
        end=sourceStart + length - 1;
      }
      simpleName.setSourceRange(sourceStart,end - sourceStart + 1);
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
        SimpleType simpleType=new SimpleType(this.ast);
      simpleType.setName(simpleName);
    simpleType.setFlags(simpleType.getFlags() | ASTNode.MALFORMED);
  simpleType.setSourceRange(sourceStart,end - sourceStart + 1);
type=simpleType;
if (this.resolveBindings) {
this.recordNodes(simpleName,typeReference);
}
break;
default :
simpleType=new SimpleType(this.ast);
simpleType.setName(simpleName);
simpleType.setSourceRange(simpleName.getStartPosition(),simpleName.getLength());
final ParameterizedType parameterizedType=new ParameterizedType(this.ast);
parameterizedType.setType(simpleType);
type=parameterizedType;
TypeReference[] typeArguments=parameterizedSingleTypeReference.typeArguments;
if (typeArguments != null) {
Type type2=null;
for (int i=0, max=typeArguments.length; i < max; i++) {
type2=convertType(typeArguments[i]);
((ParameterizedType)type).typeArguments().add(type2);
if (type2.getStartPosition() > 0) end=type2.getStartPosition() + type2.getLength() - 1;
 else end+=type2.toString().length();
}
end=retrieveClosingAngleBracketPosition(end + 1);
type.setSourceRange(sourceStart,end - sourceStart + 1);
}
 else {
type.setSourceRange(sourceStart,end - sourceStart + 1);
}
if (this.resolveBindings) {
this.recordNodes(simpleName,typeReference);
this.recordNodes(simpleType,typeReference);
}
}
}
 else {
final SimpleName simpleName=new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(name));
int end=retrieveEndOfElementTypeNamePosition(sourceStart,sourceStart + length);
if (end == -1) {
end=sourceStart + length - 1;
}
simpleName.setSourceRange(sourceStart,end - sourceStart + 1);
final SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(simpleName);
type=simpleType;
type.setSourceRange(sourceStart,end - sourceStart + 1);
type=simpleType;
if (this.resolveBindings) {
this.recordNodes(simpleName,typeReference);
}
}
if (dimensions != 0) {
type=this.ast.newArrayType(type,dimensions);
type.setSourceRange(sourceStart,length);
ArrayType subarrayType=(ArrayType)type;
int index=dimensions - 1;
while (index > 0) {
subarrayType=(ArrayType)subarrayType.getComponentType();
int end=retrieveProperRightBracketPosition(index,sourceStart);
subarrayType.setSourceRange(sourceStart,end - sourceStart + 1);
index--;
}
if (this.resolveBindings) {
completeRecord((ArrayType)type,typeReference);
}
}
}
 else {
if (typeReference instanceof ParameterizedQualifiedTypeReference) {
ParameterizedQualifiedTypeReference parameterizedQualifiedTypeReference=(ParameterizedQualifiedTypeReference)typeReference;
char[][] tokens=parameterizedQualifiedTypeReference.tokens;
TypeReference[][] typeArguments=parameterizedQualifiedTypeReference.typeArguments;
long[] positions=parameterizedQualifiedTypeReference.sourcePositions;
sourceStart=(int)(positions[0] >>> 32);
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
{
char[][] name=((org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)typeReference).getTypeName();
int nameLength=name.length;
sourceStart=(int)(positions[0] >>> 32);
length=(int)(positions[nameLength - 1] & 0xFFFFFFFF) - sourceStart + 1;
Name qualifiedName=this.setQualifiedNameNameAndSourceRanges(name,positions,typeReference);
final SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(qualifiedName);
simpleType.setSourceRange(sourceStart,length);
type=simpleType;
}
break;
default :
if (typeArguments != null) {
int numberOfEnclosingType=0;
int startingIndex=0;
int endingIndex=0;
for (int i=0, max=typeArguments.length; i < max; i++) {
if (typeArguments[i] != null) {
numberOfEnclosingType++;
}
 else if (numberOfEnclosingType == 0) {
endingIndex++;
}
}
Name name=null;
if (endingIndex - startingIndex == 0) {
final SimpleName simpleName=new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(tokens[startingIndex]));
recordPendingNameScopeResolution(simpleName);
int start=(int)(positions[startingIndex] >>> 32);
int end=(int)positions[startingIndex];
simpleName.setSourceRange(start,end - start + 1);
simpleName.index=1;
name=simpleName;
if (this.resolveBindings) {
recordNodes(simpleName,typeReference);
}
}
 else {
name=this.setQualifiedNameNameAndSourceRanges(tokens,positions,endingIndex,typeReference);
}
SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(name);
int start=(int)(positions[startingIndex] >>> 32);
int end=(int)positions[endingIndex];
simpleType.setSourceRange(start,end - start + 1);
ParameterizedType parameterizedType=new ParameterizedType(this.ast);
parameterizedType.setType(simpleType);
if (this.resolveBindings) {
recordNodes(simpleType,typeReference);
recordNodes(parameterizedType,typeReference);
}
start=simpleType.getStartPosition();
end=start + simpleType.getLength() - 1;
for (int i=0, max=typeArguments[endingIndex].length; i < max; i++) {
final Type type2=convertType(typeArguments[endingIndex][i]);
parameterizedType.typeArguments().add(type2);
end=type2.getStartPosition() + type2.getLength() - 1;
}
int indexOfEnclosingType=1;
parameterizedType.index=indexOfEnclosingType;
end=retrieveClosingAngleBracketPosition(end + 1);
length=end + 1;
parameterizedType.setSourceRange(start,end - start + 1);
startingIndex=endingIndex + 1;
Type currentType=parameterizedType;
while (startingIndex < typeArguments.length) {
SimpleName simpleName=new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(tokens[startingIndex]));
simpleName.index=startingIndex + 1;
start=(int)(positions[startingIndex] >>> 32);
end=(int)positions[startingIndex];
simpleName.setSourceRange(start,end - start + 1);
recordPendingNameScopeResolution(simpleName);
QualifiedType qualifiedType=new QualifiedType(this.ast);
qualifiedType.setQualifier(currentType);
qualifiedType.setName(simpleName);
if (this.resolveBindings) {
recordNodes(simpleName,typeReference);
recordNodes(qualifiedType,typeReference);
}
start=currentType.getStartPosition();
end=simpleName.getStartPosition() + simpleName.getLength() - 1;
qualifiedType.setSourceRange(start,end - start + 1);
indexOfEnclosingType++;
if (typeArguments[startingIndex] != null) {
qualifiedType.index=indexOfEnclosingType;
ParameterizedType parameterizedType2=new ParameterizedType(this.ast);
parameterizedType2.setType(qualifiedType);
parameterizedType2.index=indexOfEnclosingType;
if (this.resolveBindings) {
recordNodes(parameterizedType2,typeReference);
}
for (int i=0, max=typeArguments[startingIndex].length; i < max; i++) {
final Type type2=convertType(typeArguments[startingIndex][i]);
parameterizedType2.typeArguments().add(type2);
end=type2.getStartPosition() + type2.getLength() - 1;
}
end=retrieveClosingAngleBracketPosition(end + 1);
length=end + 1;
parameterizedType2.setSourceRange(start,end - start + 1);
currentType=parameterizedType2;
}
 else {
currentType=qualifiedType;
qualifiedType.index=indexOfEnclosingType;
}
startingIndex++;
}
if (this.resolveBindings) {
this.recordNodes(currentType,typeReference);
}
type=currentType;
length-=sourceStart;
}
}
}
 else if (typeReference instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) {
char[][] name=((org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)typeReference).getTypeName();
int nameLength=name.length;
long[] positions=((org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)typeReference).sourcePositions;
sourceStart=(int)(positions[0] >>> 32);
length=(int)(positions[nameLength - 1] & 0xFFFFFFFF) - sourceStart + 1;
final Name qualifiedName=this.setQualifiedNameNameAndSourceRanges(name,positions,typeReference);
final SimpleType simpleType=new SimpleType(this.ast);
simpleType.setName(qualifiedName);
type=simpleType;
type.setSourceRange(sourceStart,length);
}
 else {
TypeReference[] typeReferences=((org.eclipse.jdt.internal.compiler.ast.UnionTypeReference)typeReference).typeReferences;
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
case AST.JLS3_INTERNAL:
type=this.convertType(typeReferences[0]);
int start=typeReference.sourceStart;
int endPosition=typeReference.sourceEnd;
length=endPosition - start + 1;
type.setSourceRange(start,length);
type.setFlags(type.getFlags() | ASTNode.MALFORMED);
break;
default :
final UnionType unionType=new UnionType(this.ast);
for (int i=0, max=typeReferences.length; i < max; i++) {
unionType.types().add(this.convertType(typeReferences[i]));
}
type=unionType;
List types=unionType.types();
int size=types.size();
start=((Type)types.get(0)).getStartPosition();
Type lastType=(Type)types.get(size - 1);
endPosition=lastType.getStartPosition() + lastType.getLength();
length=endPosition - start;
type.setSourceRange(start,length);
}
}
length=typeReference.sourceEnd - sourceStart + 1;
if (dimensions != 0) {
type=this.ast.newArrayType(type,dimensions);
if (this.resolveBindings) {
completeRecord((ArrayType)type,typeReference);
}
int end=retrieveEndOfDimensionsPosition(sourceStart + length,this.compilationUnitSourceLength);
if (end != -1) {
type.setSourceRange(sourceStart,end - sourceStart + 1);
}
 else {
type.setSourceRange(sourceStart,length);
}
ArrayType subarrayType=(ArrayType)type;
int index=dimensions - 1;
while (index > 0) {
subarrayType=(ArrayType)subarrayType.getComponentType();
end=retrieveProperRightBracketPosition(index,sourceStart);
subarrayType.setSourceRange(sourceStart,end - sourceStart + 1);
index--;
}
}
}
if (this.resolveBindings) {
this.recordNodes(type,typeReference);
}
boolean sawDiamond=false;
if (typeReference instanceof ParameterizedSingleTypeReference) {
ParameterizedSingleTypeReference pstr=(ParameterizedSingleTypeReference)typeReference;
if (pstr.typeArguments == TypeReference.NO_TYPE_ARGUMENTS) {
sawDiamond=true;
}
}
 else if (typeReference instanceof ParameterizedQualifiedTypeReference) {
ParameterizedQualifiedTypeReference pqtr=(ParameterizedQualifiedTypeReference)typeReference;
for (int i=0, len=pqtr.typeArguments.length; i < len; i++) {
if (pqtr.typeArguments[i] == TypeReference.NO_TYPE_ARGUMENTS) {
sawDiamond=true;
break;
}
}
}
if (sawDiamond) {
switch (this.ast.apiLevel) {
case AST.JLS2_INTERNAL:
case AST.JLS3_INTERNAL:
type.setFlags(type.getFlags() | ASTNode.MALFORMED);
}
}
return type;
}