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: correct spelling mistake in API, doc and tests (#5934) #5943

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
4 changes: 2 additions & 2 deletions doc/processor_annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public interface AnnotationProcessor<A extends Annotation, E extends CtElement>
boolean inferConsumedAnnotationType();
Set<Class<? extends A>> getProcessedAnnotationTypes();
Set<Class<? extends A>> getConsumedAnnotationTypes();
boolean shoudBeConsumed(CtAnnotation<? extends Annotation> annotation);
boolean shouldBeConsumed(CtAnnotation<? extends Annotation> annotation);
}
```

Annotation processors extend normal processors by stating the annotation type those elements must
carry (type parameter `A`), in addition of stating the kind of source code element they process
(type parameter `E`). The `process` method (line 4) receives as arguments both the `CtElement` and the
annotation it carries. The remaining four methods (`getProcessedAnnotationTypes`, `getConsumedAnnotationTypes`,
`inferConsumedAnnotationTypes` and `shoudBeConsumed`) configure the visiting of the AST during annotation
`inferConsumedAnnotationTypes` and `shouldBeConsumed`) configure the visiting of the AST during annotation
processing. The Spoon annotation processing runtime is able to infer the type of annotation a processor
handles from its type parameter `A`. This restricts each processor to handle a single annotation. To avoid this
restriction, a developer can override the `inferConsumedAnnotationType()` method to return `false`. When doing
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/spoon/processing/AbstractAnnotationProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public boolean inferConsumedAnnotationType() {
public final boolean isToBeProcessed(E element) {
if ((element != null) && (element.getAnnotations() != null)) {
for (CtAnnotation<? extends Annotation> a : element.getAnnotations()) {
if (shoudBeProcessed(a)) {
if (shouldBeProcessed(a)) {
return true;
}
}
Expand All @@ -137,13 +137,13 @@ public final boolean isToBeProcessed(E element) {
@SuppressWarnings("unchecked")
public final void process(E element) {
for (CtAnnotation<? extends Annotation> annotation : new ArrayList<>(element.getAnnotations())) {
if (shoudBeProcessed(annotation)) {
if (shouldBeProcessed(annotation)) {
try {
process((A) annotation.getActualAnnotation(), element);
} catch (Exception e) {
Launcher.LOGGER.error(e.getMessage(), e);
}
if (shoudBeConsumed(annotation)) {
if (shouldBeConsumed(annotation)) {
element.removeAnnotation(annotation);
}
}
Expand All @@ -154,13 +154,21 @@ public final void process(E element) {
* {@inheritDoc}
*
* Removes all annotations A on elements E.
*
* @deprecated use {@link #shouldBeConsumed(CtAnnotation)} instead
*/
@Deprecated
@Override
public boolean shoudBeConsumed(CtAnnotation<? extends Annotation> annotation) {
return consumedAnnotationTypes.containsKey(annotation.getAnnotationType().getQualifiedName());
}

private boolean shoudBeProcessed(CtAnnotation<? extends Annotation> annotation) {
@Override
public boolean shouldBeConsumed(CtAnnotation<? extends Annotation> annotation) {
return consumedAnnotationTypes.containsKey(annotation.getAnnotationType().getQualifiedName());
}

private boolean shouldBeProcessed(CtAnnotation<? extends Annotation> annotation) {
return processedAnnotationTypes.containsKey(annotation.getAnnotationType().getQualifiedName());
}

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/spoon/processing/AnnotationProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* the abstract default implementation of this interface.
*/
public interface AnnotationProcessor<A extends Annotation, E extends CtElement>
extends Processor<E> {
extends Processor<E> {

/**
* Do the annotation processing job for a given annotation.
Expand Down Expand Up @@ -62,7 +62,21 @@ public interface AnnotationProcessor<A extends Annotation, E extends CtElement>

/**
* Returns true if this annotation should be removed from the processed code.
*
* @param annotation the annotation to be checked
* @return true, if the given annotation should be removed from the processed code.
*
* @deprecated use {@link #shouldBeConsumed(CtAnnotation)} instead
*/
@Deprecated
boolean shoudBeConsumed(CtAnnotation<? extends Annotation> annotation);

/**
* Returns true if this annotation should be removed from the processed code.
*
* @param annotation the annotation to be checked
* @return true, if the given annotation should be removed from the processed code.
*/
boolean shouldBeConsumed(CtAnnotation<? extends Annotation> annotation);

}
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/api/APITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public File getDefaultOutputDirectory() {

@Test
public void testOutputWithNoOutputProduceNoFolder() {
// contract: when using "NO_OUTPUT" output type, no output folder shoud be created
// contract: when using "NO_OUTPUT" output type, no output folder should be created
String destPath = "./target/nooutput_" + UUID.randomUUID().toString();
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/api/testclasses/Bar.java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testSuperClassInGetAllExecutables() {
try {
aMethod.getType().getAllExecutables();
} catch (NullPointerException e) {
fail("We shoudn't have a NullPointerException when we call getAllExecutables.");
fail("We shouldn't have a NullPointerException when we call getAllExecutables.");
}
}

Expand Down