-
Notifications
You must be signed in to change notification settings - Fork 0
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 #69 from raner/issue-64-package-level-bug
Issue #64: fixed bug with package-level post-processor options
- Loading branch information
Showing
8 changed files
with
237 additions
and
8 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...n/src/main/java/pro/projo/interfaces/annotation/postprocessor/LowerCasePostProcessor.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,55 @@ | ||
// // | ||
// Copyright 2021 Mirko Raner // | ||
// // | ||
// 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 pro.projo.interfaces.annotation.postprocessor; | ||
|
||
import java.io.FilterWriter; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.function.UnaryOperator; | ||
|
||
/** | ||
* {@link LowerCasePostProcessor} is a simple Projo template post-processor that converts | ||
* all letters to lower case. This functionality is mainly provided for demo purposes. | ||
* | ||
* @author Mirko Raner | ||
**/ | ||
public class LowerCasePostProcessor implements UnaryOperator<Writer> | ||
{ | ||
@Override | ||
public Writer apply(Writer writer) | ||
{ | ||
return new FilterWriter(writer) | ||
{ | ||
@Override | ||
public void write(int character) throws IOException | ||
{ | ||
super.write(Character.toLowerCase(character)); | ||
} | ||
|
||
@Override | ||
public void write(char[] characters, int offset, int length) throws IOException | ||
{ | ||
super.write(new String(characters).toLowerCase().toCharArray(), offset, length); | ||
} | ||
|
||
@Override | ||
public void write(String string, int offset, int length) throws IOException | ||
{ | ||
super.write(string.toLowerCase(), offset, length); | ||
} | ||
}; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...t/java/pro/projo/generation/interfaces/GeneratedPostProcessorPackageLevelSourcesTest.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,49 @@ | ||
// // | ||
// Copyright 2021 Mirko Raner // | ||
// // | ||
// 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 pro.projo.generation.interfaces; | ||
|
||
import java.io.File; | ||
import java.text.Format; | ||
import java.text.MessageFormat; | ||
import java.util.Collection; | ||
import java.util.stream.Stream; | ||
import org.junit.runners.Parameterized.Parameters; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
/** | ||
* {@link GeneratedPostProcessorPackageLevelSourcesTest} is a parameterized test that checks that all files | ||
* in {@code src/test/resources/pro/projo/generation/interfaces/options/packagelevel/expected} match their | ||
* corresponding generated files. | ||
* | ||
* @author Mirko Raner | ||
**/ | ||
public class GeneratedPostProcessorPackageLevelSourcesTest extends AbstractGeneratedSourcesTest | ||
{ | ||
static Format generated = new MessageFormat("target/generated-test-sources/test-annotations/pro/projo/generation/interfaces/test/options/packagelevel/{0}"); | ||
static Format comparison = new MessageFormat("src/test/resources/pro/projo/generation/interfaces/options/packagelevel/expected/{0}"); | ||
|
||
public GeneratedPostProcessorPackageLevelSourcesTest() | ||
{ | ||
super(comparison, generated); | ||
} | ||
|
||
@Parameters(name="{0}") | ||
public static Collection<Object[]> testSources() | ||
{ | ||
File expected = new File(comparison.format(new Object[] {""})); | ||
return Stream.of(expected.list()).map(file -> new Object[] {file}).collect(toList()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...src/test/java/pro/projo/generation/interfaces/test/options/packagelevel/package-info.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,31 @@ | ||
// // | ||
// Copyright 2021 Mirko Raner // | ||
// // | ||
// 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. // | ||
// // | ||
@Options(fileExtension=".kava", postProcessor=UpperCasePostProcessor.class, addAnnotations=false) | ||
@Interface(generate="Runnable", from=Runnable.class, options=@Options(addAnnotations=true, postProcessor=LowerCasePostProcessor.class)) | ||
@Interface(generate="AutoCloseable", from=AutoCloseable.class) | ||
package pro.projo.generation.interfaces.test.options.packagelevel; | ||
|
||
import pro.projo.interfaces.annotation.Interface; | ||
import pro.projo.interfaces.annotation.Options; | ||
import pro.projo.interfaces.annotation.postprocessor.LowerCasePostProcessor; | ||
import pro.projo.interfaces.annotation.postprocessor.UpperCasePostProcessor; | ||
|
||
/** | ||
* This {@code package-info} class contains additional annotations that are tested by the option-related tests | ||
* in {@link pro.projo.generation.interfaces.GeneratedPostProcessorPackageLevelSourcesTest}. | ||
* | ||
* @author Mirko Raner | ||
**/ |
33 changes: 33 additions & 0 deletions
33
...esources/pro/projo/generation/interfaces/options/packagelevel/expected/AutoCloseable.kava
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 2019 - 2021 MIRKO RANER // | ||
// // | ||
// 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 PRO.PROJO.GENERATION.INTERFACES.TEST.OPTIONS.PACKAGELEVEL; | ||
/* */ | ||
IMPORT JAVAX.ANNOTATION.GENERATED; | ||
/* */ | ||
/** | ||
* | ||
* THIS INTERFACE WAS EXTRACTED FROM JAVA.LANG.AUTOCLOSEABLE. | ||
* | ||
**/ | ||
/* */ | ||
|
||
/* */ | ||
PUBLIC INTERFACE AUTOCLOSEABLE | ||
{ | ||
/* */ | ||
VOID CLOSE(); | ||
/* */ | ||
} |
33 changes: 33 additions & 0 deletions
33
...est/resources/pro/projo/generation/interfaces/options/packagelevel/expected/Runnable.kava
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 2019 - 2021 mirko raner // | ||
// // | ||
// 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 pro.projo.generation.interfaces.test.options.packagelevel; | ||
/* */ | ||
import javax.annotation.generated; | ||
/* */ | ||
/** | ||
* | ||
* this interface was extracted from java.lang.runnable. | ||
* | ||
**/ | ||
/* */ | ||
|
||
/* */ | ||
public interface runnable | ||
{ | ||
/* */ | ||
void run(); | ||
/* */ | ||
} |
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
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
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