Skip to content

Commit

Permalink
Merge pull request #29 from ashitikov/master
Browse files Browse the repository at this point in the history
Fixed generation of compositions with abstract components
  • Loading branch information
ashitikov authored Mar 23, 2017
2 parents 2b5eb3e + b4bc86d commit 8622720
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'trollsoftware'
version '1.1.1-SNAPSHOT'
version '1.1.3-SNAPSHOT'

apply plugin: 'java'

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'trollsoftware'
version '1.1.1-SNAPSHOT'
version '1.1.3-SNAPSHOT'

task wrapper(type: Wrapper) {
gradleVersion = '2.5'
Expand Down
2 changes: 1 addition & 1 deletion processor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'trollsoftware'
version '1.1.1-SNAPSHOT'
version '1.1.3-SNAPSHOT'

apply plugin: 'java'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private TypeSpec getTypeSpec(TypeElement typeElement) {

specBuilder.addMethod(MethodSpec.methodBuilder("onInject")
.addModifiers(Modifier.ABSTRACT, Modifier.PROTECTED)
.addAnnotation(ShareProtected.class)
.addParameter(ParameterSpec.builder(nestedCompositionTypeClassName, "composition", Modifier.FINAL)
.build())
.build());
Expand Down Expand Up @@ -180,7 +181,8 @@ private MethodSpec getMethodSpec(Map.Entry<ExecutableElementContainer, List<Type
DeclaredType declaredType = entry.getKey().getDeclaredType();
MethodSpec.Builder builder = MethodSpecUtils.getBuilder(executableElement, declaredType, getProcessingEnv().getTypeUtils());

if (container.getRelationShip() == TypeElementPairContainer.ExecutableRelationShip.Overriding
if (container.getRelationShip() == TypeElementPairContainer.ExecutableRelationShip.OverridingAbstract
|| container.getRelationShip() == TypeElementPairContainer.ExecutableRelationShip.Overriding
|| container.getRelationShip() == TypeElementPairContainer.ExecutableRelationShip.Same) {
builder.addAnnotation(Override.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(executableElement.getSimpleName(), executableElement.getParameters().size());
}

@Override
public String toString() {
return "ExecutableElementContainer{" +
"executableElement=" + executableElement +
", declaredType=" + declaredType +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum ExecutableRelationShip {
Nothing,
Same,
Overriding,
OverridingAbstract,
Hiding
}

Expand Down Expand Up @@ -104,8 +105,11 @@ public void setDeclaredType(DeclaredType declaredType) {
public String toString() {
return "TypeElementPairContainer{" +
"intf=" + intf +
", bind=" + bind +
", declaredType=" + declaredType +
", relationShip=" + relationShip +
", useInjection=" + useInjection +
", isAbstract=" + isAbstract +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ private static TypeElementPairContainer.ExecutableRelationShip findRelation(Exec
if (overrider.equals(overridden)) {
return TypeElementPairContainer.ExecutableRelationShip.Same;
} else if (els.overrides(overrider, overridden, containing)) {
if (isAbstract(overrider)) {
return TypeElementPairContainer.ExecutableRelationShip.OverridingAbstract;
}
return TypeElementPairContainer.ExecutableRelationShip.Overriding;
} else if (els.hides(overrider, overridden)) {
return TypeElementPairContainer.ExecutableRelationShip.Hiding;
Expand Down Expand Up @@ -150,7 +153,8 @@ private static void processInterfaceElements(List<ExecutableElement> elementsFro

if (result.isDuplicateFound()) {
TypeElementPairContainer typeElementPairContainer = new TypeElementPairContainer(concreteIntf, bind, baseDt, intfInjected, result.getRelationShip());
typeElementPairContainer.setAbstract(result.getRelationShip() == TypeElementPairContainer.ExecutableRelationShip.Same);
typeElementPairContainer.setAbstract(result.getRelationShip() == TypeElementPairContainer.ExecutableRelationShip.Same
|| result.getRelationShip() == TypeElementPairContainer.ExecutableRelationShip.OverridingAbstract);

addValueToMapList(container, typeElementPairContainer, map);
} else {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/jcomposition/example/partial/DrawableFull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.example.partial;

public class DrawableFull extends DrawableFullBase {

@Override
public String getPart() {
return "Drawable Full part";
}

@Override
protected void onInject(FullBase.Composition composition) {
// inject
}

@Override
protected void onMove() {

}
}
20 changes: 20 additions & 0 deletions src/main/java/jcomposition/example/partial/Full.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.example.partial;

public abstract class Full extends FullBase {
}
26 changes: 26 additions & 0 deletions src/main/java/jcomposition/example/partial/IDrawableFull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.example.partial;

import jcomposition.api.annotations.Bind;
import jcomposition.api.annotations.Composition;
import jcomposition.example.interfaces.IDrawable;

@Bind(DrawableFull.class)
@Composition(name = "DrawableFullBase")
public interface IDrawableFull extends IFull, IDrawable {
}
26 changes: 26 additions & 0 deletions src/main/java/jcomposition/example/partial/IFull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.example.partial;

import jcomposition.api.annotations.Bind;
import jcomposition.api.annotations.Composition;
import jcomposition.example.interfaces.IMovable;

@Bind(Full.class)
@Composition(name = "FullBase")
public interface IFull extends IMovable, IPartial {
}
28 changes: 28 additions & 0 deletions src/main/java/jcomposition/example/partial/IPartial.java
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.example.partial;

import jcomposition.api.annotations.Bind;
import jcomposition.api.annotations.Composition;
import jcomposition.example.interfaces.IUpdatable;
import jcomposition.example.interfaces.IVisible;

@Bind(Partial.class)
@Composition(name = "PartialBase")
public interface IPartial extends IVisible, IUpdatable {
String getPart();
}
21 changes: 21 additions & 0 deletions src/main/java/jcomposition/example/partial/Partial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.example.partial;

public abstract class Partial extends PartialBase {

}

0 comments on commit 8622720

Please sign in to comment.