From af3a29ff1afccf452641350ed95be27669c823fa Mon Sep 17 00:00:00 2001 From: tsantalis Date: Wed, 30 Oct 2024 10:33:00 -0400 Subject: [PATCH] Add sourceFolder into LocationInfo, so that CodeTracker does not need to compute it The source folder is computed for each compilation unit and passed to all nested program elements --- .../java/gr/uom/java/xmi/LocationInfo.java | 8 +- .../java/gr/uom/java/xmi/UMLAnnotation.java | 8 +- .../gr/uom/java/xmi/UMLModelASTReader.java | 284 +++++++++--------- .../java/gr/uom/java/xmi/UMLModifier.java | 4 +- src/main/java/gr/uom/java/xmi/UMLType.java | 32 +- .../java/xmi/decomposition/AbstractCall.java | 4 +- .../xmi/decomposition/AbstractExpression.java | 6 +- .../AnonymousClassDeclarationObject.java | 4 +- .../CompositeStatementObject.java | 4 +- .../decomposition/LambdaExpressionObject.java | 38 +-- .../xmi/decomposition/LeafExpression.java | 4 +- .../xmi/decomposition/MethodReference.java | 14 +- .../xmi/decomposition/ObjectCreation.java | 12 +- .../java/xmi/decomposition/OperationBody.java | 114 +++---- .../decomposition/OperationInvocation.java | 16 +- .../xmi/decomposition/StatementObject.java | 6 +- .../TernaryOperatorExpression.java | 12 +- .../xmi/decomposition/TryStatementObject.java | 4 +- .../decomposition/VariableDeclaration.java | 36 +-- .../uom/java/xmi/decomposition/Visitor.java | 84 +++--- .../test/TestParameterizeTestRefactoring.java | 2 +- 21 files changed, 358 insertions(+), 338 deletions(-) diff --git a/src/main/java/gr/uom/java/xmi/LocationInfo.java b/src/main/java/gr/uom/java/xmi/LocationInfo.java index 271bc0b22c..a5364d24b9 100644 --- a/src/main/java/gr/uom/java/xmi/LocationInfo.java +++ b/src/main/java/gr/uom/java/xmi/LocationInfo.java @@ -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; @@ -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(); @@ -48,6 +50,10 @@ public LocationInfo(CompilationUnit cu, String filePath, ASTNode node, CodeEleme } } + public String getSourceFolder() { + return sourceFolder; + } + public String getFilePath() { return filePath; } diff --git a/src/main/java/gr/uom/java/xmi/UMLAnnotation.java b/src/main/java/gr/uom/java/xmi/UMLAnnotation.java index 2af55bf7a9..1bf5f2e511 100644 --- a/src/main/java/gr/uom/java/xmi/UMLAnnotation.java +++ b/src/main/java/gr/uom/java/xmi/UMLAnnotation.java @@ -21,18 +21,18 @@ public class UMLAnnotation implements Serializable, LocationInfoProvider { private AbstractExpression value; private Map 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 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); } } diff --git a/src/main/java/gr/uom/java/xmi/UMLModelASTReader.java b/src/main/java/gr/uom/java/xmi/UMLModelASTReader.java index 9bec4f98e3..990fa8d074 100644 --- a/src/main/java/gr/uom/java/xmi/UMLModelASTReader.java +++ b/src/main/java/gr/uom/java/xmi/UMLModelASTReader.java @@ -185,27 +185,39 @@ public UMLModel getUmlModel() { } protected void processCompilationUnit(String sourceFilePath, CompilationUnit compilationUnit, String javaFileContent) { - List comments = extractInternalComments(compilationUnit, sourceFilePath, javaFileContent); - this.umlModel.getCommentMap().put(sourceFilePath, comments); PackageDeclaration packageDeclaration = compilationUnit.getPackage(); String packageName = null; UMLJavadoc packageDoc = null; UMLPackage umlPackage = null; + String sourceFolder = ""; if(packageDeclaration != null) { packageName = packageDeclaration.getName().getFullyQualifiedName(); - packageDoc = generateJavadoc(compilationUnit, sourceFilePath, packageDeclaration.getJavadoc(), javaFileContent); - LocationInfo packageLocationInfo = generateLocationInfo(compilationUnit, sourceFilePath, packageDeclaration, CodeElementType.PACKAGE_DECLARATION); + int index = sourceFilePath.indexOf(packageName.replace('.', '/')); + if(index != -1) { + sourceFolder = sourceFilePath.substring(0, index); + } + packageDoc = generateJavadoc(compilationUnit, sourceFolder, sourceFilePath, packageDeclaration.getJavadoc(), javaFileContent); + LocationInfo packageLocationInfo = generateLocationInfo(compilationUnit, sourceFolder, sourceFilePath, packageDeclaration, CodeElementType.PACKAGE_DECLARATION); umlPackage = new UMLPackage(packageName, packageLocationInfo); } else { packageName = ""; + if(compilationUnit.types().size() > 0) { + AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) compilationUnit.types().get(0); + int index = sourceFilePath.indexOf(typeDeclaration.getName().getFullyQualifiedName()); + if(index != -1) { + sourceFolder = sourceFilePath.substring(0, index); + } + } } + List comments = extractInternalComments(compilationUnit, sourceFolder, sourceFilePath, javaFileContent); + this.umlModel.getCommentMap().put(sourceFilePath, comments); List imports = compilationUnit.imports(); List importedTypes = new ArrayList(); for(ImportDeclaration importDeclaration : imports) { String elementName = importDeclaration.getName().getFullyQualifiedName(); - LocationInfo locationInfo = generateLocationInfo(compilationUnit, sourceFilePath, importDeclaration, CodeElementType.IMPORT_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(compilationUnit, sourceFolder, sourceFilePath, importDeclaration, CodeElementType.IMPORT_DECLARATION); UMLImport imported = new UMLImport(elementName, importDeclaration.isOnDemand(), importDeclaration.isStatic(), locationInfo); importedTypes.add(imported); } @@ -213,36 +225,36 @@ protected void processCompilationUnit(String sourceFilePath, CompilationUnit com for(AbstractTypeDeclaration abstractTypeDeclaration : topLevelTypeDeclarations) { if(abstractTypeDeclaration instanceof TypeDeclaration) { TypeDeclaration topLevelTypeDeclaration = (TypeDeclaration)abstractTypeDeclaration; - processTypeDeclaration(compilationUnit, topLevelTypeDeclaration, umlPackage, packageName, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); + processTypeDeclaration(compilationUnit, topLevelTypeDeclaration, umlPackage, packageName, sourceFolder, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); } else if(abstractTypeDeclaration instanceof EnumDeclaration) { EnumDeclaration enumDeclaration = (EnumDeclaration)abstractTypeDeclaration; - processEnumDeclaration(compilationUnit, enumDeclaration, umlPackage, packageName, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); + processEnumDeclaration(compilationUnit, enumDeclaration, umlPackage, packageName, sourceFolder, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); } else if(abstractTypeDeclaration instanceof AnnotationTypeDeclaration) { AnnotationTypeDeclaration annotationDeclaration = (AnnotationTypeDeclaration)abstractTypeDeclaration; - processAnnotationTypeDeclaration(compilationUnit, annotationDeclaration, umlPackage, packageName, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); + processAnnotationTypeDeclaration(compilationUnit, annotationDeclaration, umlPackage, packageName, sourceFolder, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); } else if(abstractTypeDeclaration instanceof RecordDeclaration) { RecordDeclaration recordDeclaration = (RecordDeclaration)abstractTypeDeclaration; - processRecordDeclaration(compilationUnit, recordDeclaration, umlPackage, packageName, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); + processRecordDeclaration(compilationUnit, recordDeclaration, umlPackage, packageName, sourceFolder, sourceFilePath, importedTypes, packageDoc, comments, javaFileContent); } } } - private List extractInternalComments(CompilationUnit cu, String sourceFile, String javaFileContent) { + private List extractInternalComments(CompilationUnit cu, String sourceFolder, String sourceFile, String javaFileContent) { List astComments = cu.getCommentList(); List comments = new ArrayList(); for(Comment comment : astComments) { LocationInfo locationInfo = null; if(comment.isLineComment()) { - locationInfo = generateLocationInfo(cu, sourceFile, comment, CodeElementType.LINE_COMMENT); + locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, comment, CodeElementType.LINE_COMMENT); } else if(comment.isBlockComment()) { - locationInfo = generateLocationInfo(cu, sourceFile, comment, CodeElementType.BLOCK_COMMENT); + locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, comment, CodeElementType.BLOCK_COMMENT); } else if(comment.isDocComment() && comment.getParent() == null) { - locationInfo = generateLocationInfo(cu, sourceFile, comment, CodeElementType.BLOCK_COMMENT); + locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, comment, CodeElementType.BLOCK_COMMENT); } if(locationInfo != null) { int start = comment.getStartPosition(); @@ -251,7 +263,7 @@ else if(comment.isDocComment() && comment.getParent() == null) { UMLComment umlComment = new UMLComment(text, locationInfo); if(comment.isDocComment() && comment.getParent() == null) { Javadoc doc = (Javadoc)comment; - umlComment.setJavaDoc(generateJavadoc(cu, sourceFile, doc, javaFileContent)); + umlComment.setJavaDoc(generateJavadoc(cu, sourceFolder, sourceFile, doc, javaFileContent)); } comments.add(umlComment); } @@ -274,15 +286,15 @@ private void distributeComments(List compilationUnitComments, Locati compilationUnitComments.removeAll(codeElementComments); } - private UMLJavadoc generateJavadoc(CompilationUnit cu, BodyDeclaration bodyDeclaration, String sourceFile, String javaFileContent) { + private UMLJavadoc generateJavadoc(CompilationUnit cu, BodyDeclaration bodyDeclaration, String sourceFolder, String sourceFile, String javaFileContent) { Javadoc javaDoc = bodyDeclaration.getJavadoc(); - return generateJavadoc(cu, sourceFile, javaDoc, javaFileContent); + return generateJavadoc(cu, sourceFolder, sourceFile, javaDoc, javaFileContent); } - private UMLJavadoc generateJavadoc(CompilationUnit cu, String sourceFile, Javadoc javaDoc, String javaFileContent) { + private UMLJavadoc generateJavadoc(CompilationUnit cu, String sourceFolder, String sourceFile, Javadoc javaDoc, String javaFileContent) { UMLJavadoc doc = null; if(javaDoc != null) { - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, javaDoc, CodeElementType.JAVADOC); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, javaDoc, CodeElementType.JAVADOC); int start = javaDoc.getStartPosition(); int end = start + javaDoc.getLength(); String text = javaFileContent.substring(start, end); @@ -296,23 +308,23 @@ private UMLJavadoc generateJavadoc(CompilationUnit cu, String sourceFile, Javado doc = new UMLJavadoc(trimLeadWhiteSpace, locationInfo); List tags = javaDoc.tags(); for(TagElement parentTag : tags) { - LocationInfo tagLocationInfo = generateLocationInfo(cu, sourceFile, parentTag, CodeElementType.TAG_ELEMENT); + LocationInfo tagLocationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, parentTag, CodeElementType.TAG_ELEMENT); UMLTagElement parentTagElement = new UMLTagElement(parentTag.getTagName(), tagLocationInfo); - processTagFragments(cu, sourceFile, parentTag, parentTagElement); + processTagFragments(cu, sourceFolder, sourceFile, parentTag, parentTagElement); doc.addTag(parentTagElement); } } return doc; } - private void processTagFragments(CompilationUnit cu, String sourceFile, TagElement parentTag, UMLTagElement parentTagElement) { + private void processTagFragments(CompilationUnit cu, String sourceFolder, String sourceFile, TagElement parentTag, UMLTagElement parentTagElement) { List fragments = parentTag.fragments(); for(IDocElement docElement : fragments) { - LocationInfo docElementLocationInfo = generateLocationInfo(cu, sourceFile, (ASTNode)docElement, CodeElementType.DOC_ELEMENT); + LocationInfo docElementLocationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, (ASTNode)docElement, CodeElementType.DOC_ELEMENT); if(docElement instanceof TagElement) { TagElement nestedTag = (TagElement)docElement; UMLTagElement nestedTagElement = new UMLTagElement(nestedTag.getTagName(), docElementLocationInfo); - processTagFragments(cu, sourceFile, nestedTag, nestedTagElement); + processTagFragments(cu, sourceFolder, sourceFile, nestedTag, nestedTagElement); parentTagElement.addNestedTag(nestedTagElement); } else if(docElement instanceof JavaDocRegion) { @@ -344,14 +356,14 @@ private boolean generatedCode(UMLJavadoc javadoc) { return false; } - private void processRecordDeclaration(CompilationUnit cu, RecordDeclaration recordDeclaration, UMLPackage umlPackage, String packageName, String sourceFile, + private void processRecordDeclaration(CompilationUnit cu, RecordDeclaration recordDeclaration, UMLPackage umlPackage, String packageName, String sourceFolder, String sourceFile, List importedTypes, UMLJavadoc packageDoc, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, recordDeclaration, sourceFile, javaFileContent); + UMLJavadoc javadoc = generateJavadoc(cu, recordDeclaration, sourceFolder, sourceFile, javaFileContent); if(generatedCode(javadoc)) { return; } String recordName = recordDeclaration.getName().getFullyQualifiedName(); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, recordDeclaration, CodeElementType.RECORD_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, recordDeclaration, CodeElementType.RECORD_DECLARATION); UMLClass umlClass = new UMLClass(packageName, recordName, locationInfo, recordDeclaration.isPackageMemberTypeDeclaration(), importedTypes); umlClass.setJavadoc(javadoc); if(recordDeclaration.isPackageMemberTypeDeclaration()) { @@ -366,23 +378,23 @@ private void processRecordDeclaration(CompilationUnit cu, RecordDeclaration reco } umlClass.setRecord(true); - int startSignatureOffset = processModifiers(cu, sourceFile, recordDeclaration, umlClass, javaFileContent); + int startSignatureOffset = processModifiers(cu, sourceFolder, sourceFile, recordDeclaration, umlClass, javaFileContent); if(startSignatureOffset == -1) { startSignatureOffset = recordDeclaration.getName().getStartPosition(); } List typeParameters = recordDeclaration.typeParameters(); for(TypeParameter typeParameter : typeParameters) { UMLTypeParameter umlTypeParameter = new UMLTypeParameter(typeParameter.getName().getFullyQualifiedName(), - generateLocationInfo(cu, sourceFile, typeParameter, CodeElementType.TYPE_PARAMETER)); + generateLocationInfo(cu, sourceFolder, sourceFile, typeParameter, CodeElementType.TYPE_PARAMETER)); List typeBounds = typeParameter.typeBounds(); for(Type type : typeBounds) { - umlTypeParameter.addTypeBound(UMLType.extractTypeObject(cu, sourceFile, type, 0, javaFileContent)); + umlTypeParameter.addTypeBound(UMLType.extractTypeObject(cu, sourceFolder, sourceFile, type, 0, javaFileContent)); } List typeParameterExtendedModifiers = typeParameter.modifiers(); for(IExtendedModifier extendedModifier : typeParameterExtendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - umlTypeParameter.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation, javaFileContent)); + umlTypeParameter.addAnnotation(new UMLAnnotation(cu, sourceFolder, sourceFile, annotation, javaFileContent)); } } umlClass.addTypeParameter(umlTypeParameter); @@ -390,7 +402,7 @@ private void processRecordDeclaration(CompilationUnit cu, RecordDeclaration reco List superInterfaceTypes = recordDeclaration.superInterfaceTypes(); for(Type interfaceType : superInterfaceTypes) { - UMLType umlType = UMLType.extractTypeObject(cu, sourceFile, interfaceType, 0, javaFileContent); + UMLType umlType = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, interfaceType, 0, javaFileContent); UMLRealization umlRealization = new UMLRealization(umlClass, umlType.getClassType()); umlClass.addImplementedInterface(umlType); getUmlModel().addRealization(umlRealization); @@ -400,31 +412,31 @@ private void processRecordDeclaration(CompilationUnit cu, RecordDeclaration reco for(SingleVariableDeclaration recordComponent : recordComponents) { Type parameterType = recordComponent.getType(); String parameterName = recordComponent.getName().getFullyQualifiedName(); - UMLType type = UMLType.extractTypeObject(cu, sourceFile, parameterType, recordComponent.getExtraDimensions(), javaFileContent); + UMLType type = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, parameterType, recordComponent.getExtraDimensions(), javaFileContent); if(recordComponent.isVarargs()) { type.setVarargs(); } - LocationInfo recordComponentLocationInfo = new LocationInfo(cu, sourceFile, recordComponent, CodeElementType.RECORD_COMPONENT); + LocationInfo recordComponentLocationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, recordComponent, CodeElementType.RECORD_COMPONENT); UMLRecordComponent umlRecordComponent = new UMLRecordComponent(parameterName, type, recordComponentLocationInfo); - VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFile, recordComponent, umlRecordComponent, recordComponent.isVarargs(), javaFileContent); + VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFolder, sourceFile, recordComponent, umlRecordComponent, recordComponent.isVarargs(), javaFileContent); variableDeclaration.setAttribute(true); umlRecordComponent.setVariableDeclaration(variableDeclaration); umlRecordComponent.setClassName(umlClass.getName()); umlClass.addAttribute(umlRecordComponent); } - Map map = processBodyDeclarations(cu, recordDeclaration, umlPackage, packageName, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); + Map map = processBodyDeclarations(cu, recordDeclaration, umlPackage, packageName, sourceFolder, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); - processAnonymousClassDeclarations(cu, recordDeclaration, umlPackage, packageName, sourceFile, recordName, importedTypes, packageDoc, comments, umlClass, javaFileContent); + processAnonymousClassDeclarations(cu, recordDeclaration, umlPackage, packageName, sourceFolder, sourceFile, recordName, importedTypes, packageDoc, comments, umlClass, javaFileContent); for(BodyDeclaration declaration : map.keySet()) { if(declaration instanceof MethodDeclaration) { UMLOperation operation = (UMLOperation) map.get(declaration); - processMethodBody(cu, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); + processMethodBody(cu, sourceFolder, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); } else if(declaration instanceof Initializer) { UMLInitializer initializer = (UMLInitializer) map.get(declaration); - processInitializerBody(cu, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); + processInitializerBody(cu, sourceFolder, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); } } @@ -444,14 +456,14 @@ else if(declaration instanceof Initializer) { distributeComments(comments, locationInfo, umlClass.getComments()); } - private void processAnnotationTypeDeclaration(CompilationUnit cu, AnnotationTypeDeclaration annotationDeclaration, UMLPackage umlPackage, String packageName, String sourceFile, + private void processAnnotationTypeDeclaration(CompilationUnit cu, AnnotationTypeDeclaration annotationDeclaration, UMLPackage umlPackage, String packageName, String sourceFolder, String sourceFile, List importedTypes, UMLJavadoc packageDoc, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, annotationDeclaration, sourceFile, javaFileContent); + UMLJavadoc javadoc = generateJavadoc(cu, annotationDeclaration, sourceFolder, sourceFile, javaFileContent); if(generatedCode(javadoc)) { return; } String className = annotationDeclaration.getName().getFullyQualifiedName(); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, annotationDeclaration, CodeElementType.ANNOTATION_TYPE_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, annotationDeclaration, CodeElementType.ANNOTATION_TYPE_DECLARATION); UMLClass umlClass = new UMLClass(packageName, className, locationInfo, annotationDeclaration.isPackageMemberTypeDeclaration(), importedTypes); umlClass.setJavadoc(javadoc); if(annotationDeclaration.isPackageMemberTypeDeclaration()) { @@ -466,22 +478,22 @@ private void processAnnotationTypeDeclaration(CompilationUnit cu, AnnotationType } umlClass.setAnnotation(true); - int startSignatureOffset = processModifiers(cu, sourceFile, annotationDeclaration, umlClass, javaFileContent); + int startSignatureOffset = processModifiers(cu, sourceFolder, sourceFile, annotationDeclaration, umlClass, javaFileContent); if(startSignatureOffset == -1) { startSignatureOffset = annotationDeclaration.getName().getStartPosition(); } - Map map = processBodyDeclarations(cu, annotationDeclaration, umlPackage, packageName, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); + Map map = processBodyDeclarations(cu, annotationDeclaration, umlPackage, packageName, sourceFolder, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); - processAnonymousClassDeclarations(cu, annotationDeclaration, umlPackage, packageName, sourceFile, className, importedTypes, packageDoc, comments, umlClass, javaFileContent); + processAnonymousClassDeclarations(cu, annotationDeclaration, umlPackage, packageName, sourceFolder, sourceFile, className, importedTypes, packageDoc, comments, umlClass, javaFileContent); for(BodyDeclaration declaration : map.keySet()) { if(declaration instanceof MethodDeclaration) { UMLOperation operation = (UMLOperation) map.get(declaration); - processMethodBody(cu, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); + processMethodBody(cu, sourceFolder, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); } else if(declaration instanceof Initializer) { UMLInitializer initializer = (UMLInitializer) map.get(declaration); - processInitializerBody(cu, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); + processInitializerBody(cu, sourceFolder, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); } } @@ -501,14 +513,14 @@ else if(declaration instanceof Initializer) { distributeComments(comments, locationInfo, umlClass.getComments()); } - private void processEnumDeclaration(CompilationUnit cu, EnumDeclaration enumDeclaration, UMLPackage umlPackage, String packageName, String sourceFile, + private void processEnumDeclaration(CompilationUnit cu, EnumDeclaration enumDeclaration, UMLPackage umlPackage, String packageName, String sourceFolder, String sourceFile, List importedTypes, UMLJavadoc packageDoc, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, enumDeclaration, sourceFile, javaFileContent); + UMLJavadoc javadoc = generateJavadoc(cu, enumDeclaration, sourceFolder, sourceFile, javaFileContent); if(generatedCode(javadoc)) { return; } String className = enumDeclaration.getName().getFullyQualifiedName(); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, enumDeclaration, CodeElementType.ENUM_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, enumDeclaration, CodeElementType.ENUM_DECLARATION); UMLClass umlClass = new UMLClass(packageName, className, locationInfo, enumDeclaration.isPackageMemberTypeDeclaration(), importedTypes); umlClass.setJavadoc(javadoc); if(enumDeclaration.isPackageMemberTypeDeclaration()) { @@ -525,7 +537,7 @@ private void processEnumDeclaration(CompilationUnit cu, EnumDeclaration enumDecl List superInterfaceTypes = enumDeclaration.superInterfaceTypes(); for(Type interfaceType : superInterfaceTypes) { - UMLType umlType = UMLType.extractTypeObject(cu, sourceFile, interfaceType, 0, javaFileContent); + UMLType umlType = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, interfaceType, 0, javaFileContent); UMLRealization umlRealization = new UMLRealization(umlClass, umlType.getClassType()); umlClass.addImplementedInterface(umlType); getUmlModel().addRealization(umlRealization); @@ -533,25 +545,25 @@ private void processEnumDeclaration(CompilationUnit cu, EnumDeclaration enumDecl List enumConstantDeclarations = enumDeclaration.enumConstants(); for(EnumConstantDeclaration enumConstantDeclaration : enumConstantDeclarations) { - processEnumConstantDeclaration(cu, enumConstantDeclaration, sourceFile, umlClass, comments, javaFileContent); + processEnumConstantDeclaration(cu, enumConstantDeclaration, sourceFolder, sourceFile, umlClass, comments, javaFileContent); } - int startSignatureOffset = processModifiers(cu, sourceFile, enumDeclaration, umlClass, javaFileContent); + int startSignatureOffset = processModifiers(cu, sourceFolder, sourceFile, enumDeclaration, umlClass, javaFileContent); if(startSignatureOffset == -1) { startSignatureOffset = enumDeclaration.getName().getStartPosition(); } - Map map = processBodyDeclarations(cu, enumDeclaration, umlPackage, packageName, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); + Map map = processBodyDeclarations(cu, enumDeclaration, umlPackage, packageName, sourceFolder, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); - processAnonymousClassDeclarations(cu, enumDeclaration, umlPackage, packageName, sourceFile, className, importedTypes, packageDoc, comments, umlClass, javaFileContent); + processAnonymousClassDeclarations(cu, enumDeclaration, umlPackage, packageName, sourceFolder, sourceFile, className, importedTypes, packageDoc, comments, umlClass, javaFileContent); for(BodyDeclaration declaration : map.keySet()) { if(declaration instanceof MethodDeclaration) { UMLOperation operation = (UMLOperation) map.get(declaration); - processMethodBody(cu, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); + processMethodBody(cu, sourceFolder, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); } else if(declaration instanceof Initializer) { UMLInitializer initializer = (UMLInitializer) map.get(declaration); - processInitializerBody(cu, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); + processInitializerBody(cu, sourceFolder, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); } } @@ -572,14 +584,14 @@ else if(declaration instanceof Initializer) { } private Map processBodyDeclarations(CompilationUnit cu, AbstractTypeDeclaration abstractTypeDeclaration, UMLPackage umlPackage, String packageName, - String sourceFile, List importedTypes, UMLClass umlClass, UMLJavadoc packageDoc, List comments, String javaFileContent) { + String sourceFolder, String sourceFile, List importedTypes, UMLClass umlClass, UMLJavadoc packageDoc, List comments, String javaFileContent) { Map map = new LinkedHashMap<>(); List bodyDeclarations = abstractTypeDeclaration.bodyDeclarations(); boolean interfaceOrAnnotation = umlClass.isInterface() || umlClass.isAnnotation(); for(BodyDeclaration bodyDeclaration : bodyDeclarations) { if(bodyDeclaration instanceof FieldDeclaration) { FieldDeclaration fieldDeclaration = (FieldDeclaration)bodyDeclaration; - List attributes = processFieldDeclaration(cu, fieldDeclaration, interfaceOrAnnotation, sourceFile, comments, javaFileContent); + List attributes = processFieldDeclaration(cu, fieldDeclaration, interfaceOrAnnotation, sourceFolder, sourceFile, comments, javaFileContent); for(UMLAttribute attribute : attributes) { attribute.setClassName(umlClass.getName()); umlClass.addAttribute(attribute); @@ -587,48 +599,48 @@ private Map processBodyDeclaratio } else if(bodyDeclaration instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration)bodyDeclaration; - UMLOperation operation = processMethodDeclaration(cu, methodDeclaration, packageName, interfaceOrAnnotation, sourceFile, comments, javaFileContent); + UMLOperation operation = processMethodDeclaration(cu, methodDeclaration, packageName, interfaceOrAnnotation, sourceFolder, sourceFile, comments, javaFileContent); operation.setClassName(umlClass.getName()); umlClass.addOperation(operation); map.put(methodDeclaration, operation); } else if(bodyDeclaration instanceof AnnotationTypeMemberDeclaration) { AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration = (AnnotationTypeMemberDeclaration)bodyDeclaration; - UMLOperation operation = processAnnotationTypeMember(cu, annotationTypeMemberDeclaration, packageName, interfaceOrAnnotation, sourceFile, comments, javaFileContent); + UMLOperation operation = processAnnotationTypeMember(cu, annotationTypeMemberDeclaration, packageName, interfaceOrAnnotation, sourceFolder, sourceFile, comments, javaFileContent); operation.setClassName(umlClass.getName()); umlClass.addOperation(operation); map.put(annotationTypeMemberDeclaration, operation); } else if(bodyDeclaration instanceof Initializer) { Initializer initializer = (Initializer)bodyDeclaration; - UMLInitializer umlInitializer = processInitializer(cu, initializer, packageName, false, sourceFile, comments, javaFileContent); + UMLInitializer umlInitializer = processInitializer(cu, initializer, packageName, false, sourceFolder, sourceFile, comments, javaFileContent); umlInitializer.setClassName(umlClass.getName()); umlClass.addInitializer(umlInitializer); map.put(initializer, umlInitializer); } else if(bodyDeclaration instanceof TypeDeclaration) { TypeDeclaration typeDeclaration = (TypeDeclaration)bodyDeclaration; - processTypeDeclaration(cu, typeDeclaration, umlPackage, umlClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processTypeDeclaration(cu, typeDeclaration, umlPackage, umlClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } else if(bodyDeclaration instanceof EnumDeclaration) { EnumDeclaration enumDeclaration = (EnumDeclaration)bodyDeclaration; - processEnumDeclaration(cu, enumDeclaration, umlPackage, umlClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processEnumDeclaration(cu, enumDeclaration, umlPackage, umlClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } else if(bodyDeclaration instanceof AnnotationTypeDeclaration) { AnnotationTypeDeclaration annotationDeclaration = (AnnotationTypeDeclaration)bodyDeclaration; - processAnnotationTypeDeclaration(cu, annotationDeclaration, umlPackage, umlClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processAnnotationTypeDeclaration(cu, annotationDeclaration, umlPackage, umlClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } else if(bodyDeclaration instanceof RecordDeclaration) { RecordDeclaration recordDeclaration = (RecordDeclaration)bodyDeclaration; - processRecordDeclaration(cu, recordDeclaration, umlPackage, umlClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processRecordDeclaration(cu, recordDeclaration, umlPackage, umlClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } } return map; } - private void processTypeDeclaration(CompilationUnit cu, TypeDeclaration typeDeclaration, UMLPackage umlPackage, String packageName, String sourceFile, + private void processTypeDeclaration(CompilationUnit cu, TypeDeclaration typeDeclaration, UMLPackage umlPackage, String packageName, String sourceFolder, String sourceFile, List importedTypes, UMLJavadoc packageDoc, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, typeDeclaration, sourceFile, javaFileContent); + UMLJavadoc javadoc = generateJavadoc(cu, typeDeclaration, sourceFolder, sourceFile, javaFileContent); if(generatedCode(javadoc)) { return; } @@ -636,7 +648,7 @@ private void processTypeDeclaration(CompilationUnit cu, TypeDeclaration typeDecl if(className.equals("$")) { return; } - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, typeDeclaration, CodeElementType.TYPE_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, typeDeclaration, CodeElementType.TYPE_DECLARATION); UMLClass umlClass = new UMLClass(packageName, className, locationInfo, typeDeclaration.isPackageMemberTypeDeclaration(), importedTypes); umlClass.setJavadoc(javadoc); if(typeDeclaration.isPackageMemberTypeDeclaration()) { @@ -653,23 +665,23 @@ private void processTypeDeclaration(CompilationUnit cu, TypeDeclaration typeDecl umlClass.setInterface(true); } - int startSignatureOffset = processModifiers(cu, sourceFile, typeDeclaration, umlClass, javaFileContent); + int startSignatureOffset = processModifiers(cu, sourceFolder, sourceFile, typeDeclaration, umlClass, javaFileContent); if(startSignatureOffset == -1) { startSignatureOffset = typeDeclaration.getName().getStartPosition(); } List typeParameters = typeDeclaration.typeParameters(); for(TypeParameter typeParameter : typeParameters) { UMLTypeParameter umlTypeParameter = new UMLTypeParameter(typeParameter.getName().getFullyQualifiedName(), - generateLocationInfo(cu, sourceFile, typeParameter, CodeElementType.TYPE_PARAMETER)); + generateLocationInfo(cu, sourceFolder, sourceFile, typeParameter, CodeElementType.TYPE_PARAMETER)); List typeBounds = typeParameter.typeBounds(); for(Type type : typeBounds) { - umlTypeParameter.addTypeBound(UMLType.extractTypeObject(cu, sourceFile, type, 0, javaFileContent)); + umlTypeParameter.addTypeBound(UMLType.extractTypeObject(cu, sourceFolder, sourceFile, type, 0, javaFileContent)); } List typeParameterExtendedModifiers = typeParameter.modifiers(); for(IExtendedModifier extendedModifier : typeParameterExtendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - umlTypeParameter.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation, javaFileContent)); + umlTypeParameter.addAnnotation(new UMLAnnotation(cu, sourceFolder, sourceFile, annotation, javaFileContent)); } } umlClass.addTypeParameter(umlTypeParameter); @@ -677,7 +689,7 @@ private void processTypeDeclaration(CompilationUnit cu, TypeDeclaration typeDecl Type superclassType = typeDeclaration.getSuperclassType(); if(superclassType != null) { - UMLType umlType = UMLType.extractTypeObject(cu, sourceFile, superclassType, 0, javaFileContent); + UMLType umlType = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, superclassType, 0, javaFileContent); UMLGeneralization umlGeneralization = new UMLGeneralization(umlClass, umlType.getClassType()); umlClass.setSuperclass(umlType); getUmlModel().addGeneralization(umlGeneralization); @@ -685,24 +697,24 @@ private void processTypeDeclaration(CompilationUnit cu, TypeDeclaration typeDecl List superInterfaceTypes = typeDeclaration.superInterfaceTypes(); for(Type interfaceType : superInterfaceTypes) { - UMLType umlType = UMLType.extractTypeObject(cu, sourceFile, interfaceType, 0, javaFileContent); + UMLType umlType = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, interfaceType, 0, javaFileContent); UMLRealization umlRealization = new UMLRealization(umlClass, umlType.getClassType()); umlClass.addImplementedInterface(umlType); getUmlModel().addRealization(umlRealization); } - Map map = processBodyDeclarations(cu, typeDeclaration, umlPackage, packageName, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); + Map map = processBodyDeclarations(cu, typeDeclaration, umlPackage, packageName, sourceFolder, sourceFile, importedTypes, umlClass, packageDoc, comments, javaFileContent); - processAnonymousClassDeclarations(cu, typeDeclaration, umlPackage, packageName, sourceFile, className, importedTypes, packageDoc, comments, umlClass, javaFileContent); + processAnonymousClassDeclarations(cu, typeDeclaration, umlPackage, packageName, sourceFolder, sourceFile, className, importedTypes, packageDoc, comments, umlClass, javaFileContent); for(BodyDeclaration declaration : map.keySet()) { if(declaration instanceof MethodDeclaration) { UMLOperation operation = (UMLOperation) map.get(declaration); - processMethodBody(cu, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); + processMethodBody(cu, sourceFolder, sourceFile, (MethodDeclaration) declaration, operation, umlClass.getAttributes(), javaFileContent); } else if(declaration instanceof Initializer) { UMLInitializer initializer = (UMLInitializer) map.get(declaration); - processInitializerBody(cu, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); + processInitializerBody(cu, sourceFolder, sourceFile, (Initializer) declaration, initializer, umlClass.getAttributes(), javaFileContent); } } @@ -728,7 +740,7 @@ else if(declaration instanceof Initializer) { } private void processAnonymousClassDeclarations(CompilationUnit cu, AbstractTypeDeclaration typeDeclaration, - UMLPackage umlPackage, String packageName, String sourceFile, String className, + UMLPackage umlPackage, String packageName, String sourceFolder, String sourceFile, String className, List importedTypes, UMLJavadoc packageDoc, List allComments, UMLClass umlClass, String javaFileContent) { AnonymousClassDeclarationVisitor visitor = new AnonymousClassDeclarationVisitor(); typeDeclaration.accept(visitor); @@ -742,19 +754,19 @@ private void processAnonymousClassDeclarations(CompilationUnit cu, AbstractTypeD AbstractTypeDeclaration localTypeDeclaration = statement.getDeclaration(); if(localTypeDeclaration instanceof TypeDeclaration) { TypeDeclaration typeDeclaration2 = (TypeDeclaration)localTypeDeclaration; - processTypeDeclaration(cu, typeDeclaration2, umlPackage, fullName, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); + processTypeDeclaration(cu, typeDeclaration2, umlPackage, fullName, sourceFolder, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); } else if(localTypeDeclaration instanceof EnumDeclaration) { EnumDeclaration enumDeclaration = (EnumDeclaration)localTypeDeclaration; - processEnumDeclaration(cu, enumDeclaration, umlPackage, fullName, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); + processEnumDeclaration(cu, enumDeclaration, umlPackage, fullName, sourceFolder, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); } else if(localTypeDeclaration instanceof AnnotationTypeDeclaration) { AnnotationTypeDeclaration annotationDeclaration = (AnnotationTypeDeclaration)localTypeDeclaration; - processAnnotationTypeDeclaration(cu, annotationDeclaration, umlPackage, fullName, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); + processAnnotationTypeDeclaration(cu, annotationDeclaration, umlPackage, fullName, sourceFolder, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); } else if(localTypeDeclaration instanceof RecordDeclaration) { RecordDeclaration recordDeclaration = (RecordDeclaration)localTypeDeclaration; - processRecordDeclaration(cu, recordDeclaration, umlPackage, fullName, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); + processRecordDeclaration(cu, recordDeclaration, umlPackage, fullName, sourceFolder, sourceFile, importedTypes, packageDoc, allComments, javaFileContent); } } @@ -821,7 +833,7 @@ else if(localTypeDeclaration instanceof RecordDeclaration) { if(matchingOperation != null || matchingAttribute != null || matchingInitializer != null || matchingEnumConstant != null) { String anonymousBinaryName = getAnonymousBinaryName(node); String anonymousCodePath = getAnonymousCodePath(node); - UMLAnonymousClass anonymousClass = processAnonymousClassDeclaration(cu, anonymous, umlPackage, packageName + "." + className, anonymousBinaryName, anonymousCodePath, sourceFile, packageDoc, comments, umlClass.getImportedTypes(), javaFileContent); + UMLAnonymousClass anonymousClass = processAnonymousClassDeclaration(cu, anonymous, umlPackage, packageName + "." + className, anonymousBinaryName, anonymousCodePath, sourceFolder, sourceFile, packageDoc, comments, umlClass.getImportedTypes(), javaFileContent); umlClass.addAnonymousClass(anonymousClass); if(matchingOperation != null) { matchingOperation.addAnonymousClass(anonymousClass); @@ -879,13 +891,13 @@ else if(localTypeDeclaration instanceof RecordDeclaration) { if(bodyDeclaration instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration)bodyDeclaration; UMLOperation operation = anonymousClass.getOperations().get(i); - processMethodBody(cu, sourceFile, methodDeclaration, operation, umlClass.getAttributes(), javaFileContent); + processMethodBody(cu, sourceFolder, sourceFile, methodDeclaration, operation, umlClass.getAttributes(), javaFileContent); i++; } else if(bodyDeclaration instanceof Initializer) { Initializer initializer = (Initializer)bodyDeclaration; UMLInitializer umlInitializer = anonymousClass.getInitializers().get(j); - processInitializerBody(cu, sourceFile, initializer, umlInitializer, umlClass.getAttributes(), javaFileContent); + processInitializerBody(cu, sourceFolder, sourceFile, initializer, umlInitializer, umlClass.getAttributes(), javaFileContent); j++; } } @@ -894,10 +906,10 @@ else if(bodyDeclaration instanceof Initializer) { } } - private void processMethodBody(CompilationUnit cu, String sourceFile, MethodDeclaration methodDeclaration, UMLOperation operation, List attributes, String javaFileContent) { + private void processMethodBody(CompilationUnit cu, String sourceFolder, String sourceFile, MethodDeclaration methodDeclaration, UMLOperation operation, List attributes, String javaFileContent) { Block block = methodDeclaration.getBody(); if(block != null) { - OperationBody body = new OperationBody(cu, sourceFile, block, operation, attributes, javaFileContent); + OperationBody body = new OperationBody(cu, sourceFolder, sourceFile, block, operation, attributes, javaFileContent); operation.setBody(body); } else { @@ -905,10 +917,10 @@ private void processMethodBody(CompilationUnit cu, String sourceFile, MethodDecl } } - private void processInitializerBody(CompilationUnit cu, String sourceFile, Initializer initializer, UMLInitializer umlInitializer, List attributes, String javaFileContent) { + private void processInitializerBody(CompilationUnit cu, String sourceFolder, String sourceFile, Initializer initializer, UMLInitializer umlInitializer, List attributes, String javaFileContent) { Block block = initializer.getBody(); if(block != null) { - OperationBody body = new OperationBody(cu, sourceFile, block, umlInitializer, attributes, javaFileContent); + OperationBody body = new OperationBody(cu, sourceFolder, sourceFile, block, umlInitializer, attributes, javaFileContent); umlInitializer.setBody(body); } else { @@ -916,7 +928,7 @@ private void processInitializerBody(CompilationUnit cu, String sourceFile, Initi } } - private int processModifiers(CompilationUnit cu, String sourceFile, AbstractTypeDeclaration typeDeclaration, UMLClass umlClass, String javaFileContent) { + private int processModifiers(CompilationUnit cu, String sourceFolder, String sourceFile, AbstractTypeDeclaration typeDeclaration, UMLClass umlClass, String javaFileContent) { int startSignatureOffset = -1; int modifiers = typeDeclaration.getModifiers(); if((modifiers & Modifier.ABSTRACT) != 0) @@ -939,11 +951,11 @@ else if((modifiers & Modifier.PRIVATE) != 0) for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - umlClass.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation, javaFileContent)); + umlClass.addAnnotation(new UMLAnnotation(cu, sourceFolder, sourceFile, annotation, javaFileContent)); } else if(extendedModifier.isModifier()) { Modifier modifier = (Modifier)extendedModifier; - umlClass.addModifier(new UMLModifier(cu, sourceFile, modifier)); + umlClass.addModifier(new UMLModifier(cu, sourceFolder, sourceFile, modifier)); if(startSignatureOffset == -1) { startSignatureOffset = modifier.getStartPosition(); } @@ -952,8 +964,8 @@ else if(extendedModifier.isModifier()) { return startSignatureOffset; } - private UMLInitializer processInitializer(CompilationUnit cu, Initializer initializer, String packageName, boolean isInterfaceMethod, String sourceFile, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, initializer, sourceFile, javaFileContent); + private UMLInitializer processInitializer(CompilationUnit cu, Initializer initializer, String packageName, boolean isInterfaceMethod, String sourceFolder, String sourceFile, List comments, String javaFileContent) { + UMLJavadoc javadoc = generateJavadoc(cu, initializer, sourceFolder, sourceFile, javaFileContent); String name = ""; if(initializer.getParent() instanceof AnonymousClassDeclaration && initializer.getParent().getParent() instanceof ClassInstanceCreation) { ClassInstanceCreation creation = (ClassInstanceCreation)initializer.getParent().getParent(); @@ -963,7 +975,7 @@ else if(initializer.getParent() instanceof AbstractTypeDeclaration) { AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration)initializer.getParent(); name = typeDeclaration.getName().getIdentifier(); } - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, initializer, CodeElementType.INITIALIZER); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, initializer, CodeElementType.INITIALIZER); UMLInitializer umlInitializer = new UMLInitializer(name, locationInfo); umlInitializer.setJavadoc(javadoc); distributeComments(comments, locationInfo, umlInitializer.getComments()); @@ -975,10 +987,10 @@ else if(initializer.getParent() instanceof AbstractTypeDeclaration) { return umlInitializer; } - private UMLOperation processAnnotationTypeMember(CompilationUnit cu, AnnotationTypeMemberDeclaration annotationTypeMemberDeclatation, String packageName, boolean isInterfaceMethod, String sourceFile, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, annotationTypeMemberDeclatation, sourceFile, javaFileContent); + private UMLOperation processAnnotationTypeMember(CompilationUnit cu, AnnotationTypeMemberDeclaration annotationTypeMemberDeclatation, String packageName, boolean isInterfaceMethod, String sourceFolder, String sourceFile, List comments, String javaFileContent) { + UMLJavadoc javadoc = generateJavadoc(cu, annotationTypeMemberDeclatation, sourceFolder, sourceFile, javaFileContent); String methodName = annotationTypeMemberDeclatation.getName().getFullyQualifiedName(); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, annotationTypeMemberDeclatation, CodeElementType.ANNOTATION_TYPE_MEMBER_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, annotationTypeMemberDeclatation, CodeElementType.ANNOTATION_TYPE_MEMBER_DECLARATION); UMLOperation umlOperation = new UMLOperation(methodName, locationInfo); umlOperation.setJavadoc(javadoc); @@ -1018,32 +1030,32 @@ else if(isInterfaceMethod) for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - umlOperation.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation, javaFileContent)); + umlOperation.addAnnotation(new UMLAnnotation(cu, sourceFolder, sourceFile, annotation, javaFileContent)); } else if(extendedModifier.isModifier()) { Modifier modifier = (Modifier)extendedModifier; - umlOperation.addModifier(new UMLModifier(cu, sourceFile, modifier)); + umlOperation.addModifier(new UMLModifier(cu, sourceFolder, sourceFile, modifier)); } } Type returnType = annotationTypeMemberDeclatation.getType(); if(returnType != null) { - UMLType type = UMLType.extractTypeObject(cu, sourceFile, returnType, 0, javaFileContent); + UMLType type = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, returnType, 0, javaFileContent); UMLParameter returnParameter = new UMLParameter("return", type, "return", false); umlOperation.addParameter(returnParameter); } if(annotationTypeMemberDeclatation.getDefault() != null) { - AbstractExpression defaultExpression = new AbstractExpression(cu, sourceFile, annotationTypeMemberDeclatation.getDefault(), CodeElementType.ANNOTATION_TYPE_MEMBER_DEFAULT_EXPRESSION, umlOperation, javaFileContent); + AbstractExpression defaultExpression = new AbstractExpression(cu, sourceFolder, sourceFile, annotationTypeMemberDeclatation.getDefault(), CodeElementType.ANNOTATION_TYPE_MEMBER_DEFAULT_EXPRESSION, umlOperation, javaFileContent); umlOperation.setDefaultExpression(defaultExpression); } return umlOperation; } - private UMLOperation processMethodDeclaration(CompilationUnit cu, MethodDeclaration methodDeclaration, String packageName, boolean isInterfaceMethod, String sourceFile, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, methodDeclaration, sourceFile, javaFileContent); + private UMLOperation processMethodDeclaration(CompilationUnit cu, MethodDeclaration methodDeclaration, String packageName, boolean isInterfaceMethod, String sourceFolder, String sourceFile, List comments, String javaFileContent) { + UMLJavadoc javadoc = generateJavadoc(cu, methodDeclaration, sourceFolder, sourceFile, javaFileContent); String methodName = methodDeclaration.getName().getFullyQualifiedName(); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, methodDeclaration, CodeElementType.METHOD_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, methodDeclaration, CodeElementType.METHOD_DECLARATION); UMLOperation umlOperation = new UMLOperation(methodName, locationInfo); umlOperation.setJavadoc(javadoc); distributeComments(comments, locationInfo, umlOperation.getComments()); @@ -1086,11 +1098,11 @@ else if(isInterfaceMethod) for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - umlOperation.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation, javaFileContent)); + umlOperation.addAnnotation(new UMLAnnotation(cu, sourceFolder, sourceFile, annotation, javaFileContent)); } else if(extendedModifier.isModifier()) { Modifier modifier = (Modifier)extendedModifier; - umlOperation.addModifier(new UMLModifier(cu, sourceFile, modifier)); + umlOperation.addModifier(new UMLModifier(cu, sourceFolder, sourceFile, modifier)); if(startSignatureOffset == -1) { startSignatureOffset = modifier.getStartPosition(); } @@ -1103,16 +1115,16 @@ else if(extendedModifier.isModifier()) { } for(TypeParameter typeParameter : typeParameters) { UMLTypeParameter umlTypeParameter = new UMLTypeParameter(typeParameter.getName().getFullyQualifiedName(), - generateLocationInfo(cu, sourceFile, typeParameter, CodeElementType.TYPE_PARAMETER)); + generateLocationInfo(cu, sourceFolder, sourceFile, typeParameter, CodeElementType.TYPE_PARAMETER)); List typeBounds = typeParameter.typeBounds(); for(Type type : typeBounds) { - umlTypeParameter.addTypeBound(UMLType.extractTypeObject(cu, sourceFile, type, 0, javaFileContent)); + umlTypeParameter.addTypeBound(UMLType.extractTypeObject(cu, sourceFolder, sourceFile, type, 0, javaFileContent)); } List typeParameterExtendedModifiers = typeParameter.modifiers(); for(IExtendedModifier extendedModifier : typeParameterExtendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - umlTypeParameter.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation, javaFileContent)); + umlTypeParameter.addAnnotation(new UMLAnnotation(cu, sourceFolder, sourceFile, annotation, javaFileContent)); } } umlOperation.addTypeParameter(umlTypeParameter); @@ -1123,7 +1135,7 @@ else if(extendedModifier.isModifier()) { if(startSignatureOffset == -1) { startSignatureOffset = returnType.getStartPosition(); } - UMLType type = UMLType.extractTypeObject(cu, sourceFile, returnType, methodDeclaration.getExtraDimensions(), javaFileContent); + UMLType type = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, returnType, methodDeclaration.getExtraDimensions(), javaFileContent); UMLParameter returnParameter = new UMLParameter("return", type, "return", false); umlOperation.addParameter(returnParameter); } @@ -1134,19 +1146,19 @@ else if(extendedModifier.isModifier()) { for(SingleVariableDeclaration parameter : parameters) { Type parameterType = parameter.getType(); String parameterName = parameter.getName().getFullyQualifiedName(); - UMLType type = UMLType.extractTypeObject(cu, sourceFile, parameterType, parameter.getExtraDimensions(), javaFileContent); + UMLType type = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, parameterType, parameter.getExtraDimensions(), javaFileContent); if(parameter.isVarargs()) { type.setVarargs(); } UMLParameter umlParameter = new UMLParameter(parameterName, type, "in", parameter.isVarargs()); - VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFile, parameter, umlOperation, parameter.isVarargs(), javaFileContent); + VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFolder, sourceFile, parameter, umlOperation, parameter.isVarargs(), javaFileContent); variableDeclaration.setParameter(true); umlParameter.setVariableDeclaration(variableDeclaration); umlOperation.addParameter(umlParameter); } List thrownExceptionTypes = methodDeclaration.thrownExceptionTypes(); for(Type thrownExceptionType : thrownExceptionTypes) { - UMLType type = UMLType.extractTypeObject(cu, sourceFile, thrownExceptionType, 0, javaFileContent); + UMLType type = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, thrownExceptionType, 0, javaFileContent); umlOperation.addThrownExceptionType(type); } int endSignatureOffset = methodDeclaration.getBody() != null ? @@ -1157,11 +1169,11 @@ else if(extendedModifier.isModifier()) { return umlOperation; } - private void processEnumConstantDeclaration(CompilationUnit cu, EnumConstantDeclaration enumConstantDeclaration, String sourceFile, UMLClass umlClass, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, enumConstantDeclaration, sourceFile, javaFileContent); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, enumConstantDeclaration, CodeElementType.ENUM_CONSTANT_DECLARATION); + private void processEnumConstantDeclaration(CompilationUnit cu, EnumConstantDeclaration enumConstantDeclaration, String sourceFolder, String sourceFile, UMLClass umlClass, List comments, String javaFileContent) { + UMLJavadoc javadoc = generateJavadoc(cu, enumConstantDeclaration, sourceFolder, sourceFile, javaFileContent); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, enumConstantDeclaration, CodeElementType.ENUM_CONSTANT_DECLARATION); UMLEnumConstant enumConstant = new UMLEnumConstant(enumConstantDeclaration.getName().getIdentifier(), UMLType.extractTypeObject(umlClass.getName()), locationInfo); - VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFile, enumConstantDeclaration, javaFileContent); + VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFolder, sourceFile, enumConstantDeclaration, javaFileContent); enumConstant.setVariableDeclaration(variableDeclaration); enumConstant.setJavadoc(javadoc); distributeComments(comments, locationInfo, enumConstant.getComments()); @@ -1176,18 +1188,18 @@ private void processEnumConstantDeclaration(CompilationUnit cu, EnumConstantDecl umlClass.addEnumConstant(enumConstant); } - private List processFieldDeclaration(CompilationUnit cu, FieldDeclaration fieldDeclaration, boolean isInterfaceField, String sourceFile, List comments, String javaFileContent) { - UMLJavadoc javadoc = generateJavadoc(cu, fieldDeclaration, sourceFile, javaFileContent); + private List processFieldDeclaration(CompilationUnit cu, FieldDeclaration fieldDeclaration, boolean isInterfaceField, String sourceFolder, String sourceFile, List comments, String javaFileContent) { + UMLJavadoc javadoc = generateJavadoc(cu, fieldDeclaration, sourceFolder, sourceFile, javaFileContent); List attributes = new ArrayList(); Type fieldType = fieldDeclaration.getType(); List fragments = fieldDeclaration.fragments(); for(VariableDeclarationFragment fragment : fragments) { - UMLType type = UMLType.extractTypeObject(cu, sourceFile, fieldType, fragment.getExtraDimensions(), javaFileContent); + UMLType type = UMLType.extractTypeObject(cu, sourceFolder, sourceFile, fieldType, fragment.getExtraDimensions(), javaFileContent); String fieldName = fragment.getName().getFullyQualifiedName(); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, fragment, CodeElementType.FIELD_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, fragment, CodeElementType.FIELD_DECLARATION); UMLAttribute umlAttribute = new UMLAttribute(fieldName, type, locationInfo); - umlAttribute.setFieldDeclarationLocationInfo(generateLocationInfo(cu, sourceFile, fieldDeclaration, CodeElementType.FIELD_DECLARATION)); - VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFile, fragment, umlAttribute, javaFileContent); + umlAttribute.setFieldDeclarationLocationInfo(generateLocationInfo(cu, sourceFolder, sourceFile, fieldDeclaration, CodeElementType.FIELD_DECLARATION)); + VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFolder, sourceFile, fragment, umlAttribute, javaFileContent); variableDeclaration.setAttribute(true); umlAttribute.setVariableDeclaration(variableDeclaration); umlAttribute.setJavadoc(javadoc); @@ -1222,15 +1234,15 @@ else if(isInterfaceField) return attributes; } - private UMLAnonymousClass processAnonymousClassDeclaration(CompilationUnit cu, AnonymousClassDeclaration anonymous, UMLPackage umlPackage, String packageName, String binaryName, String codePath, String sourceFile, UMLJavadoc packageDoc, List comments, List importedTypes, String javaFileContent) { + private UMLAnonymousClass processAnonymousClassDeclaration(CompilationUnit cu, AnonymousClassDeclaration anonymous, UMLPackage umlPackage, String packageName, String binaryName, String codePath, String sourceFolder, String sourceFile, UMLJavadoc packageDoc, List comments, List importedTypes, String javaFileContent) { List bodyDeclarations = anonymous.bodyDeclarations(); - LocationInfo locationInfo = generateLocationInfo(cu, sourceFile, anonymous, CodeElementType.ANONYMOUS_CLASS_DECLARATION); + LocationInfo locationInfo = generateLocationInfo(cu, sourceFolder, sourceFile, anonymous, CodeElementType.ANONYMOUS_CLASS_DECLARATION); UMLAnonymousClass anonymousClass = new UMLAnonymousClass(packageName, binaryName, codePath, locationInfo, importedTypes); for(BodyDeclaration bodyDeclaration : bodyDeclarations) { if(bodyDeclaration instanceof FieldDeclaration) { FieldDeclaration fieldDeclaration = (FieldDeclaration)bodyDeclaration; - List attributes = processFieldDeclaration(cu, fieldDeclaration, false, sourceFile, comments, javaFileContent); + List attributes = processFieldDeclaration(cu, fieldDeclaration, false, sourceFolder, sourceFile, comments, javaFileContent); for(UMLAttribute attribute : attributes) { attribute.setClassName(anonymousClass.getCodePath()); attribute.setAnonymousClassContainer(anonymousClass); @@ -1239,33 +1251,33 @@ private UMLAnonymousClass processAnonymousClassDeclaration(CompilationUnit cu, A } else if(bodyDeclaration instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration)bodyDeclaration; - UMLOperation operation = processMethodDeclaration(cu, methodDeclaration, packageName, false, sourceFile, comments, javaFileContent); + UMLOperation operation = processMethodDeclaration(cu, methodDeclaration, packageName, false, sourceFolder, sourceFile, comments, javaFileContent); operation.setClassName(anonymousClass.getCodePath()); operation.setAnonymousClassContainer(anonymousClass); anonymousClass.addOperation(operation); } else if(bodyDeclaration instanceof Initializer) { Initializer initializer = (Initializer)bodyDeclaration; - UMLInitializer umlInitializer = processInitializer(cu, initializer, packageName, false, sourceFile, comments, javaFileContent); + UMLInitializer umlInitializer = processInitializer(cu, initializer, packageName, false, sourceFolder, sourceFile, comments, javaFileContent); umlInitializer.setClassName(anonymousClass.getCodePath()); umlInitializer.setAnonymousClassContainer(anonymousClass); anonymousClass.addInitializer(umlInitializer); } else if(bodyDeclaration instanceof TypeDeclaration) { TypeDeclaration typeDeclaration = (TypeDeclaration)bodyDeclaration; - processTypeDeclaration(cu, typeDeclaration, umlPackage, anonymousClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processTypeDeclaration(cu, typeDeclaration, umlPackage, anonymousClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } else if(bodyDeclaration instanceof EnumDeclaration) { EnumDeclaration enumDeclaration = (EnumDeclaration)bodyDeclaration; - processEnumDeclaration(cu, enumDeclaration, umlPackage, anonymousClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processEnumDeclaration(cu, enumDeclaration, umlPackage, anonymousClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } else if(bodyDeclaration instanceof AnnotationTypeDeclaration) { AnnotationTypeDeclaration annotationDeclaration = (AnnotationTypeDeclaration)bodyDeclaration; - processAnnotationTypeDeclaration(cu, annotationDeclaration, umlPackage, anonymousClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processAnnotationTypeDeclaration(cu, annotationDeclaration, umlPackage, anonymousClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } else if(bodyDeclaration instanceof RecordDeclaration) { RecordDeclaration recordDeclaration = (RecordDeclaration)bodyDeclaration; - processRecordDeclaration(cu, recordDeclaration, umlPackage, anonymousClass.getName(), sourceFile, importedTypes, packageDoc, comments, javaFileContent); + processRecordDeclaration(cu, recordDeclaration, umlPackage, anonymousClass.getName(), sourceFolder, sourceFile, importedTypes, packageDoc, comments, javaFileContent); } } distributeComments(comments, locationInfo, anonymousClass.getComments()); @@ -1389,7 +1401,7 @@ private boolean isParent(ASTNode child, ASTNode parent) { return false; } - private LocationInfo generateLocationInfo(CompilationUnit cu, String sourceFile, ASTNode node, CodeElementType codeElementType) { - return new LocationInfo(cu, sourceFile, node, codeElementType); + private LocationInfo generateLocationInfo(CompilationUnit cu, String sourceFolder, String sourceFile, ASTNode node, CodeElementType codeElementType) { + return new LocationInfo(cu, sourceFolder, sourceFile, node, codeElementType); } } diff --git a/src/main/java/gr/uom/java/xmi/UMLModifier.java b/src/main/java/gr/uom/java/xmi/UMLModifier.java index 6ccc214810..2ecd613573 100644 --- a/src/main/java/gr/uom/java/xmi/UMLModifier.java +++ b/src/main/java/gr/uom/java/xmi/UMLModifier.java @@ -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() { diff --git a/src/main/java/gr/uom/java/xmi/UMLType.java b/src/main/java/gr/uom/java/xmi/UMLType.java index 30c011fd21..2bc196d3c3 100644 --- a/src/main/java/gr/uom/java/xmi/UMLType.java +++ b/src/main/java/gr/uom/java/xmi/UMLType.java @@ -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 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 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); } @@ -285,7 +285,7 @@ else if(type instanceof NameQualifiedType) { AnnotatableType annotatableType = (AnnotatableType)nameQualified; List 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); } @@ -293,7 +293,7 @@ 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 { @@ -302,18 +302,18 @@ else if(type instanceof WildcardType) { AnnotatableType annotatableType = (AnnotatableType)wildcard; List 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 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(); @@ -321,11 +321,11 @@ else if(type instanceof 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 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; } @@ -334,7 +334,7 @@ else if(type instanceof UnionType) { List types = union.types(); List umlTypes = new ArrayList(); 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); } @@ -343,7 +343,7 @@ else if(type instanceof IntersectionType) { List types = intersection.types(); List umlTypes = new ArrayList(); 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); } diff --git a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java index d103f20e78..3402e845c5 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java @@ -36,8 +36,8 @@ public abstract class AbstractCall extends LeafExpression { private static final List logNames = List.of("trace", "debug", "info", "warn", "error", "fatal", "log"); private static final List 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() { diff --git a/src/main/java/gr/uom/java/xmi/decomposition/AbstractExpression.java b/src/main/java/gr/uom/java/xmi/decomposition/AbstractExpression.java index ccfd7e9d64..6ced181c9e 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AbstractExpression.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AbstractExpression.java @@ -45,9 +45,9 @@ public class AbstractExpression extends AbstractCodeFragment { private List ternaryOperatorExpressions; private List 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(); diff --git a/src/main/java/gr/uom/java/xmi/decomposition/AnonymousClassDeclarationObject.java b/src/main/java/gr/uom/java/xmi/decomposition/AnonymousClassDeclarationObject.java index 5d750ad9b7..8cb7667dc5 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AnonymousClassDeclarationObject.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AnonymousClassDeclarationObject.java @@ -43,8 +43,8 @@ public class AnonymousClassDeclarationObject implements LocationInfoProvider { private List ternaryOperatorExpressions = new ArrayList(); private List lambdas = new ArrayList(); - 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); } diff --git a/src/main/java/gr/uom/java/xmi/decomposition/CompositeStatementObject.java b/src/main/java/gr/uom/java/xmi/decomposition/CompositeStatementObject.java index fc2f05c450..05786ea9f8 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/CompositeStatementObject.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/CompositeStatementObject.java @@ -26,10 +26,10 @@ public class CompositeStatementObject extends AbstractStatement { private Optional 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(); this.expressionList = new ArrayList(); this.variableDeclarations = new ArrayList(); diff --git a/src/main/java/gr/uom/java/xmi/decomposition/LambdaExpressionObject.java b/src/main/java/gr/uom/java/xmi/decomposition/LambdaExpressionObject.java index db6bdfa2c1..b4b5388f2d 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/LambdaExpressionObject.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/LambdaExpressionObject.java @@ -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 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(); } @@ -71,10 +71,10 @@ 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); @@ -82,13 +82,13 @@ else if(lambda.getBody() instanceof 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 @@ -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() { diff --git a/src/main/java/gr/uom/java/xmi/decomposition/LeafExpression.java b/src/main/java/gr/uom/java/xmi/decomposition/LeafExpression.java index c156d1188b..b24c3d0433 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/LeafExpression.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/LeafExpression.java @@ -19,8 +19,8 @@ public class LeafExpression extends AbstractCodeFragment { protected LocationInfo locationInfo; protected VariableDeclarationContainer container; - public LeafExpression(CompilationUnit cu, String filePath, ASTNode expression, CodeElementType codeElementType, VariableDeclarationContainer container) { - this.locationInfo = new LocationInfo(cu, filePath, expression, codeElementType); + public LeafExpression(CompilationUnit cu, String sourceFolder, String filePath, ASTNode expression, CodeElementType codeElementType, VariableDeclarationContainer container) { + this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, expression, codeElementType); this.string = stringify(expression); this.container = container; } diff --git a/src/main/java/gr/uom/java/xmi/decomposition/MethodReference.java b/src/main/java/gr/uom/java/xmi/decomposition/MethodReference.java index fbabe9ac41..efc81cc389 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/MethodReference.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/MethodReference.java @@ -19,15 +19,15 @@ public class MethodReference extends AbstractCall { private String methodName; private volatile int hashCode = 0; - public MethodReference(CompilationUnit cu, String filePath, ExpressionMethodReference reference, VariableDeclarationContainer container) { - super(cu, filePath, reference, CodeElementType.METHOD_REFERENCE, container); + public MethodReference(CompilationUnit cu, String sourceFolder, String filePath, ExpressionMethodReference reference, VariableDeclarationContainer container) { + super(cu, sourceFolder, filePath, reference, CodeElementType.METHOD_REFERENCE, container); this.methodName = reference.getName().getIdentifier(); this.expression = stringify(reference.getExpression()); this.arguments = new ArrayList(); } - public MethodReference(CompilationUnit cu, String filePath, SuperMethodReference reference, VariableDeclarationContainer container) { - super(cu, filePath, reference, CodeElementType.METHOD_REFERENCE, container); + public MethodReference(CompilationUnit cu, String sourceFolder, String filePath, SuperMethodReference reference, VariableDeclarationContainer container) { + super(cu, sourceFolder, filePath, reference, CodeElementType.METHOD_REFERENCE, container); this.methodName = reference.getName().getIdentifier(); this.arguments = new ArrayList(); if(reference.getQualifier() != null) { @@ -38,10 +38,10 @@ public MethodReference(CompilationUnit cu, String filePath, SuperMethodReference } } - public MethodReference(CompilationUnit cu, String filePath, TypeMethodReference reference, VariableDeclarationContainer container, String javaFileContent) { - super(cu, filePath, reference, CodeElementType.METHOD_REFERENCE, container); + public MethodReference(CompilationUnit cu, String sourceFolder, String filePath, TypeMethodReference reference, VariableDeclarationContainer container, String javaFileContent) { + super(cu, sourceFolder, filePath, reference, CodeElementType.METHOD_REFERENCE, container); this.methodName = reference.getName().getIdentifier(); - this.expression = UMLType.extractTypeObject(cu, filePath, reference.getType(), 0, javaFileContent).toQualifiedString(); + this.expression = UMLType.extractTypeObject(cu, sourceFolder, filePath, reference.getType(), 0, javaFileContent).toQualifiedString(); this.arguments = new ArrayList(); } diff --git a/src/main/java/gr/uom/java/xmi/decomposition/ObjectCreation.java b/src/main/java/gr/uom/java/xmi/decomposition/ObjectCreation.java index 55c0aa7138..83e1290173 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/ObjectCreation.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/ObjectCreation.java @@ -24,9 +24,9 @@ public class ObjectCreation extends AbstractCall { private boolean isArray = false; private volatile int hashCode = 0; - public ObjectCreation(CompilationUnit cu, String filePath, ClassInstanceCreation creation, VariableDeclarationContainer container, String javaFileContent) { - super(cu, filePath, creation, CodeElementType.CLASS_INSTANCE_CREATION, container); - this.type = UMLType.extractTypeObject(cu, filePath, creation.getType(), 0, javaFileContent); + public ObjectCreation(CompilationUnit cu, String sourceFolder, String filePath, ClassInstanceCreation creation, VariableDeclarationContainer container, String javaFileContent) { + super(cu, sourceFolder, filePath, creation, CodeElementType.CLASS_INSTANCE_CREATION, container); + this.type = UMLType.extractTypeObject(cu, sourceFolder, filePath, creation.getType(), 0, javaFileContent); this.numberOfArguments = creation.arguments().size(); this.arguments = new ArrayList(); List args = creation.arguments(); @@ -41,10 +41,10 @@ public ObjectCreation(CompilationUnit cu, String filePath, ClassInstanceCreation } } - public ObjectCreation(CompilationUnit cu, String filePath, ArrayCreation creation, VariableDeclarationContainer container, String javaFileContent) { - super(cu, filePath, creation, CodeElementType.ARRAY_CREATION, container); + public ObjectCreation(CompilationUnit cu, String sourceFolder, String filePath, ArrayCreation creation, VariableDeclarationContainer container, String javaFileContent) { + super(cu, sourceFolder, filePath, creation, CodeElementType.ARRAY_CREATION, container); this.isArray = true; - this.type = UMLType.extractTypeObject(cu, filePath, creation.getType(), 0, javaFileContent); + this.type = UMLType.extractTypeObject(cu, sourceFolder, filePath, creation.getType(), 0, javaFileContent); this.numberOfArguments = creation.dimensions().size(); this.arguments = new ArrayList(); List args = creation.dimensions(); diff --git a/src/main/java/gr/uom/java/xmi/decomposition/OperationBody.java b/src/main/java/gr/uom/java/xmi/decomposition/OperationBody.java index d07d31f273..47c0f9b26a 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/OperationBody.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/OperationBody.java @@ -57,8 +57,8 @@ public class OperationBody { private List comments; private final String javaFileContent; - public OperationBody(CompilationUnit cu, String filePath, Block methodBody, VariableDeclarationContainer container, List attributes, String javaFileContent) { - this.compositeStatement = new CompositeStatementObject(cu, filePath, methodBody, 0, CodeElementType.BLOCK); + public OperationBody(CompilationUnit cu, String sourceFolder, String filePath, Block methodBody, VariableDeclarationContainer container, List attributes, String javaFileContent) { + this.compositeStatement = new CompositeStatementObject(cu, sourceFolder, filePath, methodBody, 0, CodeElementType.BLOCK); this.comments = container.getComments(); this.container = container; this.javaFileContent = javaFileContent; @@ -80,7 +80,7 @@ public OperationBody(CompilationUnit cu, String filePath, Block methodBody, Vari } List statements = methodBody.statements(); for(Statement statement : statements) { - processStatement(cu, filePath, compositeStatement, statement); + processStatement(cu, sourceFolder, filePath, compositeStatement, statement); } for(AbstractCall invocation : getAllOperationInvocations()) { if(invocation.isAssertion()) { @@ -170,7 +170,7 @@ public VariableDeclaration getVariableDeclaration(String variableName) { return compositeStatement.getVariableDeclaration(variableName); } - private void processStatement(CompilationUnit cu, String filePath, CompositeStatementObject parent, Statement statement) { + private void processStatement(CompilationUnit cu, String sourceFolder, String filePath, CompositeStatementObject parent, Statement statement) { for(UMLComment comment : comments) { if(comment.getParent() != null && comment.getParent().equals(parent)) continue; @@ -188,160 +188,160 @@ private void processStatement(CompilationUnit cu, String filePath, CompositeStat if(statement instanceof Block) { Block block = (Block)statement; List blockStatements = block.statements(); - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, block, parent.getDepth()+1, CodeElementType.BLOCK); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, block, parent.getDepth()+1, CodeElementType.BLOCK); parent.addStatement(child); addStatementInVariableScopes(child); for(Statement blockStatement : blockStatements) { - processStatement(cu, filePath, child, blockStatement); + processStatement(cu, sourceFolder, filePath, child, blockStatement); } } else if(statement instanceof IfStatement) { IfStatement ifStatement = (IfStatement)statement; - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, ifStatement, parent.getDepth()+1, CodeElementType.IF_STATEMENT); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, ifStatement, parent.getDepth()+1, CodeElementType.IF_STATEMENT); parent.addStatement(child); - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, ifStatement.getExpression(), CodeElementType.IF_STATEMENT_CONDITION, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, ifStatement.getExpression(), CodeElementType.IF_STATEMENT_CONDITION, container, javaFileContent); child.addExpression(abstractExpression); addStatementInVariableScopes(child); - processStatement(cu, filePath, child, ifStatement.getThenStatement()); + processStatement(cu, sourceFolder, filePath, child, ifStatement.getThenStatement()); if(ifStatement.getElseStatement() != null) { - processStatement(cu, filePath, child, ifStatement.getElseStatement()); + processStatement(cu, sourceFolder, filePath, child, ifStatement.getElseStatement()); } } else if(statement instanceof ForStatement) { ForStatement forStatement = (ForStatement)statement; - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, forStatement, parent.getDepth()+1, CodeElementType.FOR_STATEMENT); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, forStatement, parent.getDepth()+1, CodeElementType.FOR_STATEMENT); parent.addStatement(child); List initializers = forStatement.initializers(); for(Expression initializer : initializers) { - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, initializer, CodeElementType.FOR_STATEMENT_INITIALIZER, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, initializer, CodeElementType.FOR_STATEMENT_INITIALIZER, container, javaFileContent); child.addExpression(abstractExpression); } Expression expression = forStatement.getExpression(); if(expression != null) { - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, expression, CodeElementType.FOR_STATEMENT_CONDITION, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, expression, CodeElementType.FOR_STATEMENT_CONDITION, container, javaFileContent); child.addExpression(abstractExpression); } List updaters = forStatement.updaters(); for(Expression updater : updaters) { - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, updater, CodeElementType.FOR_STATEMENT_UPDATER, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, updater, CodeElementType.FOR_STATEMENT_UPDATER, container, javaFileContent); child.addExpression(abstractExpression); } addStatementInVariableScopes(child); List variableDeclarations = child.getVariableDeclarations(); this.activeVariableDeclarations.addAll(variableDeclarations); - processStatement(cu, filePath, child, forStatement.getBody()); + processStatement(cu, sourceFolder, filePath, child, forStatement.getBody()); this.activeVariableDeclarations.removeAll(variableDeclarations); } else if(statement instanceof EnhancedForStatement) { EnhancedForStatement enhancedForStatement = (EnhancedForStatement)statement; - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, enhancedForStatement, parent.getDepth()+1, CodeElementType.ENHANCED_FOR_STATEMENT); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, enhancedForStatement, parent.getDepth()+1, CodeElementType.ENHANCED_FOR_STATEMENT); parent.addStatement(child); SingleVariableDeclaration variableDeclaration = enhancedForStatement.getParameter(); - VariableDeclaration vd = new VariableDeclaration(cu, filePath, variableDeclaration, container, javaFileContent); + VariableDeclaration vd = new VariableDeclaration(cu, sourceFolder, filePath, variableDeclaration, container, javaFileContent); child.addVariableDeclaration(vd); - AbstractExpression variableDeclarationName = new AbstractExpression(cu, filePath, variableDeclaration.getName(), CodeElementType.ENHANCED_FOR_STATEMENT_PARAMETER_NAME, container, javaFileContent); + AbstractExpression variableDeclarationName = new AbstractExpression(cu, sourceFolder, filePath, variableDeclaration.getName(), CodeElementType.ENHANCED_FOR_STATEMENT_PARAMETER_NAME, container, javaFileContent); child.addExpression(variableDeclarationName); if(variableDeclaration.getInitializer() != null) { - AbstractExpression variableDeclarationInitializer = new AbstractExpression(cu, filePath, variableDeclaration.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent); + AbstractExpression variableDeclarationInitializer = new AbstractExpression(cu, sourceFolder, filePath, variableDeclaration.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent); child.addExpression(variableDeclarationInitializer); } - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, enhancedForStatement.getExpression(), CodeElementType.ENHANCED_FOR_STATEMENT_EXPRESSION, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, enhancedForStatement.getExpression(), CodeElementType.ENHANCED_FOR_STATEMENT_EXPRESSION, container, javaFileContent); child.addExpression(abstractExpression); addStatementInVariableScopes(child); List variableDeclarations = child.getVariableDeclarations(); this.activeVariableDeclarations.addAll(variableDeclarations); - processStatement(cu, filePath, child, enhancedForStatement.getBody()); + processStatement(cu, sourceFolder, filePath, child, enhancedForStatement.getBody()); this.activeVariableDeclarations.removeAll(variableDeclarations); } else if(statement instanceof WhileStatement) { WhileStatement whileStatement = (WhileStatement)statement; - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, whileStatement, parent.getDepth()+1, CodeElementType.WHILE_STATEMENT); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, whileStatement, parent.getDepth()+1, CodeElementType.WHILE_STATEMENT); parent.addStatement(child); - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, whileStatement.getExpression(), CodeElementType.WHILE_STATEMENT_CONDITION, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, whileStatement.getExpression(), CodeElementType.WHILE_STATEMENT_CONDITION, container, javaFileContent); child.addExpression(abstractExpression); addStatementInVariableScopes(child); - processStatement(cu, filePath, child, whileStatement.getBody()); + processStatement(cu, sourceFolder, filePath, child, whileStatement.getBody()); } else if(statement instanceof DoStatement) { DoStatement doStatement = (DoStatement)statement; - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, doStatement, parent.getDepth()+1, CodeElementType.DO_STATEMENT); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, doStatement, parent.getDepth()+1, CodeElementType.DO_STATEMENT); parent.addStatement(child); - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, doStatement.getExpression(), CodeElementType.DO_STATEMENT_CONDITION, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, doStatement.getExpression(), CodeElementType.DO_STATEMENT_CONDITION, container, javaFileContent); child.addExpression(abstractExpression); addStatementInVariableScopes(child); - processStatement(cu, filePath, child, doStatement.getBody()); + processStatement(cu, sourceFolder, filePath, child, doStatement.getBody()); } else if(statement instanceof ExpressionStatement) { ExpressionStatement expressionStatement = (ExpressionStatement)statement; - StatementObject child = new StatementObject(cu, filePath, expressionStatement, parent.getDepth()+1, CodeElementType.EXPRESSION_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, expressionStatement, parent.getDepth()+1, CodeElementType.EXPRESSION_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof SwitchStatement) { SwitchStatement switchStatement = (SwitchStatement)statement; - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, switchStatement, parent.getDepth()+1, CodeElementType.SWITCH_STATEMENT); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, switchStatement, parent.getDepth()+1, CodeElementType.SWITCH_STATEMENT); parent.addStatement(child); - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, switchStatement.getExpression(), CodeElementType.SWITCH_STATEMENT_CONDITION, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, switchStatement.getExpression(), CodeElementType.SWITCH_STATEMENT_CONDITION, container, javaFileContent); child.addExpression(abstractExpression); addStatementInVariableScopes(child); List switchStatements = switchStatement.statements(); for(Statement switchStatement2 : switchStatements) - processStatement(cu, filePath, child, switchStatement2); + processStatement(cu, sourceFolder, filePath, child, switchStatement2); } else if(statement instanceof SwitchCase) { SwitchCase switchCase = (SwitchCase)statement; - StatementObject child = new StatementObject(cu, filePath, switchCase, parent.getDepth()+1, CodeElementType.SWITCH_CASE, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, switchCase, parent.getDepth()+1, CodeElementType.SWITCH_CASE, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof YieldStatement) { YieldStatement yieldStatement = (YieldStatement)statement; - StatementObject child = new StatementObject(cu, filePath, yieldStatement, parent.getDepth()+1, CodeElementType.YIELD_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, yieldStatement, parent.getDepth()+1, CodeElementType.YIELD_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof AssertStatement) { AssertStatement assertStatement = (AssertStatement)statement; - StatementObject child = new StatementObject(cu, filePath, assertStatement, parent.getDepth()+1, CodeElementType.ASSERT_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, assertStatement, parent.getDepth()+1, CodeElementType.ASSERT_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof LabeledStatement) { LabeledStatement labeledStatement = (LabeledStatement)statement; SimpleName label = labeledStatement.getLabel(); - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, labeledStatement, parent.getDepth()+1, CodeElementType.LABELED_STATEMENT.setName(label.getIdentifier())); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, labeledStatement, parent.getDepth()+1, CodeElementType.LABELED_STATEMENT.setName(label.getIdentifier())); parent.addStatement(child); addStatementInVariableScopes(child); - processStatement(cu, filePath, child, labeledStatement.getBody()); + processStatement(cu, sourceFolder, filePath, child, labeledStatement.getBody()); } else if(statement instanceof ReturnStatement) { ReturnStatement returnStatement = (ReturnStatement)statement; - StatementObject child = new StatementObject(cu, filePath, returnStatement, parent.getDepth()+1, CodeElementType.RETURN_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, returnStatement, parent.getDepth()+1, CodeElementType.RETURN_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof SynchronizedStatement) { SynchronizedStatement synchronizedStatement = (SynchronizedStatement)statement; - CompositeStatementObject child = new CompositeStatementObject(cu, filePath, synchronizedStatement, parent.getDepth()+1, CodeElementType.SYNCHRONIZED_STATEMENT); + CompositeStatementObject child = new CompositeStatementObject(cu, sourceFolder, filePath, synchronizedStatement, parent.getDepth()+1, CodeElementType.SYNCHRONIZED_STATEMENT); parent.addStatement(child); - AbstractExpression abstractExpression = new AbstractExpression(cu, filePath, synchronizedStatement.getExpression(), CodeElementType.SYNCHRONIZED_STATEMENT_EXPRESSION, container, javaFileContent); + AbstractExpression abstractExpression = new AbstractExpression(cu, sourceFolder, filePath, synchronizedStatement.getExpression(), CodeElementType.SYNCHRONIZED_STATEMENT_EXPRESSION, container, javaFileContent); child.addExpression(abstractExpression); addStatementInVariableScopes(child); - processStatement(cu, filePath, child, synchronizedStatement.getBody()); + processStatement(cu, sourceFolder, filePath, child, synchronizedStatement.getBody()); } else if(statement instanceof ThrowStatement) { ThrowStatement throwStatement = (ThrowStatement)statement; - StatementObject child = new StatementObject(cu, filePath, throwStatement, parent.getDepth()+1, CodeElementType.THROW_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, throwStatement, parent.getDepth()+1, CodeElementType.THROW_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof TryStatement) { TryStatement tryStatement = (TryStatement)statement; - TryStatementObject child = new TryStatementObject(cu, filePath, tryStatement, parent.getDepth()+1); + TryStatementObject child = new TryStatementObject(cu, sourceFolder, filePath, tryStatement, parent.getDepth()+1); parent.addStatement(child); List resources = tryStatement.resources(); for(Expression resource : resources) { - AbstractExpression expression = new AbstractExpression(cu, filePath, resource, CodeElementType.TRY_STATEMENT_RESOURCE, container, javaFileContent); + AbstractExpression expression = new AbstractExpression(cu, sourceFolder, filePath, resource, CodeElementType.TRY_STATEMENT_RESOURCE, container, javaFileContent); child.addExpression(expression); } addStatementInVariableScopes(child); @@ -349,23 +349,23 @@ else if(statement instanceof TryStatement) { this.activeVariableDeclarations.addAll(variableDeclarations); List tryStatements = tryStatement.getBody().statements(); for(Statement blockStatement : tryStatements) { - processStatement(cu, filePath, child, blockStatement); + processStatement(cu, sourceFolder, filePath, child, blockStatement); } this.activeVariableDeclarations.removeAll(variableDeclarations); List catchClauses = tryStatement.catchClauses(); for(CatchClause catchClause : catchClauses) { Block catchClauseBody = catchClause.getBody(); - CompositeStatementObject catchClauseStatementObject = new CompositeStatementObject(cu, filePath, catchClause, parent.getDepth()+1, CodeElementType.CATCH_CLAUSE); + CompositeStatementObject catchClauseStatementObject = new CompositeStatementObject(cu, sourceFolder, filePath, catchClause, parent.getDepth()+1, CodeElementType.CATCH_CLAUSE); child.addCatchClause(catchClauseStatementObject); parent.addStatement(catchClauseStatementObject); catchClauseStatementObject.setTryContainer(child); SingleVariableDeclaration variableDeclaration = catchClause.getException(); - VariableDeclaration vd = new VariableDeclaration(cu, filePath, variableDeclaration, container, javaFileContent); + VariableDeclaration vd = new VariableDeclaration(cu, sourceFolder, filePath, variableDeclaration, container, javaFileContent); catchClauseStatementObject.addVariableDeclaration(vd); - AbstractExpression variableDeclarationName = new AbstractExpression(cu, filePath, variableDeclaration.getName(), CodeElementType.CATCH_CLAUSE_EXCEPTION_NAME, container, javaFileContent); + AbstractExpression variableDeclarationName = new AbstractExpression(cu, sourceFolder, filePath, variableDeclaration.getName(), CodeElementType.CATCH_CLAUSE_EXCEPTION_NAME, container, javaFileContent); catchClauseStatementObject.addExpression(variableDeclarationName); if(variableDeclaration.getInitializer() != null) { - AbstractExpression variableDeclarationInitializer = new AbstractExpression(cu, filePath, variableDeclaration.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent); + AbstractExpression variableDeclarationInitializer = new AbstractExpression(cu, sourceFolder, filePath, variableDeclaration.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent); catchClauseStatementObject.addExpression(variableDeclarationInitializer); } addStatementInVariableScopes(catchClauseStatementObject); @@ -373,57 +373,57 @@ else if(statement instanceof TryStatement) { this.activeVariableDeclarations.addAll(catchClauseVariableDeclarations); List blockStatements = catchClauseBody.statements(); for(Statement blockStatement : blockStatements) { - processStatement(cu, filePath, catchClauseStatementObject, blockStatement); + processStatement(cu, sourceFolder, filePath, catchClauseStatementObject, blockStatement); } this.activeVariableDeclarations.removeAll(catchClauseVariableDeclarations); } Block finallyBlock = tryStatement.getFinally(); if(finallyBlock != null) { - CompositeStatementObject finallyClauseStatementObject = new CompositeStatementObject(cu, filePath, finallyBlock, parent.getDepth()+1, CodeElementType.FINALLY_BLOCK); + CompositeStatementObject finallyClauseStatementObject = new CompositeStatementObject(cu, sourceFolder, filePath, finallyBlock, parent.getDepth()+1, CodeElementType.FINALLY_BLOCK); child.setFinallyClause(finallyClauseStatementObject); parent.addStatement(finallyClauseStatementObject); finallyClauseStatementObject.setTryContainer(child); addStatementInVariableScopes(finallyClauseStatementObject); List blockStatements = finallyBlock.statements(); for(Statement blockStatement : blockStatements) { - processStatement(cu, filePath, finallyClauseStatementObject, blockStatement); + processStatement(cu, sourceFolder, filePath, finallyClauseStatementObject, blockStatement); } } } else if(statement instanceof VariableDeclarationStatement) { VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)statement; - StatementObject child = new StatementObject(cu, filePath, variableDeclarationStatement, parent.getDepth()+1, CodeElementType.VARIABLE_DECLARATION_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, variableDeclarationStatement, parent.getDepth()+1, CodeElementType.VARIABLE_DECLARATION_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); this.activeVariableDeclarations.addAll(child.getVariableDeclarations()); } else if(statement instanceof ConstructorInvocation) { ConstructorInvocation constructorInvocation = (ConstructorInvocation)statement; - StatementObject child = new StatementObject(cu, filePath, constructorInvocation, parent.getDepth()+1, CodeElementType.CONSTRUCTOR_INVOCATION, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, constructorInvocation, parent.getDepth()+1, CodeElementType.CONSTRUCTOR_INVOCATION, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof SuperConstructorInvocation) { SuperConstructorInvocation superConstructorInvocation = (SuperConstructorInvocation)statement; - StatementObject child = new StatementObject(cu, filePath, superConstructorInvocation, parent.getDepth()+1, CodeElementType.SUPER_CONSTRUCTOR_INVOCATION, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, superConstructorInvocation, parent.getDepth()+1, CodeElementType.SUPER_CONSTRUCTOR_INVOCATION, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof BreakStatement) { BreakStatement breakStatement = (BreakStatement)statement; - StatementObject child = new StatementObject(cu, filePath, breakStatement, parent.getDepth()+1, CodeElementType.BREAK_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, breakStatement, parent.getDepth()+1, CodeElementType.BREAK_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof ContinueStatement) { ContinueStatement continueStatement = (ContinueStatement)statement; - StatementObject child = new StatementObject(cu, filePath, continueStatement, parent.getDepth()+1, CodeElementType.CONTINUE_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, continueStatement, parent.getDepth()+1, CodeElementType.CONTINUE_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } else if(statement instanceof EmptyStatement) { EmptyStatement emptyStatement = (EmptyStatement)statement; - StatementObject child = new StatementObject(cu, filePath, emptyStatement, parent.getDepth()+1, CodeElementType.EMPTY_STATEMENT, container, javaFileContent); + StatementObject child = new StatementObject(cu, sourceFolder, filePath, emptyStatement, parent.getDepth()+1, CodeElementType.EMPTY_STATEMENT, container, javaFileContent); parent.addStatement(child); addStatementInVariableScopes(child); } diff --git a/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java b/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java index 79bbd589f9..0704d63ba3 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java @@ -85,8 +85,8 @@ public class OperationInvocation extends AbstractCall { PRIMITIVE_TYPE_NARROWING_MAP = Collections.unmodifiableMap(PRIMITIVE_TYPE_NARROWING_MAP); } - public OperationInvocation(CompilationUnit cu, String filePath, MethodInvocation invocation, VariableDeclarationContainer container) { - super(cu, filePath, invocation, CodeElementType.METHOD_INVOCATION, container); + public OperationInvocation(CompilationUnit cu, String sourceFolder, String filePath, MethodInvocation invocation, VariableDeclarationContainer container) { + super(cu, sourceFolder, filePath, invocation, CodeElementType.METHOD_INVOCATION, container); this.methodName = invocation.getName().getIdentifier(); this.numberOfArguments = invocation.arguments().size(); this.arguments = new ArrayList(); @@ -129,8 +129,8 @@ else if(expression instanceof ClassInstanceCreation) { } } - public OperationInvocation(CompilationUnit cu, String filePath, SuperMethodInvocation invocation, VariableDeclarationContainer container) { - super(cu, filePath, invocation, CodeElementType.SUPER_METHOD_INVOCATION, container); + public OperationInvocation(CompilationUnit cu, String sourceFolder, String filePath, SuperMethodInvocation invocation, VariableDeclarationContainer container) { + super(cu, sourceFolder, filePath, invocation, CodeElementType.SUPER_METHOD_INVOCATION, container); this.methodName = invocation.getName().getIdentifier(); this.numberOfArguments = invocation.arguments().size(); this.arguments = new ArrayList(); @@ -142,8 +142,8 @@ public OperationInvocation(CompilationUnit cu, String filePath, SuperMethodInvoc } } - public OperationInvocation(CompilationUnit cu, String filePath, SuperConstructorInvocation invocation, VariableDeclarationContainer container) { - super(cu, filePath, invocation, CodeElementType.SUPER_CONSTRUCTOR_INVOCATION, container); + public OperationInvocation(CompilationUnit cu, String sourceFolder, String filePath, SuperConstructorInvocation invocation, VariableDeclarationContainer container) { + super(cu, sourceFolder, filePath, invocation, CodeElementType.SUPER_CONSTRUCTOR_INVOCATION, container); this.methodName = "super"; this.numberOfArguments = invocation.arguments().size(); this.arguments = new ArrayList(); @@ -157,8 +157,8 @@ public OperationInvocation(CompilationUnit cu, String filePath, SuperConstructor } } - public OperationInvocation(CompilationUnit cu, String filePath, ConstructorInvocation invocation, VariableDeclarationContainer container) { - super(cu, filePath, invocation, CodeElementType.CONSTRUCTOR_INVOCATION, container); + public OperationInvocation(CompilationUnit cu, String sourceFolder, String filePath, ConstructorInvocation invocation, VariableDeclarationContainer container) { + super(cu, sourceFolder, filePath, invocation, CodeElementType.CONSTRUCTOR_INVOCATION, container); this.methodName = "this"; this.numberOfArguments = invocation.arguments().size(); this.arguments = new ArrayList(); diff --git a/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java b/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java index 4386d8e620..651df9391c 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java @@ -51,10 +51,10 @@ public class StatementObject extends AbstractStatement { private List lambdas; private String actualSignature; - public StatementObject(CompilationUnit cu, String filePath, Statement statement, int depth, CodeElementType codeElementType, VariableDeclarationContainer container, String javaFileContent) { + public StatementObject(CompilationUnit cu, String sourceFolder, String filePath, Statement statement, int depth, CodeElementType codeElementType, VariableDeclarationContainer container, String javaFileContent) { super(); - this.locationInfo = new LocationInfo(cu, filePath, statement, codeElementType); - Visitor visitor = new Visitor(cu, filePath, container, javaFileContent); + this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, statement, codeElementType); + Visitor visitor = new Visitor(cu, sourceFolder, filePath, container, javaFileContent); statement.accept(visitor); this.variables = visitor.getVariables(); this.types = visitor.getTypes(); diff --git a/src/main/java/gr/uom/java/xmi/decomposition/TernaryOperatorExpression.java b/src/main/java/gr/uom/java/xmi/decomposition/TernaryOperatorExpression.java index 164e040cb8..ba53aa5f51 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/TernaryOperatorExpression.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/TernaryOperatorExpression.java @@ -16,15 +16,15 @@ public class TernaryOperatorExpression extends LeafExpression { private AbstractExpression thenExpression; private AbstractCodeFragment elseExpression; - public TernaryOperatorExpression(CompilationUnit cu, String filePath, ConditionalExpression expression, VariableDeclarationContainer container, String javaFileContent) { - super(cu, filePath, expression, CodeElementType.TERNARY_OPERATOR, container); - this.condition = new AbstractExpression(cu, filePath, expression.getExpression(), CodeElementType.TERNARY_OPERATOR_CONDITION, container, javaFileContent); - this.thenExpression = new AbstractExpression(cu, filePath, expression.getThenExpression(), CodeElementType.TERNARY_OPERATOR_THEN_EXPRESSION, container, javaFileContent); + public TernaryOperatorExpression(CompilationUnit cu, String sourceFolder, String filePath, ConditionalExpression expression, VariableDeclarationContainer container, String javaFileContent) { + super(cu, sourceFolder, filePath, expression, CodeElementType.TERNARY_OPERATOR, container); + this.condition = new AbstractExpression(cu, sourceFolder, filePath, expression.getExpression(), CodeElementType.TERNARY_OPERATOR_CONDITION, container, javaFileContent); + this.thenExpression = new AbstractExpression(cu, sourceFolder, filePath, expression.getThenExpression(), CodeElementType.TERNARY_OPERATOR_THEN_EXPRESSION, container, javaFileContent); if(expression.getElseExpression() instanceof ConditionalExpression) { - this.elseExpression = new TernaryOperatorExpression(cu, filePath, (ConditionalExpression)expression.getElseExpression(), container, javaFileContent); + this.elseExpression = new TernaryOperatorExpression(cu, sourceFolder, filePath, (ConditionalExpression)expression.getElseExpression(), container, javaFileContent); } else { - this.elseExpression = new AbstractExpression(cu, filePath, expression.getElseExpression(), CodeElementType.TERNARY_OPERATOR_ELSE_EXPRESSION, container, javaFileContent); + this.elseExpression = new AbstractExpression(cu, sourceFolder, filePath, expression.getElseExpression(), CodeElementType.TERNARY_OPERATOR_ELSE_EXPRESSION, container, javaFileContent); } } diff --git a/src/main/java/gr/uom/java/xmi/decomposition/TryStatementObject.java b/src/main/java/gr/uom/java/xmi/decomposition/TryStatementObject.java index 348597dfe9..baf917a131 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/TryStatementObject.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/TryStatementObject.java @@ -12,8 +12,8 @@ public class TryStatementObject extends CompositeStatementObject { private List catchClauses; private CompositeStatementObject finallyClause; - public TryStatementObject(CompilationUnit cu, String filePath, Statement statement, int depth) { - super(cu, filePath, statement, depth, CodeElementType.TRY_STATEMENT); + public TryStatementObject(CompilationUnit cu, String sourceFolder, String filePath, Statement statement, int depth) { + super(cu, sourceFolder, filePath, statement, depth, CodeElementType.TRY_STATEMENT); this.catchClauses = new ArrayList(); } diff --git a/src/main/java/gr/uom/java/xmi/decomposition/VariableDeclaration.java b/src/main/java/gr/uom/java/xmi/decomposition/VariableDeclaration.java index 32ea95ace2..c5a497946f 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/VariableDeclaration.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/VariableDeclaration.java @@ -47,7 +47,7 @@ public class VariableDeclaration implements LocationInfoProvider, VariableDeclar private List modifiers; private String actualSignature; - public VariableDeclaration(CompilationUnit cu, String filePath, VariableDeclarationFragment fragment, VariableDeclarationContainer container, String javaFileContent) { + public VariableDeclaration(CompilationUnit cu, String sourceFolder, String filePath, VariableDeclarationFragment fragment, VariableDeclarationContainer container, String javaFileContent) { this.annotations = new ArrayList(); this.modifiers = new ArrayList(); List extendedModifiers = null; @@ -80,23 +80,23 @@ else if(fragment.getParent() instanceof FieldDeclaration) { for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - this.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent)); + this.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent)); } else if(extendedModifier.isModifier()) { Modifier modifier = (Modifier)extendedModifier; - this.modifiers.add(new UMLModifier(cu, filePath, modifier)); + this.modifiers.add(new UMLModifier(cu, sourceFolder, filePath, modifier)); if(startSignatureOffset == -1) { startSignatureOffset = modifier.getStartPosition(); } } } } - this.locationInfo = new LocationInfo(cu, filePath, fragment, extractVariableDeclarationType(fragment)); + this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, fragment, extractVariableDeclarationType(fragment)); this.variableName = fragment.getName().getIdentifier(); - this.initializer = fragment.getInitializer() != null ? new AbstractExpression(cu, filePath, fragment.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent) : null; + this.initializer = fragment.getInitializer() != null ? new AbstractExpression(cu, sourceFolder, filePath, fragment.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent) : null; Type astType = extractType(fragment); if(astType != null) { - this.type = UMLType.extractTypeObject(cu, filePath, astType, fragment.getExtraDimensions(), javaFileContent); + this.type = UMLType.extractTypeObject(cu, sourceFolder, filePath, astType, fragment.getExtraDimensions(), javaFileContent); if(startSignatureOffset == -1) { startSignatureOffset = astType.getStartPosition(); } @@ -122,7 +122,7 @@ else if(extendedModifier.isModifier()) { this.actualSignature = javaFileContent.substring(startSignatureOffset, endSignatureOffset); } - public VariableDeclaration(CompilationUnit cu, String filePath, SingleVariableDeclaration fragment, VariableDeclarationContainer container, String javaFileContent) { + public VariableDeclaration(CompilationUnit cu, String sourceFolder, String filePath, SingleVariableDeclaration fragment, VariableDeclarationContainer container, String javaFileContent) { this.annotations = new ArrayList(); this.modifiers = new ArrayList(); int modifiers = fragment.getModifiers(); @@ -133,33 +133,33 @@ public VariableDeclaration(CompilationUnit cu, String filePath, SingleVariableDe for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - this.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent)); + this.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent)); } else if(extendedModifier.isModifier()) { Modifier modifier = (Modifier)extendedModifier; - this.modifiers.add(new UMLModifier(cu, filePath, modifier)); + this.modifiers.add(new UMLModifier(cu, sourceFolder, filePath, modifier)); } } - this.locationInfo = new LocationInfo(cu, filePath, fragment, extractVariableDeclarationType(fragment)); + this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, fragment, extractVariableDeclarationType(fragment)); this.variableName = fragment.getName().getIdentifier(); - this.initializer = fragment.getInitializer() != null ? new AbstractExpression(cu, filePath, fragment.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent) : null; + this.initializer = fragment.getInitializer() != null ? new AbstractExpression(cu, sourceFolder, filePath, fragment.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER, container, javaFileContent) : null; Type astType = extractType(fragment); - this.type = UMLType.extractTypeObject(cu, filePath, astType, fragment.getExtraDimensions(), javaFileContent); + this.type = UMLType.extractTypeObject(cu, sourceFolder, filePath, astType, fragment.getExtraDimensions(), javaFileContent); int startOffset = fragment.getStartPosition(); ASTNode scopeNode = getScopeNode(fragment); int endOffset = scopeNode.getStartPosition() + scopeNode.getLength(); this.scope = new VariableScope(cu, filePath, startOffset, endOffset); } - public VariableDeclaration(CompilationUnit cu, String filePath, SingleVariableDeclaration fragment, VariableDeclarationContainer container, boolean varargs, String javaFileContent) { - this(cu, filePath, fragment, container, javaFileContent); + public VariableDeclaration(CompilationUnit cu, String sourceFolder, String filePath, SingleVariableDeclaration fragment, VariableDeclarationContainer container, boolean varargs, String javaFileContent) { + this(cu, sourceFolder, filePath, fragment, container, javaFileContent); this.varargsParameter = varargs; if(varargs) { this.type.setVarargs(); } } - public VariableDeclaration(CompilationUnit cu, String filePath, EnumConstantDeclaration fragment, String javaFileContent) { + public VariableDeclaration(CompilationUnit cu, String sourceFolder, String filePath, EnumConstantDeclaration fragment, String javaFileContent) { this.annotations = new ArrayList(); this.modifiers = new ArrayList(); int modifiers = fragment.getModifiers(); @@ -172,17 +172,17 @@ public VariableDeclaration(CompilationUnit cu, String filePath, EnumConstantDecl for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; - this.annotations.add(new UMLAnnotation(cu, filePath, annotation, javaFileContent)); + this.annotations.add(new UMLAnnotation(cu, sourceFolder, filePath, annotation, javaFileContent)); } else if(extendedModifier.isModifier()) { Modifier modifier = (Modifier)extendedModifier; - this.modifiers.add(new UMLModifier(cu, filePath, modifier)); + this.modifiers.add(new UMLModifier(cu, sourceFolder, filePath, modifier)); if(startSignatureOffset == -1) { startSignatureOffset = modifier.getStartPosition(); } } } - this.locationInfo = new LocationInfo(cu, filePath, fragment, CodeElementType.ENUM_CONSTANT_DECLARATION); + this.locationInfo = new LocationInfo(cu, sourceFolder, filePath, fragment, CodeElementType.ENUM_CONSTANT_DECLARATION); this.variableName = fragment.getName().getIdentifier(); this.initializer = null; if(startSignatureOffset == -1) { diff --git a/src/main/java/gr/uom/java/xmi/decomposition/Visitor.java b/src/main/java/gr/uom/java/xmi/decomposition/Visitor.java index 98e762ac1f..87407a629f 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/Visitor.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/Visitor.java @@ -66,6 +66,7 @@ public class Visitor extends ASTVisitor { public static final Pattern METHOD_INVOCATION_PATTERN = Pattern.compile("!(\\w|\\.)*@\\w*"); public static final Pattern METHOD_SIGNATURE_PATTERN = Pattern.compile("(public|protected|private|static|\\s) +[\\w\\<\\>\\[\\]]+\\s+(\\w+) *\\([^\\)]*\\) *(\\{?|[^;])"); private CompilationUnit cu; + private String sourceFolder; private String filePath; private VariableDeclarationContainer container; private List variables = new ArrayList<>(); @@ -97,15 +98,16 @@ public class Visitor extends ASTVisitor { private DefaultMutableTreeNode current = root; private final String javaFileContent; - public Visitor(CompilationUnit cu, String filePath, VariableDeclarationContainer container, String javaFileContent) { + public Visitor(CompilationUnit cu, String sourceFolder, String filePath, VariableDeclarationContainer container, String javaFileContent) { this.cu = cu; + this.sourceFolder = sourceFolder; this.filePath = filePath; this.container = container; this.javaFileContent = javaFileContent; } public boolean visit(ArrayAccess node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.ARRAY_ACCESS, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.ARRAY_ACCESS, container); arrayAccesses.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -115,7 +117,7 @@ public boolean visit(ArrayAccess node) { } public boolean visit(PrefixExpression node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.PREFIX_EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.PREFIX_EXPRESSION, container); prefixExpressions.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -125,7 +127,7 @@ public boolean visit(PrefixExpression node) { } public boolean visit(PostfixExpression node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.POSTFIX_EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.POSTFIX_EXPRESSION, container); postfixExpressions.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -135,7 +137,7 @@ public boolean visit(PostfixExpression node) { } public boolean visit(ConditionalExpression node) { - TernaryOperatorExpression ternary = new TernaryOperatorExpression(cu, filePath, node, container, javaFileContent); + TernaryOperatorExpression ternary = new TernaryOperatorExpression(cu, sourceFolder, filePath, node, container, javaFileContent); ternaryOperatorExpressions.add(ternary); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -145,7 +147,7 @@ public boolean visit(ConditionalExpression node) { } public boolean visit(InfixExpression node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.INFIX_EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.INFIX_EXPRESSION, container); infixExpressions.add(expression); infixOperators.add(node.getOperator().toString()); if(current.getUserObject() != null) { @@ -157,7 +159,7 @@ public boolean visit(InfixExpression node) { } public boolean visit(Assignment node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.ASSIGNMENT, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.ASSIGNMENT, container); assignments.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -171,7 +173,7 @@ public boolean visit(ClassInstanceCreation node) { for(Expression argument : arguments) { processArgument(argument); } - ObjectCreation creation = new ObjectCreation(cu, filePath, node, container, javaFileContent); + ObjectCreation creation = new ObjectCreation(cu, sourceFolder, filePath, node, container, javaFileContent); creations.add(creation); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -181,7 +183,7 @@ public boolean visit(ClassInstanceCreation node) { } public boolean visit(ArrayCreation node) { - ObjectCreation creation = new ObjectCreation(cu, filePath, node, container, javaFileContent); + ObjectCreation creation = new ObjectCreation(cu, sourceFolder, filePath, node, container, javaFileContent); String nodeAsString = stringify(node); creations.add(creation); if(current.getUserObject() != null) { @@ -200,7 +202,7 @@ public boolean visit(ArrayCreation node) { public boolean visit(VariableDeclarationFragment node) { if(!(node.getParent() instanceof LambdaExpression)) { - VariableDeclaration variableDeclaration = new VariableDeclaration(cu, filePath, node, container, javaFileContent); + VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFolder, filePath, node, container, javaFileContent); variableDeclarations.add(variableDeclaration); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -211,7 +213,7 @@ public boolean visit(VariableDeclarationFragment node) { } public boolean visit(SingleVariableDeclaration node) { - VariableDeclaration variableDeclaration = new VariableDeclaration(cu, filePath, node, container, node.isVarargs(), javaFileContent); + VariableDeclaration variableDeclaration = new VariableDeclaration(cu, sourceFolder, filePath, node, container, node.isVarargs(), javaFileContent); variableDeclarations.add(variableDeclaration); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -306,7 +308,7 @@ private DefaultMutableTreeNode deleteNode(AnonymousClassDeclaration childAnonymo private DefaultMutableTreeNode insertNode(AnonymousClassDeclaration childAnonymous) { Enumeration enumeration = root.postorderEnumeration(); - AnonymousClassDeclarationObject anonymousObject = new AnonymousClassDeclarationObject(cu, filePath, childAnonymous); + AnonymousClassDeclarationObject anonymousObject = new AnonymousClassDeclarationObject(cu, sourceFolder, filePath, childAnonymous); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(anonymousObject); DefaultMutableTreeNode parentNode = root; @@ -346,7 +348,7 @@ private boolean isParent(ASTNode child, ASTNode parent) { } public boolean visit(TextBlock node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.TEXT_BLOCK, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.TEXT_BLOCK, container); textBlocks.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -356,7 +358,7 @@ public boolean visit(TextBlock node) { } public boolean visit(StringLiteral node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.STRING_LITERAL, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.STRING_LITERAL, container); stringLiterals.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -366,7 +368,7 @@ public boolean visit(StringLiteral node) { } public boolean visit(CharacterLiteral node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.CHAR_LITERAL, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.CHAR_LITERAL, container); charLiterals.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -376,7 +378,7 @@ public boolean visit(CharacterLiteral node) { } public boolean visit(NumberLiteral node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.NUMBER_LITERAL, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.NUMBER_LITERAL, container); numberLiterals.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -386,7 +388,7 @@ public boolean visit(NumberLiteral node) { } public boolean visit(NullLiteral node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.NULL_LITERAL, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.NULL_LITERAL, container); nullLiterals.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -396,7 +398,7 @@ public boolean visit(NullLiteral node) { } public boolean visit(BooleanLiteral node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.BOOLEAN_LITERAL, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.BOOLEAN_LITERAL, container); booleanLiterals.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -406,7 +408,7 @@ public boolean visit(BooleanLiteral node) { } public boolean visit(TypeLiteral node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.TYPE_LITERAL, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.TYPE_LITERAL, container); typeLiterals.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -417,7 +419,7 @@ public boolean visit(TypeLiteral node) { public boolean visit(ThisExpression node) { if(!(node.getParent() instanceof FieldAccess)) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.THIS_EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.THIS_EXPRESSION, container); thisExpressions.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -430,7 +432,7 @@ public boolean visit(ThisExpression node) { public boolean visit(SimpleName node) { if(node.getParent() instanceof FieldAccess && ((FieldAccess)node.getParent()).getExpression() instanceof ThisExpression) { FieldAccess fieldAccess = (FieldAccess)node.getParent(); - LeafExpression fieldAccessExpression = new LeafExpression(cu, filePath, fieldAccess, CodeElementType.FIELD_ACCESS, container); + LeafExpression fieldAccessExpression = new LeafExpression(cu, sourceFolder, filePath, fieldAccess, CodeElementType.FIELD_ACCESS, container); variables.add(fieldAccessExpression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -472,7 +474,7 @@ else if(node.getParent() instanceof QualifiedName && // skip names being part of qualified names } else { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.SIMPLE_NAME, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.SIMPLE_NAME, container); variables.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -542,7 +544,7 @@ public boolean visit(MethodInvocation node) { for(Expression argument : arguments) { processArgument(argument); } - OperationInvocation invocation = new OperationInvocation(cu, filePath, node, container); + OperationInvocation invocation = new OperationInvocation(cu, sourceFolder, filePath, node, container); methodInvocations.add(invocation); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -552,7 +554,7 @@ public boolean visit(MethodInvocation node) { } public boolean visit(ExpressionMethodReference node) { - MethodReference reference = new MethodReference(cu, filePath, node, container); + MethodReference reference = new MethodReference(cu, sourceFolder, filePath, node, container); methodInvocations.add(reference); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -562,7 +564,7 @@ public boolean visit(ExpressionMethodReference node) { } public boolean visit(SuperMethodReference node) { - MethodReference reference = new MethodReference(cu, filePath, node, container); + MethodReference reference = new MethodReference(cu, sourceFolder, filePath, node, container); methodInvocations.add(reference); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -572,7 +574,7 @@ public boolean visit(SuperMethodReference node) { } public boolean visit(TypeMethodReference node) { - MethodReference reference = new MethodReference(cu, filePath, node, container, javaFileContent); + MethodReference reference = new MethodReference(cu, sourceFolder, filePath, node, container, javaFileContent); methodInvocations.add(reference); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -614,7 +616,7 @@ public boolean visit(SuperMethodInvocation node) { for(Expression argument : arguments) { processArgument(argument); } - OperationInvocation invocation = new OperationInvocation(cu, filePath, node, container); + OperationInvocation invocation = new OperationInvocation(cu, sourceFolder, filePath, node, container); methodInvocations.add(invocation); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -628,7 +630,7 @@ public boolean visit(SuperConstructorInvocation node) { for(Expression argument : arguments) { processArgument(argument); } - OperationInvocation invocation = new OperationInvocation(cu, filePath, node, container); + OperationInvocation invocation = new OperationInvocation(cu, sourceFolder, filePath, node, container); methodInvocations.add(invocation); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -642,7 +644,7 @@ public boolean visit(ConstructorInvocation node) { for(Expression argument : arguments) { processArgument(argument); } - OperationInvocation invocation = new OperationInvocation(cu, filePath, node, container); + OperationInvocation invocation = new OperationInvocation(cu, sourceFolder, filePath, node, container); methodInvocations.add(invocation); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -664,7 +666,7 @@ private void processArgument(Expression argument) { castExpressionInParenthesizedExpression(argument)) return; if(argument instanceof ExpressionMethodReference) { - LambdaExpressionObject lambda = new LambdaExpressionObject(cu, filePath, (ExpressionMethodReference)argument, container, javaFileContent); + LambdaExpressionObject lambda = new LambdaExpressionObject(cu, sourceFolder, filePath, (ExpressionMethodReference)argument, container, javaFileContent); lambdas.add(lambda); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -672,7 +674,7 @@ private void processArgument(Expression argument) { } } else if(argument instanceof SuperMethodReference) { - LambdaExpressionObject lambda = new LambdaExpressionObject(cu, filePath, (SuperMethodReference)argument, container, javaFileContent); + LambdaExpressionObject lambda = new LambdaExpressionObject(cu, sourceFolder, filePath, (SuperMethodReference)argument, container, javaFileContent); lambdas.add(lambda); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -680,14 +682,14 @@ else if(argument instanceof SuperMethodReference) { } } else if(argument instanceof TypeMethodReference) { - LambdaExpressionObject lambda = new LambdaExpressionObject(cu, filePath, (TypeMethodReference)argument, container, javaFileContent); + LambdaExpressionObject lambda = new LambdaExpressionObject(cu, sourceFolder, filePath, (TypeMethodReference)argument, container, javaFileContent); lambdas.add(lambda); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); anonymous.getLambdas().add(lambda); } } - LeafExpression expression = new LeafExpression(cu, filePath, argument, CodeElementType.EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, argument, CodeElementType.EXPRESSION, container); this.arguments.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -716,7 +718,7 @@ public boolean visit(QualifiedName node) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); anonymous.getTypes().add(qualifier.getFullyQualifiedName()); } - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.QUALIFIED_NAME, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.QUALIFIED_NAME, container); variables.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -724,7 +726,7 @@ public boolean visit(QualifiedName node) { } } else if(qualifier instanceof SimpleName && !(node.getParent() instanceof QualifiedName)) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.QUALIFIED_NAME, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.QUALIFIED_NAME, container); variables.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -732,7 +734,7 @@ else if(qualifier instanceof SimpleName && !(node.getParent() instanceof Qualifi } } else if(qualifier instanceof QualifiedName && !(node.getParent() instanceof QualifiedName)) { - LeafExpression expression = new LeafExpression(cu, filePath, qualifier, CodeElementType.QUALIFIED_NAME, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, qualifier, CodeElementType.QUALIFIED_NAME, container); variables.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -745,14 +747,14 @@ else if(qualifier instanceof QualifiedName && !(node.getParent() instanceof Qual public boolean visit(CastExpression node) { Expression castExpression = node.getExpression(); if(castExpression instanceof SimpleName) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.CAST_EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.CAST_EXPRESSION, container); variables.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); anonymous.getVariables().add(expression); } } - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.CAST_EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.CAST_EXPRESSION, container); castExpressions.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -762,7 +764,7 @@ public boolean visit(CastExpression node) { } public boolean visit(LambdaExpression node) { - LambdaExpressionObject lambda = new LambdaExpressionObject(cu, filePath, node, container, javaFileContent); + LambdaExpressionObject lambda = new LambdaExpressionObject(cu, sourceFolder, filePath, node, container, javaFileContent); lambdas.add(lambda); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -775,7 +777,7 @@ public boolean visit(SwitchExpression node) { List statements = node.statements(); for(Statement statement : statements) { if(statement instanceof Block) { - LambdaExpressionObject lambda = new LambdaExpressionObject(cu, filePath, statement, container, javaFileContent); + LambdaExpressionObject lambda = new LambdaExpressionObject(cu, sourceFolder, filePath, statement, container, javaFileContent); lambdas.add(lambda); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); @@ -787,7 +789,7 @@ public boolean visit(SwitchExpression node) { } public boolean visit(ParenthesizedExpression node) { - LeafExpression expression = new LeafExpression(cu, filePath, node, CodeElementType.PARENTHESIZED_EXPRESSION, container); + LeafExpression expression = new LeafExpression(cu, sourceFolder, filePath, node, CodeElementType.PARENTHESIZED_EXPRESSION, container); parenthesizedExpressions.add(expression); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); diff --git a/src/test/java/org/refactoringminer/test/TestParameterizeTestRefactoring.java b/src/test/java/org/refactoringminer/test/TestParameterizeTestRefactoring.java index b17931b59a..8351cc55ab 100644 --- a/src/test/java/org/refactoringminer/test/TestParameterizeTestRefactoring.java +++ b/src/test/java/org/refactoringminer/test/TestParameterizeTestRefactoring.java @@ -553,7 +553,7 @@ private static UMLModel createUmlModel(String sourceCode) { UMLModel model = new UMLModelASTReader(javaFileContents, Set.of("."), false).getUmlModel(); ASTNode node = (ASTNode) cu; assertNotNull(node); - LocationInfo location = new LocationInfo(cu, "TestClass.java", node, LocationInfo.CodeElementType.TYPE_DECLARATION); + LocationInfo location = new LocationInfo(cu, "", "TestClass.java", node, LocationInfo.CodeElementType.TYPE_DECLARATION); UMLClass aClass = new UMLClass("org.refactoringminer.test", "TestClass", location, true, Collections.emptyList()); aClass.setVisibility(Visibility.PUBLIC); return model;