-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from ashitikov/refactor_mergeconflict
Refactoring of MergeConflictPolicy enum. Make it more flexible using …
- Loading branch information
Showing
23 changed files
with
452 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
api/src/main/java/jcomposition/api/IMergeConflictPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api; | ||
|
||
import jcomposition.api.types.IExecutableElementContainer; | ||
import jcomposition.api.types.ITypeElementPairContainer; | ||
|
||
import java.util.List; | ||
|
||
public interface IMergeConflictPolicy { | ||
/** | ||
* Applies merge policy to method using list of overriders | ||
* @param elementContainer executable element container | ||
* @param overriders list of overriders of executable element | ||
* @return list of overriders to implement | ||
*/ | ||
List<ITypeElementPairContainer> merge(IExecutableElementContainer elementContainer, | ||
List<ITypeElementPairContainer> overriders); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
api/src/main/java/jcomposition/api/policies/BaseAbstractPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.policies; | ||
|
||
import jcomposition.api.IMergeConflictPolicy; | ||
import jcomposition.api.types.ITypeElementPairContainer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class BaseAbstractPolicy implements IMergeConflictPolicy { | ||
/** | ||
* Removes (filter) abstract methods from overriders list | ||
* | ||
* @param overriders list of overriders of executable element | ||
* @return not abstract methods to implement | ||
*/ | ||
public List<ITypeElementPairContainer> filterAbstract(List<ITypeElementPairContainer> overriders) { | ||
List<ITypeElementPairContainer> notAbstract = new ArrayList<ITypeElementPairContainer>(overriders.size()); | ||
|
||
for (ITypeElementPairContainer overrider : overriders) { | ||
if (!overrider.isAbstract()) { | ||
notAbstract.add(overrider); | ||
} | ||
} | ||
|
||
return notAbstract; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
api/src/main/java/jcomposition/api/policies/MakeAbstractPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.policies; | ||
|
||
import jcomposition.api.types.IExecutableElementContainer; | ||
import jcomposition.api.types.ITypeElementPairContainer; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Make method abstract in case of conflict. | ||
*/ | ||
public class MakeAbstractPolicy extends BaseAbstractPolicy { | ||
@Override | ||
public List<ITypeElementPairContainer> merge(IExecutableElementContainer elementContainer, List<ITypeElementPairContainer> overriders) { | ||
if (overriders.size() > 0) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return overriders; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
api/src/main/java/jcomposition/api/policies/MixVoidPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.policies; | ||
|
||
import jcomposition.api.types.IExecutableElementContainer; | ||
import jcomposition.api.types.ITypeElementPairContainer; | ||
|
||
import javax.lang.model.type.TypeKind; | ||
import java.util.List; | ||
|
||
/** | ||
* Use first overriding method in case of returning non-void value. | ||
* Mix methods call that returns nothing (void) | ||
*/ | ||
public class MixVoidPolicy extends UseFirstPolicy { | ||
@Override | ||
public List<ITypeElementPairContainer> merge(IExecutableElementContainer elementContainer, List<ITypeElementPairContainer> overriders) { | ||
if (elementContainer.getExecutableElement().getReturnType().getKind() != TypeKind.VOID) { | ||
return super.merge(elementContainer, overriders); | ||
} | ||
|
||
return filterAbstract(overriders); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
api/src/main/java/jcomposition/api/policies/UseFirstPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.policies; | ||
|
||
import jcomposition.api.types.IExecutableElementContainer; | ||
import jcomposition.api.types.ITypeElementPairContainer; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Use first overriding method in case of conflict | ||
*/ | ||
public class UseFirstPolicy extends BaseAbstractPolicy { | ||
@Override | ||
public List<ITypeElementPairContainer> merge(IExecutableElementContainer elementContainer, List<ITypeElementPairContainer> overriders) { | ||
overriders = filterAbstract(overriders); | ||
|
||
return (overriders.size() > 1 ? | ||
overriders.subList(0, 1) : | ||
overriders); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api/src/main/java/jcomposition/api/types/ExecutableRelationShip.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.types; | ||
|
||
public enum ExecutableRelationShip { | ||
/** | ||
* There is no hiding or overriding relationship between executable and type element. | ||
*/ | ||
Nothing, | ||
Same, | ||
Overriding, | ||
OverridingAbstract, | ||
Hiding | ||
} |
28 changes: 28 additions & 0 deletions
28
api/src/main/java/jcomposition/api/types/IExecutableElementContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.types; | ||
|
||
import javax.lang.model.element.ExecutableElement; | ||
import javax.lang.model.type.DeclaredType; | ||
|
||
public interface IExecutableElementContainer { | ||
ExecutableElement getExecutableElement(); | ||
|
||
DeclaredType getDeclaredType(); | ||
|
||
boolean hasSuperMethod(); | ||
} |
23 changes: 23 additions & 0 deletions
23
api/src/main/java/jcomposition/api/types/IRelationShipResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.types; | ||
|
||
public interface IRelationShipResult { | ||
boolean isDuplicateFound(); | ||
|
||
ExecutableRelationShip getRelationShip(); | ||
} |
36 changes: 36 additions & 0 deletions
36
api/src/main/java/jcomposition/api/types/ITypeElementPairContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2017 TrollSoftware ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jcomposition.api.types; | ||
|
||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.type.DeclaredType; | ||
|
||
public interface ITypeElementPairContainer { | ||
boolean isAbstract(); | ||
|
||
boolean isFinal(); | ||
|
||
boolean hasUseInjection(); | ||
|
||
ExecutableRelationShip getRelationShip(); | ||
|
||
TypeElement getIntf(); | ||
|
||
TypeElement getBind(); | ||
|
||
DeclaredType getDeclaredType(); | ||
} |
Oops, something went wrong.