|
|
|
@ -289,8 +289,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
|
|
|
|
|
private final T fSourcePosition; |
|
|
|
|
|
|
|
|
|
private final T fNamePos; |
|
|
|
|
|
|
|
|
|
public ClassEntity(ITypeBinding jdtType, String name, Collection<CAstQualifier> quals, Collection<CAstEntity> entities, |
|
|
|
|
T pos) { |
|
|
|
|
T pos, T namePos) { |
|
|
|
|
fNamePos = namePos; |
|
|
|
|
fName = name; |
|
|
|
|
fQuals = quals; |
|
|
|
|
fEntities = entities; |
|
|
|
@ -396,6 +399,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
return fTypeDict.new JdtJavaType(fJdtType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Position getNamePosition() { |
|
|
|
|
return fNamePos; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isInterface(AbstractTypeDeclaration decl) { |
|
|
|
@ -405,7 +413,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
|
|
|
|
|
private CAstEntity visitTypeDecl(AbstractTypeDeclaration n, WalkContext context) { |
|
|
|
|
return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(), n.getName().getIdentifier(), n.getModifiers(), |
|
|
|
|
isInterface(n), n instanceof AnnotationTypeDeclaration, context); |
|
|
|
|
isInterface(n), n instanceof AnnotationTypeDeclaration, context, makePosition(n.getName())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -416,10 +424,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
* @param typeBinding |
|
|
|
|
* @param name Used in creating default constructor, and passed into new ClassEntity() |
|
|
|
|
* @param context |
|
|
|
|
* @param namePos |
|
|
|
|
*/ |
|
|
|
|
private CAstEntity createClassDeclaration(ASTNode n, List<BodyDeclaration> bodyDecls, |
|
|
|
|
List<EnumConstantDeclaration> enumConstants, ITypeBinding typeBinding, String name, int modifiers, |
|
|
|
|
boolean isInterface, boolean isAnnotation, WalkContext context) { |
|
|
|
|
boolean isInterface, boolean isAnnotation, WalkContext context, T namePos) { |
|
|
|
|
final List<CAstEntity> memberEntities = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
// find and collect all initializers (type Initializer) and field initializers (type VariableDeclarationFragment).
|
|
|
|
@ -465,7 +474,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
IVariableBinding fieldBinding = fieldFrag.resolveBinding(); |
|
|
|
|
memberEntities.add(new FieldEntity(fieldFrag.getName().getIdentifier(), fieldBinding.getType(), quals, |
|
|
|
|
makePosition(fieldFrag.getStartPosition(), fieldFrag.getStartPosition() + fieldFrag.getLength()), |
|
|
|
|
handleAnnotations(fieldBinding))); |
|
|
|
|
handleAnnotations(fieldBinding), makePosition(fieldFrag.getName()))); |
|
|
|
|
} |
|
|
|
|
} else if (decl instanceof Initializer) { |
|
|
|
|
// Initializers are inserted into constructors when making constructors.
|
|
|
|
@ -526,12 +535,12 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
|
|
|
|
|
Collection<CAstQualifier> quals = JDT2CAstUtils.mapModifiersToQualifiers(modifiers, isInterface, isAnnotation); |
|
|
|
|
|
|
|
|
|
return new ClassEntity(typeBinding, name, quals, memberEntities, makePosition(n)); |
|
|
|
|
return new ClassEntity(typeBinding, name, quals, memberEntities, makePosition(n), namePos); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private CAstEntity visit(AnonymousClassDeclaration n, WalkContext context) { |
|
|
|
|
return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(), |
|
|
|
|
JDT2CAstUtils.anonTypeName(n.resolveBinding()), 0 /* no modifiers */, false, false, context); |
|
|
|
|
JDT2CAstUtils.anonTypeName(n.resolveBinding()), 0 /* no modifiers */, false, false, context, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private CAstNode visit(TypeDeclarationStatement n, WalkContext context) { |
|
|
|
@ -1106,6 +1115,15 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
SingleVariableDeclaration p = (SingleVariableDeclaration) fDecl.parameters().get(arg); |
|
|
|
|
return makePosition(p); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Position getNamePosition() { |
|
|
|
|
if (fDecl == null) { |
|
|
|
|
return null; |
|
|
|
|
} else { |
|
|
|
|
return makePosition(fDecl); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ////////////////////////////////////
|
|
|
|
@ -1158,13 +1176,16 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
|
|
|
|
|
private final T position; |
|
|
|
|
|
|
|
|
|
private final T namePos; |
|
|
|
|
|
|
|
|
|
private final Set<CAstAnnotation> annotations; |
|
|
|
|
|
|
|
|
|
private FieldEntity(String name, ITypeBinding type, Collection<CAstQualifier> quals, T position, Set<CAstAnnotation> annotations) { |
|
|
|
|
private FieldEntity(String name, ITypeBinding type, Collection<CAstQualifier> quals, T position, Set<CAstAnnotation> annotations, T namePos) { |
|
|
|
|
super(); |
|
|
|
|
this.type = type; |
|
|
|
|
this.quals = quals; |
|
|
|
|
this.name = name; |
|
|
|
|
this.namePos = namePos; |
|
|
|
|
this.position = position; |
|
|
|
|
this.annotations = annotations; |
|
|
|
|
} |
|
|
|
@ -1261,6 +1282,13 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Position getPosition(int arg) { |
|
|
|
|
return namePos; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Position getNamePosition() { |
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -3045,6 +3073,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
public Position getPosition(int arg) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Position getNamePosition() { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// /////////////////////////////
|
|
|
|
@ -3340,7 +3373,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
*/ |
|
|
|
|
private CAstEntity visit(EnumConstantDeclaration decl, WalkContext context) { |
|
|
|
|
return new FieldEntity(decl.getName().getIdentifier(), decl.resolveVariable().getType(), enumQuals, makePosition(decl |
|
|
|
|
.getStartPosition(), decl.getStartPosition() + decl.getLength()), null); |
|
|
|
|
.getStartPosition(), decl.getStartPosition() + decl.getLength()), null, makePosition(decl.getName())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -3489,10 +3522,9 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private CAstEntity visit(EnumDeclaration n, WalkContext context) { |
|
|
|
|
|
|
|
|
|
// JDT contains correct type info / class / subclass info for the enum
|
|
|
|
|
return createClassDeclaration(n, n.bodyDeclarations(), n.enumConstants(), n.resolveBinding(), n.getName().getIdentifier(), n |
|
|
|
|
.resolveBinding().getModifiers(), false, false, context); |
|
|
|
|
.resolveBinding().getModifiers(), false, false, context, makePosition(n.getName())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|