Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fully comply with the contract of CtScannerTest#testScannerCallsAllProperties #1870

Merged
merged 4 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
package spoon.reflect.visitor;


import spoon.reflect.declaration.CtElement;
import spoon.reflect.path.CtRole;

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Deque;
import java.util.Iterator;

/**
* This visitor implements a deep-search scan on the model for 2 elements.
*
Expand All @@ -37,15 +29,15 @@
*/
// autogenerated by CtBiScannerGenerator
public class CtBiScannerDefault extends spoon.reflect.visitor.CtAbstractBiScanner {
protected Deque<CtElement> stack = new ArrayDeque<>();
protected java.util.Deque<spoon.reflect.declaration.CtElement> stack = new java.util.ArrayDeque<>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct that current generator produces fully qualified names here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the BiScanner generator does not use autoimport


protected void enter(CtElement e) {
protected void enter(spoon.reflect.declaration.CtElement e) {
}

protected void exit(CtElement e) {
protected void exit(spoon.reflect.declaration.CtElement e) {
}

public void biScan(CtElement element, CtElement other) {
public void biScan(spoon.reflect.declaration.CtElement element, spoon.reflect.declaration.CtElement other) {
if (other == null) {
return;
}
Expand All @@ -57,12 +49,12 @@ public void biScan(CtElement element, CtElement other) {
}
}

public void biScan(CtRole role, CtElement element, CtElement other) {
public void biScan(spoon.reflect.path.CtRole role, spoon.reflect.declaration.CtElement element, spoon.reflect.declaration.CtElement other) {
biScan(element, other);
}

protected void biScan(CtRole role, Collection<? extends CtElement> elements, Collection<? extends CtElement> others) {
for (Iterator<? extends CtElement> firstIt = elements.iterator(), secondIt = others.iterator(); (firstIt.hasNext()) && (secondIt.hasNext());) {
protected void biScan(spoon.reflect.path.CtRole role, java.util.Collection<? extends spoon.reflect.declaration.CtElement> elements, java.util.Collection<? extends spoon.reflect.declaration.CtElement> others) {
for (java.util.Iterator<? extends spoon.reflect.declaration.CtElement> firstIt = elements.iterator(), secondIt = others.iterator(); (firstIt.hasNext()) && (secondIt.hasNext());) {
biScan(role, firstIt.next(), secondIt.next());
}
}
Expand Down Expand Up @@ -925,6 +917,7 @@ public void visitCtImport(final spoon.reflect.declaration.CtImport ctImport) {
enter(ctImport);
biScan(spoon.reflect.path.CtRole.IMPORT_REFERENCE, ctImport.getReference(), other.getReference());
biScan(spoon.reflect.path.CtRole.ANNOTATION, ctImport.getAnnotations(), other.getAnnotations());
biScan(spoon.reflect.path.CtRole.COMMENT, ctImport.getComments(), other.getComments());
exit(ctImport);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/spoon/reflect/visitor/CtScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ public void visitCtImport(final CtImport ctImport) {
enter(ctImport);
scan(CtRole.IMPORT_REFERENCE, ctImport.getReference());
scan(CtRole.ANNOTATION, ctImport.getAnnotations());
scan(CtRole.COMMENT, ctImport.getComments());
exit(ctImport);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ public void visitCtImport(final spoon.reflect.declaration.CtImport ctImport) {
spoon.reflect.declaration.CtImport aCtImport = spoon.support.visitor.clone.CloneBuilder.build(this.builder, ctImport, ctImport.getFactory().Core().createImport());
aCtImport.setReference(this.cloneHelper.clone(ctImport.getReference()));
aCtImport.setAnnotations(this.cloneHelper.clone(ctImport.getAnnotations()));
aCtImport.setComments(this.cloneHelper.clone(ctImport.getComments()));
this.other = aCtImport;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,7 @@ public void visitCtJavaDocTag(final spoon.reflect.code.CtJavaDocTag docTag) {
public void visitCtImport(final spoon.reflect.declaration.CtImport ctImport) {
replaceElementIfExist(ctImport.getReference(), new spoon.support.visitor.replace.ReplacementVisitor.CtImportReferenceReplaceListener(ctImport));
replaceInListIfExist(ctImport.getAnnotations(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementAnnotationsReplaceListener(ctImport));
replaceInListIfExist(ctImport.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(ctImport));
}

// auto-generated, see spoon.generating.ReplacementVisitorGenerator
Expand Down
9 changes: 6 additions & 3 deletions src/test/java/spoon/reflect/visitor/CtScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.reflect.visitor.processors.CheckScannerTestProcessor;
Expand Down Expand Up @@ -112,7 +113,8 @@ public void testScannerCallsAllProperties() throws Exception {
launcher.run();

CtTypeReference<?> ctElementRef = launcher.getFactory().createCtTypeReference(CtElement.class);

CtTypeReference<?> ctRefRef = launcher.getFactory().createCtTypeReference(CtReference.class);

CtClass<?> scannerCtClass = (CtClass<?>)launcher.getFactory().Type().get(CtScanner.class);

List<String> problems = new ArrayList<>();
Expand Down Expand Up @@ -170,8 +172,9 @@ public boolean matches(CtInvocation element) {
return super.matches(element) && element.getExecutable().getSimpleName().equals(getter.getName());
}
}).first();
if(getter.getName().equals("getComments")) {
//ignore missing getComments ... until discussion about its contracts is finished

if(getter.getName().equals("getComments") && leafMmType.getModelInterface().isSubtypeOf(ctRefRef)) {
//one cannot set comments on references see the @UnsettableProperty of CtReference#setComments
return;
}

Expand Down