Skip to content

Commit

Permalink
Add sourceFolder into LocationInfo, so that CodeTracker does not need to
Browse files Browse the repository at this point in the history
compute it
The source folder is computed for each compilation unit and passed to all nested program elements
  • Loading branch information
tsantalis committed Oct 30, 2024
1 parent 2575fe0 commit af3a29f
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 338 deletions.
8 changes: 7 additions & 1 deletion src/main/java/gr/uom/java/xmi/LocationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import gr.uom.java.xmi.diff.CodeRange;

public class LocationInfo {
private String sourceFolder;
private String filePath;
private int startOffset;
private int endOffset;
Expand All @@ -19,7 +20,8 @@ public class LocationInfo {
private int endColumn;
private CodeElementType codeElementType;

public LocationInfo(CompilationUnit cu, String filePath, ASTNode node, CodeElementType codeElementType) {
public LocationInfo(CompilationUnit cu, String sourceFolder, String filePath, ASTNode node, CodeElementType codeElementType) {
this.sourceFolder = sourceFolder;
this.filePath = filePath;
this.codeElementType = codeElementType;
this.startOffset = node.getStartPosition();
Expand Down Expand Up @@ -48,6 +50,10 @@ public LocationInfo(CompilationUnit cu, String filePath, ASTNode node, CodeEleme
}
}

public String getSourceFolder() {
return sourceFolder;
}

public String getFilePath() {
return filePath;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gr/uom/java/xmi/UMLAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ public class UMLAnnotation implements Serializable, LocationInfoProvider {
private AbstractExpression value;
private Map<String, AbstractExpression> memberValuePairs = new LinkedHashMap<>();

public UMLAnnotation(CompilationUnit cu, String filePath, Annotation annotation, String javaFileContent) {
public UMLAnnotation(CompilationUnit cu, String sourceFolder, String filePath, Annotation annotation, String javaFileContent) {
this.typeName = annotation.getTypeName().getFullyQualifiedName();
this.locationInfo = new LocationInfo(cu, filePath, annotation, CodeElementType.ANNOTATION);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, annotation, CodeElementType.ANNOTATION);
if(annotation instanceof SingleMemberAnnotation) {
SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation)annotation;
this.value = new AbstractExpression(cu, filePath, singleMemberAnnotation.getValue(), CodeElementType.SINGLE_MEMBER_ANNOTATION_VALUE, null, javaFileContent);
this.value = new AbstractExpression(cu, sourceFolder, filePath, singleMemberAnnotation.getValue(), CodeElementType.SINGLE_MEMBER_ANNOTATION_VALUE, null, javaFileContent);
}
else if(annotation instanceof NormalAnnotation) {
NormalAnnotation normalAnnotation = (NormalAnnotation)annotation;
List<MemberValuePair> pairs = normalAnnotation.values();
for(MemberValuePair pair : pairs) {
AbstractExpression value = new AbstractExpression(cu, filePath, pair.getValue(), CodeElementType.NORMAL_ANNOTATION_MEMBER_VALUE_PAIR, null, javaFileContent);
AbstractExpression value = new AbstractExpression(cu, sourceFolder, filePath, pair.getValue(), CodeElementType.NORMAL_ANNOTATION_MEMBER_VALUE_PAIR, null, javaFileContent);
memberValuePairs.put(pair.getName().getIdentifier(), value);
}
}
Expand Down
284 changes: 148 additions & 136 deletions src/main/java/gr/uom/java/xmi/UMLModelASTReader.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/java/gr/uom/java/xmi/UMLModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class UMLModifier implements Serializable, LocationInfoProvider {
private String keyword;
private LocationInfo locationInfo;

public UMLModifier(CompilationUnit cu, String filePath, Modifier modifier) {
public UMLModifier(CompilationUnit cu, String sourceFolder, String filePath, Modifier modifier) {
this.keyword = modifier.getKeyword().toString();
this.locationInfo = new LocationInfo(cu, filePath, modifier, CodeElementType.MODIFIER);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, modifier, CodeElementType.MODIFIER);
}

public String getKeyword() {
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/gr/uom/java/xmi/UMLType.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,31 +250,31 @@ else if(typeArguments.charAt(i) == '<') {
return openingTags == closingTags;
}

public static UMLType extractTypeObject(CompilationUnit cu, String filePath, Type type, int extraDimensions, String javaFileContent) {
UMLType umlType = extractTypeObject(cu, filePath, type, javaFileContent);
umlType.locationInfo = new LocationInfo(cu, filePath, type, CodeElementType.TYPE);
public static UMLType extractTypeObject(CompilationUnit cu, String sourceFolder, String filePath, Type type, int extraDimensions, String javaFileContent) {
UMLType umlType = extractTypeObject(cu, sourceFolder, filePath, type, javaFileContent);
umlType.locationInfo = new LocationInfo(cu, sourceFolder, filePath, type, CodeElementType.TYPE);
umlType.arrayDimension += extraDimensions;
return umlType;
}

private static UMLType extractTypeObject(CompilationUnit cu, String filePath, Type type, String javaFileContent) {
private static UMLType extractTypeObject(CompilationUnit cu, String sourceFolder, String filePath, Type type, String javaFileContent) {
if(type.isPrimitiveType() || type.isSimpleType()) {
LeafType leafType = extractTypeObject(stringify(type));
AnnotatableType annotatableType = (AnnotatableType)type;
List<Annotation> annotations = annotatableType.annotations();
for(Annotation annotation : annotations) {
leafType.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent));
leafType.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent));
}
return leafType;
}
else if(type instanceof QualifiedType) {
QualifiedType qualified = (QualifiedType)type;
UMLType leftType = extractTypeObject(cu, filePath, qualified.getQualifier(), javaFileContent);
UMLType leftType = extractTypeObject(cu, sourceFolder, filePath, qualified.getQualifier(), javaFileContent);
LeafType rightType = extractTypeObject(qualified.getName().getFullyQualifiedName());
AnnotatableType annotatableType = (AnnotatableType)qualified;
List<Annotation> annotations = annotatableType.annotations();
for(Annotation annotation : annotations) {
rightType.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent));
rightType.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent));
}
return new CompositeType(leftType, rightType);
}
Expand All @@ -285,15 +285,15 @@ else if(type instanceof NameQualifiedType) {
AnnotatableType annotatableType = (AnnotatableType)nameQualified;
List<Annotation> annotations = annotatableType.annotations();
for(Annotation annotation : annotations) {
rightType.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent));
rightType.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent));
}
return new CompositeType(leftType, rightType);
}
else if(type instanceof WildcardType) {
WildcardType wildcard = (WildcardType)type;
gr.uom.java.xmi.WildcardType myWildcardType = null;
if(wildcard.getBound() != null) {
UMLType bound = extractTypeObject(cu, filePath, wildcard.getBound(), javaFileContent);
UMLType bound = extractTypeObject(cu, sourceFolder, filePath, wildcard.getBound(), javaFileContent);
myWildcardType = new gr.uom.java.xmi.WildcardType(bound, wildcard.isUpperBound());
}
else {
Expand All @@ -302,30 +302,30 @@ else if(type instanceof WildcardType) {
AnnotatableType annotatableType = (AnnotatableType)wildcard;
List<Annotation> annotations = annotatableType.annotations();
for(Annotation annotation : annotations) {
myWildcardType.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent));
myWildcardType.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent));
}
return myWildcardType;
}
else if(type instanceof ArrayType) {
ArrayType array = (ArrayType)type;
UMLType arrayType = extractTypeObject(cu, filePath, array.getElementType(), javaFileContent);
UMLType arrayType = extractTypeObject(cu, sourceFolder, filePath, array.getElementType(), javaFileContent);
for(Object dim : array.dimensions()) {
Dimension dimension = (Dimension)dim;
List<Annotation> annotations = dimension.annotations();
for(Annotation annotation : annotations) {
arrayType.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent));
arrayType.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent));
}
}
arrayType.arrayDimension = array.getDimensions();
return arrayType;
}
else if(type instanceof ParameterizedType) {
ParameterizedType parameterized = (ParameterizedType)type;
UMLType container = extractTypeObject(cu, filePath, parameterized.getType(), javaFileContent);
UMLType container = extractTypeObject(cu, sourceFolder, filePath, parameterized.getType(), javaFileContent);
container.parameterized = true;
List<Type> typeArguments = parameterized.typeArguments();
for(Type argument : typeArguments) {
container.typeArguments.add(extractTypeObject(cu, filePath, argument, javaFileContent));
container.typeArguments.add(extractTypeObject(cu, sourceFolder, filePath, argument, javaFileContent));
}
return container;
}
Expand All @@ -334,7 +334,7 @@ else if(type instanceof UnionType) {
List<Type> types = union.types();
List<UMLType> umlTypes = new ArrayList<UMLType>();
for(Type unionType : types) {
umlTypes.add(extractTypeObject(cu, filePath, unionType, javaFileContent));
umlTypes.add(extractTypeObject(cu, sourceFolder, filePath, unionType, javaFileContent));
}
return new ListCompositeType(umlTypes, Kind.UNION);
}
Expand All @@ -343,7 +343,7 @@ else if(type instanceof IntersectionType) {
List<Type> types = intersection.types();
List<UMLType> umlTypes = new ArrayList<UMLType>();
for(Type unionType : types) {
umlTypes.add(extractTypeObject(cu, filePath, unionType, javaFileContent));
umlTypes.add(extractTypeObject(cu, sourceFolder, filePath, unionType, javaFileContent));
}
return new ListCompositeType(umlTypes, Kind.INTERSECTION);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public abstract class AbstractCall extends LeafExpression {
private static final List<String> logNames = List.of("trace", "debug", "info", "warn", "error", "fatal", "log");
private static final List<String> logGuardNames = List.of("isDebugEnabled", "isEnabled", "isErrorEnabled", "isFatalEnabled", "isInfoEnabled", "isTraceEnabled", "isWarnEnabled");

public AbstractCall(CompilationUnit cu, String filePath, ASTNode expression, CodeElementType codeElementType, VariableDeclarationContainer container) {
super(cu, filePath, expression, codeElementType, container);
public AbstractCall(CompilationUnit cu, String sourceFolder, String filePath, ASTNode expression, CodeElementType codeElementType, VariableDeclarationContainer container) {
super(cu, sourceFolder, filePath, expression, codeElementType, container);
}

protected AbstractCall() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class AbstractExpression extends AbstractCodeFragment {
private List<TernaryOperatorExpression> ternaryOperatorExpressions;
private List<LambdaExpressionObject> lambdas;

public AbstractExpression(CompilationUnit cu, String filePath, Expression expression, CodeElementType codeElementType, VariableDeclarationContainer container, String javaFileContent) {
this.locationInfo = new LocationInfo(cu, filePath, expression, codeElementType);
Visitor visitor = new Visitor(cu, filePath, container, javaFileContent);
public AbstractExpression(CompilationUnit cu, String sourceFolder, String filePath, Expression expression, CodeElementType codeElementType, VariableDeclarationContainer container, String javaFileContent) {
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, expression, codeElementType);
Visitor visitor = new Visitor(cu, sourceFolder, filePath, container, javaFileContent);
expression.accept(visitor);
this.variables = visitor.getVariables();
this.types = visitor.getTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class AnonymousClassDeclarationObject implements LocationInfoProvider {
private List<TernaryOperatorExpression> ternaryOperatorExpressions = new ArrayList<TernaryOperatorExpression>();
private List<LambdaExpressionObject> lambdas = new ArrayList<LambdaExpressionObject>();

public AnonymousClassDeclarationObject(CompilationUnit cu, String filePath, AnonymousClassDeclaration anonymous) {
this.locationInfo = new LocationInfo(cu, filePath, anonymous, CodeElementType.ANONYMOUS_CLASS_DECLARATION);
public AnonymousClassDeclarationObject(CompilationUnit cu, String sourceFolder, String filePath, AnonymousClassDeclaration anonymous) {
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, anonymous, CodeElementType.ANONYMOUS_CLASS_DECLARATION);
this.astNode = anonymous;
this.astNodeString = stringify(anonymous);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class CompositeStatementObject extends AbstractStatement {
private Optional<TryStatementObject> tryContainer;
private LocationInfo locationInfo;

public CompositeStatementObject(CompilationUnit cu, String filePath, ASTNode statement, int depth, CodeElementType codeElementType) {
public CompositeStatementObject(CompilationUnit cu, String sourceFolder, String filePath, ASTNode statement, int depth, CodeElementType codeElementType) {
super();
this.setDepth(depth);
this.locationInfo = new LocationInfo(cu, filePath, statement, codeElementType);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, statement, codeElementType);
this.statementList = new ArrayList<AbstractStatement>();
this.expressionList = new ArrayList<AbstractExpression>();
this.variableDeclarations = new ArrayList<VariableDeclaration>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ public class LambdaExpressionObject implements VariableDeclarationContainer, Loc
private VariableDeclarationContainer owner;
private String asString;

public LambdaExpressionObject(CompilationUnit cu, String filePath, LambdaExpression lambda, VariableDeclarationContainer owner, String javaFileContent) {
public LambdaExpressionObject(CompilationUnit cu, String sourceFolder, String filePath, LambdaExpression lambda, VariableDeclarationContainer owner, String javaFileContent) {
this.owner = owner;
this.asString = lambda.toString();
this.locationInfo = new LocationInfo(cu, filePath, lambda, CodeElementType.LAMBDA_EXPRESSION);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, lambda, CodeElementType.LAMBDA_EXPRESSION);
this.hasParentheses = lambda.hasParentheses();
List<org.eclipse.jdt.core.dom.VariableDeclaration> params = lambda.parameters();
for(org.eclipse.jdt.core.dom.VariableDeclaration param : params) {
VariableDeclaration parameter = null;
if(param instanceof VariableDeclarationFragment) {
parameter = new VariableDeclaration(cu, filePath, (VariableDeclarationFragment)param, this, javaFileContent);
parameter = new VariableDeclaration(cu, sourceFolder, filePath, (VariableDeclarationFragment)param, this, javaFileContent);
}
else if(param instanceof SingleVariableDeclaration) {
parameter = new VariableDeclaration(cu, filePath, (SingleVariableDeclaration)param, this, javaFileContent);
parameter = new VariableDeclaration(cu, sourceFolder, filePath, (SingleVariableDeclaration)param, this, javaFileContent);
Type parameterType = ((SingleVariableDeclaration)param).getType();
String parameterName = param.getName().getFullyQualifiedName();
UMLType type = UMLType.extractTypeObject(cu, filePath, parameterType, param.getExtraDimensions(), javaFileContent);
UMLType type = UMLType.extractTypeObject(cu, sourceFolder, filePath, parameterType, param.getExtraDimensions(), javaFileContent);
if(((SingleVariableDeclaration)param).isVarargs()) {
type.setVarargs();
}
Expand All @@ -71,24 +71,24 @@ else if(param instanceof SingleVariableDeclaration) {
this.parameters.add(parameter);
}
if(lambda.getBody() instanceof Block) {
this.body = new OperationBody(cu, filePath, (Block)lambda.getBody(), this, new ArrayList<>(), javaFileContent);
this.body = new OperationBody(cu, sourceFolder, filePath, (Block)lambda.getBody(), this, new ArrayList<>(), javaFileContent);
}
else if(lambda.getBody() instanceof Expression) {
this.expression = new AbstractExpression(cu, filePath, (Expression)lambda.getBody(), CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
this.expression = new AbstractExpression(cu, sourceFolder, filePath, (Expression)lambda.getBody(), CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
this.expression.setLambdaOwner(this);
for(VariableDeclaration parameter : parameters) {
parameter.addStatementInScope(expression);
}
}
}

public LambdaExpressionObject(CompilationUnit cu, String filePath, Statement switchCaseBody, VariableDeclarationContainer owner, String javaFileContent) {
public LambdaExpressionObject(CompilationUnit cu, String sourceFolder, String filePath, Statement switchCaseBody, VariableDeclarationContainer owner, String javaFileContent) {
this.owner = owner;
this.hasParentheses = false;
this.asString = switchCaseBody.toString();
this.locationInfo = new LocationInfo(cu, filePath, switchCaseBody, CodeElementType.LAMBDA_EXPRESSION);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, switchCaseBody, CodeElementType.LAMBDA_EXPRESSION);
if(switchCaseBody instanceof Block) {
this.body = new OperationBody(cu, filePath, (Block)switchCaseBody, this, new ArrayList<>(), javaFileContent);
this.body = new OperationBody(cu, sourceFolder, filePath, (Block)switchCaseBody, this, new ArrayList<>(), javaFileContent);
}
else {
//TODO find a way to support switch-case with a single statement
Expand All @@ -97,25 +97,25 @@ public LambdaExpressionObject(CompilationUnit cu, String filePath, Statement swi
}
}

public LambdaExpressionObject(CompilationUnit cu, String filePath, ExpressionMethodReference reference, VariableDeclarationContainer owner, String javaFileContent) {
public LambdaExpressionObject(CompilationUnit cu, String sourceFolder, String filePath, ExpressionMethodReference reference, VariableDeclarationContainer owner, String javaFileContent) {
this.owner = owner;
this.asString = reference.toString();
this.locationInfo = new LocationInfo(cu, filePath, reference, CodeElementType.LAMBDA_EXPRESSION);
this.expression = new AbstractExpression(cu, filePath, reference, CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, reference, CodeElementType.LAMBDA_EXPRESSION);
this.expression = new AbstractExpression(cu, sourceFolder, filePath, reference, CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
}

public LambdaExpressionObject(CompilationUnit cu, String filePath, SuperMethodReference reference, VariableDeclarationContainer owner, String javaFileContent) {
public LambdaExpressionObject(CompilationUnit cu, String sourceFolder, String filePath, SuperMethodReference reference, VariableDeclarationContainer owner, String javaFileContent) {
this.owner = owner;
this.asString = reference.toString();
this.locationInfo = new LocationInfo(cu, filePath, reference, CodeElementType.LAMBDA_EXPRESSION);
this.expression = new AbstractExpression(cu, filePath, reference, CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, reference, CodeElementType.LAMBDA_EXPRESSION);
this.expression = new AbstractExpression(cu, sourceFolder, filePath, reference, CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
}

public LambdaExpressionObject(CompilationUnit cu, String filePath, TypeMethodReference reference, VariableDeclarationContainer owner, String javaFileContent) {
public LambdaExpressionObject(CompilationUnit cu, String sourceFolder, String filePath, TypeMethodReference reference, VariableDeclarationContainer owner, String javaFileContent) {
this.owner = owner;
this.asString = reference.toString();
this.locationInfo = new LocationInfo(cu, filePath, reference, CodeElementType.LAMBDA_EXPRESSION);
this.expression = new AbstractExpression(cu, filePath, reference, CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, reference, CodeElementType.LAMBDA_EXPRESSION);
this.expression = new AbstractExpression(cu, sourceFolder, filePath, reference, CodeElementType.LAMBDA_EXPRESSION_BODY, this, javaFileContent);
}

public VariableDeclarationContainer getOwner() {
Expand Down
Loading

0 comments on commit af3a29f

Please sign in to comment.