-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #454 from ctrimble/feature_target-version
Specify target JVM version
- Loading branch information
Showing
15 changed files
with
256 additions
and
6 deletions.
There are no files selected for viewing
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
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
40 changes: 40 additions & 0 deletions
40
jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/LanguageFeatures.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,40 @@ | ||
/** | ||
* Copyright © 2010-2014 Nokia | ||
* | ||
* 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 org.jsonschema2pojo.util; | ||
|
||
import org.jsonschema2pojo.GenerationConfig; | ||
import static java.util.Arrays.asList; | ||
|
||
import java.util.Collection; | ||
|
||
public class LanguageFeatures { | ||
|
||
public static final Collection<String> LESS_THAN_8 | ||
= asList("1.1", "1.2", "1.3", "1.4", "1.5", "5", "1.6", "6", "1.7", "7"); | ||
public static final Collection<String> LESS_THAN_7 | ||
= asList("1.1", "1.2", "1.3", "1.4", "1.5", "5", "1.6", "6"); | ||
public static final Collection<String> LESS_THAN_6 | ||
= asList("1.1", "1.2", "1.3", "1.4", "1.5", "5"); | ||
|
||
public static boolean canUseJava7( GenerationConfig config ) { | ||
return !LESS_THAN_7.contains(config.getTargetVersion()); | ||
} | ||
|
||
public static boolean canUseJava8( GenerationConfig config ) { | ||
return !LESS_THAN_8.contains(config.getTargetVersion()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/Models.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,33 @@ | ||
/** | ||
* Copyright © 2010-2014 Nokia | ||
* | ||
* 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 org.jsonschema2pojo.util; | ||
|
||
import com.sun.codemodel.JAnnotationArrayMember; | ||
import com.sun.codemodel.JAnnotationUse; | ||
import com.sun.codemodel.JMethod; | ||
|
||
public class Models { | ||
|
||
public static void suppressWarnings(JMethod method, String... values) { | ||
JAnnotationUse annotation = method.annotate(SuppressWarnings.class); | ||
JAnnotationArrayMember member = annotation.paramArray("value"); | ||
for( String value : values ) { | ||
member.param(value); | ||
} | ||
} | ||
|
||
} |
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
93 changes: 93 additions & 0 deletions
93
jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/util/LanguageFeaturesTest.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,93 @@ | ||
/** | ||
* Copyright © 2010-2014 Nokia | ||
* | ||
* 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 org.jsonschema2pojo.util; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import org.jsonschema2pojo.GenerationConfig; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
import static org.jsonschema2pojo.util.LanguageFeaturesTest.VersionEnum.*; | ||
import static org.mockito.Mockito.*; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.hamcrest.MatcherAssert.*; | ||
|
||
@RunWith(Parameterized.class) | ||
public class LanguageFeaturesTest { | ||
|
||
public static enum VersionEnum { | ||
|
||
BEFORE_6(false, false, false), | ||
MAX_6(true, false, false), | ||
MAX_7(true, true, false), | ||
MAX_8(true, true, true), | ||
AFTER_8(true, true, true); | ||
|
||
public final boolean canUse6; | ||
public final boolean canUse7; | ||
public final boolean canUse8; | ||
|
||
VersionEnum(boolean canUse6, boolean canUse7, boolean canUse8) { | ||
this.canUse6 = canUse6; | ||
this.canUse7 = canUse7; | ||
this.canUse8 = canUse8; | ||
} | ||
} | ||
|
||
@Parameters | ||
public static Collection<Object[]> parameters() { | ||
return Arrays.asList(new Object[][] { | ||
{ "1.5", BEFORE_6 }, | ||
{ "5", BEFORE_6 }, | ||
{ "1.6", MAX_6 }, | ||
{ "6", MAX_6 }, | ||
{ "1.7", MAX_7 }, | ||
{ "7", MAX_7 }, | ||
{ "1.8", MAX_8 }, | ||
{ "8", MAX_8 }, | ||
{ "1.9", AFTER_8 }, | ||
{ "9", AFTER_8 } | ||
}); | ||
} | ||
|
||
private String version; | ||
private VersionEnum versionSpec; | ||
|
||
public LanguageFeaturesTest(String version, VersionEnum versionSpec) { | ||
this.version = version; | ||
this.versionSpec = versionSpec; | ||
} | ||
|
||
@Test | ||
public void correctTestForJava7() { | ||
assertThat(LanguageFeatures.canUseJava7(mockConfig(version)), equalTo(versionSpec.canUse7)); | ||
} | ||
|
||
@Test | ||
public void correctTestForJava8() { | ||
assertThat(LanguageFeatures.canUseJava8(mockConfig(version)), equalTo(versionSpec.canUse8)); | ||
} | ||
|
||
public static GenerationConfig mockConfig(String version) { | ||
GenerationConfig config = mock(GenerationConfig.class); | ||
when(config.getTargetVersion()).thenReturn(version); | ||
return config; | ||
} | ||
} |
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
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
Oops, something went wrong.