Skip to content

Commit

Permalink
fix AstCheckerTest - accept call of ModelList or ModelSet
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed May 12, 2018
1 parent 530f81f commit c6b108d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/java/spoon/reflect/ast/AstCheckerTest.java
Expand Up @@ -4,6 +4,7 @@
import spoon.Launcher;
import spoon.experimental.modelobs.FineModelChangeListener;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtFieldRead;
import spoon.reflect.code.CtIf;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.code.CtReturn;
Expand All @@ -19,6 +20,8 @@
import spoon.support.DerivedProperty;
import spoon.support.UnsettableProperty;
import spoon.support.comparator.CtLineElementComparator;
import spoon.support.util.ModelList;
import spoon.support.util.ModelSet;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -146,6 +149,7 @@ private boolean isToBeProcessed(CtMethod<?> candidate) {
&& !isSurcharged(candidate) //
&& !isDelegateMethod(candidate) //
&& !isUnsupported(candidate.getBody()) //
&& !isCallModelCollection(candidate.getBody()) //
&& !hasPushToStackInvocation(candidate.getBody());
}

Expand Down Expand Up @@ -214,6 +218,28 @@ private boolean isUnsupported(CtBlock<?> body) {
&& body.getStatements().get(0) instanceof CtThrow //
&& "UnsupportedOperationException".equals(((CtThrow) body.getStatements().get(0)).getThrownExpression().getType().getSimpleName());
}

private boolean isCallModelCollection(CtBlock<?> body) {

return body.filterChildren((CtInvocation inv) -> {
if (inv.getTarget() instanceof CtFieldRead) {
CtFieldRead fielRead = (CtFieldRead) inv.getTarget();
if (isModelCollection(fielRead.getType()) ) {
//it is invocation on ModelList, ModelSet or ModelMap
return true;
}
}
return false;
}).first() != null;
}

private boolean isModelCollection(CtTypeReference<?> typeRef) {
Factory f = typeRef.getFactory();
if (typeRef.isSubtypeOf(f.Type().createReference(ModelList.class))) return true;
if (typeRef.isSubtypeOf(f.Type().createReference(ModelSet.class))) return true;
// if (typeRef.isSubtypeOf(f.Type().createReference(ModelMap.class))) return true;
return false;
}

private boolean hasPushToStackInvocation(CtBlock<?> body) {
return body.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
Expand Down

0 comments on commit c6b108d

Please sign in to comment.