diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b7ddd9f2..9ba6f398 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,10 +24,10 @@ jobs: os: [ ubuntu-latest, macos-latest ] steps: - - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac with: fetch-depth: 2 - - uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3 + - uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 with: java-version: 11 java-package: jdk @@ -40,7 +40,7 @@ jobs: run: echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")" shell: bash - name: Use Maven dependency cache - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: ~/.m2/repository key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }} @@ -51,7 +51,7 @@ jobs: - name: Run tests run: mvn test - name: Upload coverage report to Codecov - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d with: fail_ci_if_error: false @@ -60,16 +60,16 @@ jobs: if: ${{ github.ref == 'refs/heads/master' }} steps: - - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac with: fetch-depth: 0 # fetch everything - - uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3 + - uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 with: java-version: 11 java-package: jdk architecture: x64 distribution: ${{ env.JAVA_DISTRIBUTION }} - - uses: actions/setup-python@b55428b1882923874294fa556849718a1d7f2ca5 + - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 with: python-version: 3.8 @@ -78,7 +78,7 @@ jobs: run: echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")" shell: bash - name: Use Maven dependency cache - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: ~/.m2/repository key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }} @@ -95,10 +95,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac with: fetch-depth: 0 # fetch everything - - uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3 + - uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 with: java-version: 11 java-package: jdk @@ -110,7 +110,7 @@ jobs: run: echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")" shell: bash - name: Use Maven dependency cache - uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: ~/.m2/repository key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }} diff --git a/pom.xml b/pom.xml index 28bc4cc1..d15b41e7 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ ch.qos.logback logback-classic - 1.2.11 + 1.4.11 @@ -100,7 +100,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.3.0 + 3.5.0 package @@ -246,7 +246,7 @@ com.diffplug.spotless spotless-maven-plugin - 2.21.0 + 2.39.0 @@ -254,7 +254,7 @@ src/test/java/**/*.java - 1.9 + 1.17.0 @@ -265,7 +265,11 @@ src/test/kotlin/**/*.kt - 0.37.2 + 0.48.0 + + true + true + diff --git a/src/main/java/se/kth/spork/spoon/printer/OperatorHelper.java b/src/main/java/se/kth/spork/spoon/printer/OperatorHelper.java index 5192956c..091c547b 100644 --- a/src/main/java/se/kth/spork/spoon/printer/OperatorHelper.java +++ b/src/main/java/se/kth/spork/spoon/printer/OperatorHelper.java @@ -48,7 +48,9 @@ public static String getOperatorText(Object o) { } } - /** @return java source code representation of a pre or post unary operator. */ + /** + * @return java source code representation of a pre or post unary operator. + */ public static String getOperatorText(UnaryOperatorKind o) { switch (o) { case POS: @@ -72,7 +74,9 @@ public static String getOperatorText(UnaryOperatorKind o) { } } - /** @return java source code representation of a binary operator. */ + /** + * @return java source code representation of a binary operator. + */ public static String getOperatorText(BinaryOperatorKind o) { switch (o) { case OR: diff --git a/src/main/kotlin/se/kth/spork/base3dm/TdmMerge.kt b/src/main/kotlin/se/kth/spork/base3dm/TdmMerge.kt index 3c961485..a28b4d6d 100644 --- a/src/main/kotlin/se/kth/spork/base3dm/TdmMerge.kt +++ b/src/main/kotlin/se/kth/spork/base3dm/TdmMerge.kt @@ -26,8 +26,10 @@ private val LOGGER: LazyLogger = LazyLogger(Object::class.java) */ fun resolveRawMerge(base: ChangeSet, delta: ChangeSet) { for (pcs in delta.pcsSet) { - if (!delta.contains(pcs)) // was removed as otherPcs + if (!delta.contains(pcs)) { + // was removed as otherPcs continue + } // We need to merge the content of the predecessor and successor, but we can skip the parent. // The reason is that a parent node that never appears as a predecessor or successor will never be diff --git a/src/main/kotlin/se/kth/spork/spoon/contentresolver.kt b/src/main/kotlin/se/kth/spork/spoon/ContentResolver.kt similarity index 97% rename from src/main/kotlin/se/kth/spork/spoon/contentresolver.kt rename to src/main/kotlin/se/kth/spork/spoon/ContentResolver.kt index b9b0ae15..cd687a36 100644 --- a/src/main/kotlin/se/kth/spork/spoon/contentresolver.kt +++ b/src/main/kotlin/se/kth/spork/spoon/ContentResolver.kt @@ -74,7 +74,8 @@ private fun getContent(elem: CtElement): RoledValues { if (elem is CtComment) { val rawContent = elem.rawContent val content = RoledValue( - CtRole.COMMENT_CONTENT, elem.getValueByRole(CtRole.COMMENT_CONTENT) + CtRole.COMMENT_CONTENT, + elem.getValueByRole(CtRole.COMMENT_CONTENT), ) content.putMetadata(RoledValue.Key.RAW_CONTENT, rawContent) rvs.add(content) diff --git a/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt b/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt index 5769fa9b..014380ac 100644 --- a/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt +++ b/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt @@ -85,7 +85,7 @@ object Spoon3dmMerge { left: T, right: T, baseMatcher: (ITree, ITree) -> Matcher, - leftRightMatcher: (ITree, ITree) -> Matcher + leftRightMatcher: (ITree, ITree) -> Matcher, ): Pair { val start = System.nanoTime() @@ -106,7 +106,12 @@ object Spoon3dmMerge { // 3DM PHASE LOGGER.info { "Mapping nodes to class representatives" } var classRepMap = createClassRepresentativesMapping( - base, left, right, baseLeft, baseRight, leftRight + base, + left, + right, + baseLeft, + baseRight, + leftRight, ) LOGGER.info { "Converting Spoon trees to PCS triples" } val t0 = PcsBuilder.fromSpoon(base, Revision.BASE) @@ -114,10 +119,16 @@ object Spoon3dmMerge { val t2 = PcsBuilder.fromSpoon(right, Revision.RIGHT) LOGGER.info { "Computing raw PCS merge" } var delta = ChangeSet( - classRepMap, ::getContent, t0, t1, t2 + classRepMap, + ::getContent, + t0, + t1, + t2, ) val t0Star = ChangeSet( - classRepMap, ::getContent, t0 + classRepMap, + ::getContent, + t0, ) LOGGER.info { "Resolving final PCS merge" } resolveRawMerge(t0Star, delta) @@ -126,11 +137,19 @@ object Spoon3dmMerge { LOGGER.info { "Root conflicts detected, restarting merge" } LOGGER.info { "Removing root conflicting nodes from tree matchings" } removeFromMappings( - rootConflictingNodes, baseLeft, baseRight, leftRight + rootConflictingNodes, + baseLeft, + baseRight, + leftRight, ) LOGGER.info { "Mapping nodes to class representatives" } classRepMap = createClassRepresentativesMapping( - base, left, right, baseLeft, baseRight, leftRight + base, + left, + right, + baseLeft, + baseRight, + leftRight, ) LOGGER.info { "Computing raw PCS merge" } delta = ChangeSet(classRepMap, ::getContent, t0, t1, t2) @@ -141,31 +160,35 @@ object Spoon3dmMerge { // INTERPRETER PHASE LOGGER.info { "Interpreting resolved PCS merge" } val structuralConflictHandlers = Arrays.asList( - MethodOrderingConflictHandler(), OptimisticInsertInsertHandler() + MethodOrderingConflictHandler(), + OptimisticInsertInsertHandler(), ) val contentConflictHandlers = Arrays.asList( IsImplicitHandler(), ModifierHandler(), IsUpperHandler(), - CommentContentHandler() + CommentContentHandler(), ) val merge = fromMergedPcs( delta, baseLeft, baseRight, structuralConflictHandlers, - contentConflictHandlers + contentConflictHandlers, ) + // we can be certain that the merge tree has the same root type as the three constituents, // so this cast is safe - @Suppress("UNCHECKED_CAST") val mergeTree = merge.first as T + @Suppress("UNCHECKED_CAST") + val mergeTree = merge.first as T val numConflicts = merge.second val metadataElementConflicts = mergeMetadataElements(mergeTree, base, left, right) LOGGER.info { "Checking for duplicated members" } val duplicateMemberConflicts = eliminateDuplicateMembers(mergeTree) LOGGER.info { "Merged in " + (System.nanoTime() - start).toDouble() / 1e9 + " seconds" } return Pair( - mergeTree, numConflicts + metadataElementConflicts + duplicateMemberConflicts + mergeTree, + numConflicts + metadataElementConflicts + duplicateMemberConflicts, ) } @@ -190,7 +213,7 @@ object Spoon3dmMerge { mergeTree: CtElement, base: CtElement, left: CtElement, - right: CtElement + right: CtElement, ): Int { var numConflicts = 0 if (base.getMetadata(Parser.IMPORT_STATEMENTS) != null) { @@ -261,7 +284,7 @@ object Spoon3dmMerge { left, right, ::matchTrees, - ::matchTrees + ::matchTrees, ) numConflicts += mergePair.second val mergedMember = mergePair.first @@ -271,7 +294,8 @@ object Spoon3dmMerge { // badness in the Spoon API: addTypeMember returns a generic type that depends only on the // static type of the returned expression. So we must store the returned expression and declare // the type, or Kotlin gets grumpy. - @Suppress("UNUSED_VARIABLE") val dontcare: CtType<*> = type.addTypeMember(mergedMember) + @Suppress("UNUSED_VARIABLE") + val dontcare: CtType<*> = type.addTypeMember(mergedMember) } return numConflicts @@ -285,7 +309,7 @@ object Spoon3dmMerge { private fun mergeCuComments( base: CtElement, left: CtElement, - right: CtElement + right: CtElement, ): Pair { val baseComment = getCuComment(base) val leftComment = getCuComment(left) @@ -312,7 +336,7 @@ object Spoon3dmMerge { private fun mergeImportStatements( base: CtElement, left: CtElement, - right: CtElement + right: CtElement, ): List { val baseImports = HashSet(base.getMetadata(Parser.IMPORT_STATEMENTS) as Collection) val leftImports = HashSet(left.getMetadata(Parser.IMPORT_STATEMENTS) as Collection) diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/CommentContentHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/CommentContentHandler.kt index 8f5ae897..49c71d8b 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/CommentContentHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/CommentContentHandler.kt @@ -19,14 +19,17 @@ class CommentContentHandler : ContentConflictHandler { rightVal: Any, baseElem: CtElement?, leftElem: CtElement, - rightElem: CtElement + rightElem: CtElement, ): Pair { return Pair(mergeComments(baseVal ?: "", leftVal, rightVal), false) } private fun mergeComments(base: Any, left: Any, right: Any): Any? { val merge = lineBasedMerge(base.toString(), left.toString(), right.toString()) - return if (merge.second > 0) null - else merge.first + return if (merge.second > 0) { + null + } else { + merge.first + } } } diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflict.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflict.kt index c72e84d7..42328976 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflict.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflict.kt @@ -7,7 +7,7 @@ class ContentConflict( val role: CtRole, val base: RoledValue?, val left: RoledValue, - val right: RoledValue + val right: RoledValue, ) { companion object { diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflictHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflictHandler.kt index 12e853ce..889cfcb0 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflictHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/ContentConflictHandler.kt @@ -38,7 +38,7 @@ interface ContentConflictHandler { rightVal: Any, baseElem: CtElement?, leftElem: CtElement, - rightElem: CtElement + rightElem: CtElement, ): Pair /** @return The role that this conflict handler deals with. diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/ContentMerger.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/ContentMerger.kt index 03952d26..eb956d0a 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/ContentMerger.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/ContentMerger.kt @@ -23,7 +23,7 @@ class ContentMerger(conflictHandlers: List) { * @return A pair of merged contents and a potentially empty collection of unresolved conflicts. */ fun mergedContent( - nodeContents: Set> + nodeContents: Set>, ): Pair> { if (nodeContents.size == 1) { return Pair(nodeContents.iterator().next().value, emptyList()) @@ -60,8 +60,8 @@ class ContentMerger(conflictHandlers: List) { role, baseRoledValues?.get(i), leftRv, - rightRv - ) + rightRv, + ), ) var merged: Any? = null @@ -84,7 +84,7 @@ class ContentMerger(conflictHandlers: List) { rightVal, baseRoledValues?.element, leftRoledValues.element, - rightRoledValues.element + rightRoledValues.element, ) merged = result.first conflictPresent = result.second @@ -100,7 +100,7 @@ class ContentMerger(conflictHandlers: List) { companion object { private fun getContentRevisions( - contents: Set> + contents: Set>, ): Triple?, Content, Content> { var base: Content? = null var left: Content? = null diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/IsImplicitHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/IsImplicitHandler.kt index c2f5d05f..19e1cbd4 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/IsImplicitHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/IsImplicitHandler.kt @@ -19,7 +19,7 @@ class IsImplicitHandler : ContentConflictHandler { rightVal: Any, baseElem: CtElement?, leftElem: CtElement, - rightElem: CtElement + rightElem: CtElement, ): Pair { val mergedValue = if (baseVal != null) { // as there are only two possible values for a boolean, left and right disagreeing must diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/IsUpperHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/IsUpperHandler.kt index 2e1ed4de..6a18b7ba 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/IsUpperHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/IsUpperHandler.kt @@ -21,7 +21,7 @@ class IsUpperHandler : ContentConflictHandler { rightVal: Any, baseElem: CtElement?, leftElem: CtElement, - rightElem: CtElement + rightElem: CtElement, ): Pair { return Pair(mergeIsUpper(baseElem, leftElem, rightElem), false) } @@ -30,7 +30,7 @@ class IsUpperHandler : ContentConflictHandler { private fun mergeIsUpper( baseElem: CtElement?, leftElem: CtElement, - rightElem: CtElement + rightElem: CtElement, ): Any? { val left = leftElem as CtWildcardReference val right = rightElem as CtWildcardReference diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/MethodOrderingConflictHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/MethodOrderingConflictHandler.kt index d68de28b..e6d1b2ed 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/MethodOrderingConflictHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/MethodOrderingConflictHandler.kt @@ -13,7 +13,7 @@ class MethodOrderingConflictHandler : StructuralConflictHandler { override fun tryResolveConflict( leftNodes: List, rightNodes: List, - type: ConflictType + type: ConflictType, ): List? { // we currently don't care about the type but it could be relevant in the future if (type != ConflictType.INSERT_INSERT) { diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/ModifierHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/ModifierHandler.kt index 0f8186f7..556aeddc 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/ModifierHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/ModifierHandler.kt @@ -24,12 +24,12 @@ class ModifierHandler : ContentConflictHandler { rightVal: Any, baseElem: CtElement?, leftElem: CtElement, - rightElem: CtElement + rightElem: CtElement, ): Pair { return mergeModifierKinds( (baseVal ?: setOf()) as Set, leftVal as Set, - rightVal as Set + rightVal as Set, ) } @@ -83,7 +83,7 @@ class ModifierHandler : ContentConflictHandler { private fun mergeModifierKinds( base: Set, left: Set, - right: Set + right: Set, ): Pair { val modifiers = base + left + right val baseVis = getVisibility(base) @@ -120,7 +120,7 @@ class ModifierHandler : ContentConflictHandler { val isDeleted = { m: ModifierKind -> m in base && ((m in left) xor (m in right)) } val mods = (visibility + keywords + other).filter { - mod -> + mod -> isInLeftAndRight(mod) || !isDeleted(mod) }.toSet() return Pair(mods, conflict) diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/OptimisticInsertInsertHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/OptimisticInsertInsertHandler.kt index 42e5bdcd..a67f379d 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/OptimisticInsertInsertHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/OptimisticInsertInsertHandler.kt @@ -12,10 +12,14 @@ class OptimisticInsertInsertHandler : StructuralConflictHandler { override fun tryResolveConflict( leftNodes: List, rightNodes: List, - type: ConflictType + type: ConflictType, ): List? { - return if (leftNodes.isNotEmpty() && rightNodes.isNotEmpty() || type != ConflictType.INSERT_INSERT) null - else if (leftNodes.isNotEmpty()) leftNodes - else rightNodes + return if (leftNodes.isNotEmpty() && rightNodes.isNotEmpty() || type != ConflictType.INSERT_INSERT) { + null + } else if (leftNodes.isNotEmpty()) { + leftNodes + } else { + rightNodes + } } } diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflict.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflict.kt index 653cf401..3f9905c5 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflict.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflict.kt @@ -33,7 +33,7 @@ class StructuralConflict { base: CtElement?, left: CtElement, right: CtElement, - lineBasedMerge: String + lineBasedMerge: String, ) { this.base = if (base != null) listOf(base) else null this.left = listOf(left) @@ -70,7 +70,7 @@ class StructuralConflict { } fun extractRootConflictingNodes( - structuralConflicts: Map, Set>> + structuralConflicts: Map, Set>>, ): Set { val toIgnore: MutableSet = HashSet() for ((pcs, value) in structuralConflicts) { diff --git a/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflictHandler.kt b/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflictHandler.kt index a3b90b3e..379b370b 100644 --- a/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflictHandler.kt +++ b/src/main/kotlin/se/kth/spork/spoon/conflict/StructuralConflictHandler.kt @@ -22,6 +22,6 @@ interface StructuralConflictHandler { fun tryResolveConflict( leftNodes: List, rightNodes: List, - type: ConflictType + type: ConflictType, ): List? } diff --git a/src/main/kotlin/se/kth/spork/spoon/matching/ClassRepresentatives.kt b/src/main/kotlin/se/kth/spork/spoon/matching/ClassRepresentatives.kt index c0d6512e..b73708f7 100644 --- a/src/main/kotlin/se/kth/spork/spoon/matching/ClassRepresentatives.kt +++ b/src/main/kotlin/se/kth/spork/spoon/matching/ClassRepresentatives.kt @@ -36,7 +36,7 @@ fun createClassRepresentativesMapping( right: CtElement, baseLeft: SpoonMapping, baseRight: SpoonMapping, - leftRight: SpoonMapping + leftRight: SpoonMapping, ): Map { val classRepMap = initializeClassRepresentatives(base) mapToClassRepresentatives(left, baseLeft, classRepMap, Revision.LEFT) diff --git a/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt b/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt index 5935ffe6..1e54a7e5 100644 --- a/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt +++ b/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt @@ -204,7 +204,9 @@ class SpoonMapping private constructor() { private fun isPrimitiveType(elem: CtElement): Boolean { return if (elem is CtTypeInformation) { (elem as CtTypeInformation).isPrimitive - } else false + } else { + false + } } private fun isAnnotationValue(elem: CtElement): Boolean { diff --git a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/PcsInterpreter.kt b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/PcsInterpreter.kt index ab548c3b..6ce4a78f 100644 --- a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/PcsInterpreter.kt +++ b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/PcsInterpreter.kt @@ -22,7 +22,7 @@ fun fromMergedPcs( baseLeft: SpoonMapping, baseRight: SpoonMapping, structuralConflictHandlers: List, - contentConflictHandlers: List + contentConflictHandlers: List, ): Pair { val sporkTreeBuilder = SporkTreeBuilder(delta, baseLeft, baseRight, structuralConflictHandlers) val sporkTreeRoot = sporkTreeBuilder.buildTree() @@ -38,6 +38,6 @@ fun fromMergedPcs( val spoonTreeRoot = spoonTreeBuilder.build(sporkTreeRoot) return Pair( spoonTreeRoot, - sporkTreeBuilder.numStructuralConflicts() + spoonTreeBuilder.numContentConflicts + sporkTreeBuilder.numStructuralConflicts() + spoonTreeBuilder.numContentConflicts, ) } diff --git a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SpoonTreeBuilder.kt b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SpoonTreeBuilder.kt index 13b81710..8909e3af 100644 --- a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SpoonTreeBuilder.kt +++ b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SpoonTreeBuilder.kt @@ -42,7 +42,7 @@ class SpoonTreeBuilder internal constructor( private val baseLeft: SpoonMapping, private val baseRight: SpoonMapping, oldEnv: Environment, - contentConflictHandlers: List + contentConflictHandlers: List, ) { var numContentConflicts: Int = 0 private set @@ -91,7 +91,9 @@ class SpoonTreeBuilder internal constructor( if (root.node === virtualRoot || !child.isSingleRevisionSubtree - ) build(child) + ) { + build(child) + } } return lastChild } @@ -193,7 +195,7 @@ class SpoonTreeBuilder internal constructor( originalTree: CtElement, mergeParent: CtElement, mergeTree: CtElement, - mergeTreeRole: CtRole + mergeTreeRole: CtRole, ): Any { val siblings = mergeParent.getValueByRole(mergeTreeRole) val inserted: Any = when (siblings) { @@ -308,7 +310,7 @@ class SpoonTreeBuilder internal constructor( private fun resolveAnnotationMap( mergeTree: CtElement, siblings: Map<*, *>, - originalTree: CtElement + originalTree: CtElement, ): Map<*, *> { val mutableCurrent: MutableMap = TreeMap(siblings) val annotation = originalTree.parent as CtAnnotation<*> @@ -355,7 +357,9 @@ class SpoonTreeBuilder internal constructor( init { setSporkEnvironment( - factory.environment, oldEnv.tabulationSize, oldEnv.isUsingTabulations + factory.environment, + oldEnv.tabulationSize, + oldEnv.isUsingTabulations, ) } } diff --git a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTree.kt b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTree.kt index 45f84537..89194602 100644 --- a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTree.kt +++ b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTree.kt @@ -22,7 +22,7 @@ import kotlin.jvm.JvmOverloads class SporkTree @JvmOverloads constructor( val node: SpoonNode, val content: Set>, - val structuralConflict: StructuralConflict? = null + val structuralConflict: StructuralConflict? = null, ) { private val _children: MutableList = mutableListOf() val children: List diff --git a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTreeBuilder.kt b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTreeBuilder.kt index 4fffd714..4f7f4e4a 100644 --- a/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTreeBuilder.kt +++ b/src/main/kotlin/se/kth/spork/spoon/pcsinterpreter/SporkTreeBuilder.kt @@ -32,7 +32,7 @@ internal class SporkTreeBuilder( private val delta: ChangeSet, private val baseLeft: SpoonMapping, private val baseRight: SpoonMapping, - private val conflictHandlers: List + private val conflictHandlers: List, ) { private val rootToChildren: Map>> = buildRootToChildren(delta.pcsSet) private val contents: Map>> = delta.contents @@ -49,14 +49,16 @@ internal class SporkTreeBuilder( /** Try to resolve a structural conflict automatically. */ private fun tryResolveConflict( leftNodes: List, - rightNodes: List + rightNodes: List, ): List? { // we can currently only resolve conflict lists for insert/insert conflicts // TODO Expand conflict handling to deal with more than just insert/insert val conflictType = ConflictType.INSERT_INSERT return conflictHandlers.mapNotNull { handler: StructuralConflictHandler -> handler.tryResolveConflict( - leftNodes, rightNodes, conflictType + leftNodes, + rightNodes, + conflictType, ) }.firstOrNull() } @@ -83,8 +85,10 @@ internal class SporkTreeBuilder( val children: Map>? = rootToChildren[currentRoot] val currentContent = contents[currentRoot] ?: emptySet() var tree = SporkTree(currentRoot, currentContent) - if (children == null) // leaf node + if (children == null) { + // leaf node return tree + } try { build(currentRoot.startOfChildList, tree, children) for (inconsistent in remainingInconsistencies) { @@ -121,8 +125,10 @@ internal class SporkTreeBuilder( } private fun build(start: SpoonNode, tree: SporkTree, children: Map>?) { - if (children == null) // leaf node + if (children == null) { + // leaf node return + } var next: SpoonNode? = start while (true) { val nextPcs = children[next]!! @@ -155,7 +161,8 @@ internal class SporkTreeBuilder( private fun getSuccessorConflict(pcs: Pcs): Pcs? = delta.structuralConflicts[pcs]?.firstOrNull { isSuccessorConflict( - pcs, it + pcs, + it, ) } @@ -190,11 +197,16 @@ internal class SporkTreeBuilder( } } val (first, second) = lineBasedMerge( - base.element, left!!.element, right!!.element + base.element, + left!!.element, + right!!.element, ) numStructuralConflicts += second return StructuralConflict( - base.element, left.element, right.element, first + base.element, + left.element, + right.element, + first, ) } @@ -202,7 +214,7 @@ internal class SporkTreeBuilder( nextPcs: Pcs, conflicting: Pcs, children: Map>, - tree: SporkTree + tree: SporkTree, ): SpoonNode { remainingInconsistencies.remove(nextPcs) remainingInconsistencies.remove(conflicting) @@ -225,7 +237,7 @@ internal class SporkTreeBuilder( .collect(Collectors.toList()), rightNodes.stream() .map(SpoonNode::element) - .collect(Collectors.toList()) + .collect(Collectors.toList()), ) // next is used as a dummy node here, so it should not be added to usedNodes tree.addChild(SporkTree(next, contents[next]!!, conflict)) @@ -250,7 +262,7 @@ internal class SporkTreeBuilder( */ private fun extractConflictList( pcs: Pcs, - siblings: Map> + siblings: Map>, ): List { var currentPcs = pcs val nodes: MutableList = mutableListOf() @@ -261,7 +273,8 @@ internal class SporkTreeBuilder( val predConflict = conflicts.stream() .filter { isPredecessorConflict( - finalPcs, it + finalPcs, + it, ) } .findFirst() @@ -271,9 +284,11 @@ internal class SporkTreeBuilder( } } val nextNode = currentPcs.successor - if (nextNode.isEndOfList) throw ConflictException( - "Reached the end of the child list without finding a predecessor conflict" - ) + if (nextNode.isEndOfList) { + throw ConflictException( + "Reached the end of the child list without finding a predecessor conflict", + ) + } nodes.add(nextNode) currentPcs = siblings[nextNode]!! } @@ -282,7 +297,7 @@ internal class SporkTreeBuilder( companion object { private val LOGGER = LazyLogger(SporkTreeBuilder::class.java) private fun buildRootToChildren( - pcses: Set> + pcses: Set>, ): Map>> { val rootToChildren: MutableMap>> = HashMap() for (pcs in pcses) { diff --git a/src/main/kotlin/se/kth/spork/spoon/wrappers/NodeFactory.kt b/src/main/kotlin/se/kth/spork/spoon/wrappers/NodeFactory.kt index f5cc0b51..9340a6d7 100644 --- a/src/main/kotlin/se/kth/spork/spoon/wrappers/NodeFactory.kt +++ b/src/main/kotlin/se/kth/spork/spoon/wrappers/NodeFactory.kt @@ -43,11 +43,13 @@ object NodeFactory { CtRole.BODY, // always present as a single node CtRole.NESTED_TYPE, // falls under type member CtRole.FIELD, // falls under type member - CtRole.METHOD // falls under type member + CtRole.METHOD, // falls under type member ) private val EXPLODED_TYPES = Arrays.asList( - CtExecutableReference::class.java, CtExecutable::class.java, CtType::class.java + CtExecutableReference::class.java, + CtExecutable::class.java, + CtType::class.java, ) private var EXPLODED_TYPE_ROLES: Map, List> = EXPLODED_TYPES.map { it to getRoles(it).filter { it !in IGNORED_ROLES } @@ -112,8 +114,9 @@ object NodeFactory { } private fun initializeWrapper(elem: CtElement): Node { - if (elem is CtUnnamedModule) + if (elem is CtUnnamedModule) { return initializeWrapper(elem, virtualRoot) + } val spoonParent = elem.parent val roleInParent = elem.roleInParent val actualParent = wrapInternal(spoonParent) @@ -272,7 +275,7 @@ object NodeFactory { */ private class ListEdge internal constructor( // the parent of the child list override val parent: SpoonNode, - private val side: Side + private val side: Side, ) : SpoonNode { enum class Side { START, END diff --git a/src/main/kotlin/se/kth/spork/spoon/wrappers/RoledValue.kt b/src/main/kotlin/se/kth/spork/spoon/wrappers/RoledValue.kt index 5f2f4371..616c09c8 100644 --- a/src/main/kotlin/se/kth/spork/spoon/wrappers/RoledValue.kt +++ b/src/main/kotlin/se/kth/spork/spoon/wrappers/RoledValue.kt @@ -8,7 +8,7 @@ class RoledValue(val role: CtRole, val value: Any?) { private val metadata: MutableMap = EnumMap(se.kth.spork.spoon.wrappers.RoledValue.Key::class.java) enum class Key { - RAW_CONTENT + RAW_CONTENT, } fun putMetadata(key: Key, value: Any) { diff --git a/src/main/kotlin/se/kth/spork/util/LineBasedMerge.kt b/src/main/kotlin/se/kth/spork/util/LineBasedMerge.kt index 183d839b..c10b34b6 100644 --- a/src/main/kotlin/se/kth/spork/util/LineBasedMerge.kt +++ b/src/main/kotlin/se/kth/spork/util/LineBasedMerge.kt @@ -40,7 +40,7 @@ fun lineBasedMerge(base: String, left: String, right: String): Pair }, baseRaw, leftRaw, - rightRaw + rightRaw, ) val it: Iterator = res.iterator() diff --git a/src/test/java/se/kth/spork/cli/CliTest.java b/src/test/java/se/kth/spork/cli/CliTest.java index 15809e45..e3f11b5a 100644 --- a/src/test/java/se/kth/spork/cli/CliTest.java +++ b/src/test/java/se/kth/spork/cli/CliTest.java @@ -53,7 +53,7 @@ void merge_shouldThrowOnMissingType_whenGlobalFallbackIsDisabled() { assertThrows( MergeException.class, - () -> Cli.merge(sources.base, sources.left, sources.right, /*exitOnError=*/ true), + () -> Cli.merge(sources.base, sources.left, sources.right, /* exitOnError= */ true), "Merge contained no types and global line-based fallback is disabled"); } @@ -64,7 +64,7 @@ void merge_shouldMexgeCorrectlyOnMissingType_whenGlobalFallbackIsEnabled() { String expected = Parser.INSTANCE.read(sources.expected); Pair merge = - Cli.merge(sources.base, sources.left, sources.right, /*exitOnError=*/ false); + Cli.merge(sources.base, sources.left, sources.right, /* exitOnError= */ false); assertEquals(0, merge.getSecond()); assertEquals(expected, merge.getFirst()); diff --git a/src/test/java/se/kth/spork/spoon/Spoon3dmMergeTest.java b/src/test/java/se/kth/spork/spoon/Spoon3dmMergeTest.java index a83d3b9a..eb2cab0e 100644 --- a/src/test/java/se/kth/spork/spoon/Spoon3dmMergeTest.java +++ b/src/test/java/se/kth/spork/spoon/Spoon3dmMergeTest.java @@ -5,8 +5,6 @@ import java.io.IOException; import java.util.Comparator; import java.util.List; -import java.util.Set; - import kotlin.Pair; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; @@ -73,7 +71,7 @@ private static void runTestMerge(Util.TestSources sources) { // this assert is just to give a better overview of obvious errors, but it relies on the // pretty printer's // correctness - //assertEquals(Cli.prettyPrint(expected), Cli.prettyPrint(mergeTree)); + // assertEquals(Cli.prettyPrint(expected), Cli.prettyPrint(mergeTree)); System.out.println(Cli.prettyPrint(mergeTree)); // we cannot assert CtModules so stricly @@ -82,12 +80,13 @@ private static void runTestMerge(Util.TestSources sources) { // so we force the order of types and assert one by one assertTrue(expected instanceof CtModule); - final Comparator nameComparator = new Comparator<>() { - @Override - public int compare(CtType o, CtType t1) { - return o.getQualifiedName().compareTo(t1.getQualifiedName()); - } - }; + final Comparator nameComparator = + new Comparator<>() { + @Override + public int compare(CtType o, CtType t1) { + return o.getQualifiedName().compareTo(t1.getQualifiedName()); + } + }; final List list1 = expected.filterChildren(c -> (c instanceof CtType)).list(); final List list2 = mergeTree.filterChildren(c -> (c instanceof CtType)).list(); list1.sort(nameComparator);