Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 791aeee

Browse files
committed
Add support for multi-value SuppressWarnings
1 parent 7c85a85 commit 791aeee

File tree

7 files changed

+64
-1
lines changed

7 files changed

+64
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ test-output
1010
/.metadata
1111
.cache
1212
derby.log
13+
nb-configuration.xml

src/main/java/com/mysema/codegen/CodeWriter.java

+2
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,6 @@ <T> CodeWriter beginStaticMethod(Type type, String name, Collection<T> params,
109109

110110
CodeWriter suppressWarnings(String type) throws IOException;
111111

112+
CodeWriter suppressWarnings(String... types) throws IOException;
113+
112114
}

src/main/java/com/mysema/codegen/JavaWriter.java

+5
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@ public JavaWriter suppressWarnings(String type) throws IOException {
481481
return line("@SuppressWarnings(\"" + type + "\")");
482482
}
483483

484+
@Override
485+
public CodeWriter suppressWarnings(String... types) throws IOException {
486+
return annotation(new MultiSuppressWarnings(types));
487+
}
488+
484489
private <T> Parameter[] transform(Collection<T> parameters,
485490
Function<T, Parameter> transformer) {
486491
Parameter[] rv = new Parameter[parameters.size()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.mysema.codegen;
17+
18+
import java.lang.annotation.Annotation;
19+
import java.util.Arrays;
20+
21+
@SuppressWarnings("AnnotationAsSuperInterface") // Internal helper class
22+
class MultiSuppressWarnings implements SuppressWarnings {
23+
24+
private final String[] values;
25+
26+
public MultiSuppressWarnings(String... values) {
27+
this.values = Arrays.copyOf(values, values.length);
28+
}
29+
30+
@Override
31+
@SuppressWarnings("ReturnOfCollectionOrArrayField")
32+
public String[] value() {
33+
return values;
34+
}
35+
36+
@Override
37+
public Class<? extends Annotation> annotationType() {
38+
return SuppressWarnings.class;
39+
}
40+
}

src/main/java/com/mysema/codegen/ScalaWriter.java

+5
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ public ScalaWriter suppressWarnings(String type) throws IOException {
579579
return line("@SuppressWarnings(\"" + type + "\")");
580580
}
581581

582+
@Override
583+
public CodeWriter suppressWarnings(String... types) throws IOException {
584+
return annotation(new MultiSuppressWarnings(types));
585+
}
586+
582587
private <T> Parameter[] transform(Collection<T> parameters,
583588
Function<T, Parameter> transformer) {
584589
Parameter[] rv = new Parameter[parameters.size()];

src/test/java/com/mysema/codegen/JavaWriterTest.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public Parameter apply(Parameter input) {
4545

4646
private static void match(String resource, String text) throws IOException {
4747
// TODO : try to compile ?
48-
String expected = Resources.toString(JavaWriterTest.class.getResource(resource), Charsets.UTF_8)
48+
String expected = Resources.toString(JavaWriterTest.class.getResource(resource), Charsets.UTF_8)
4949
.replace("\r\n", "\n").trim();
5050
String actual = text.trim();
5151
assertEquals(expected, actual);
@@ -335,4 +335,12 @@ public void SuppressWarnings() throws IOException {
335335

336336
match("/testSuppressWarnings", w.toString());
337337
}
338+
339+
@Test
340+
public void SuppressWarnings2() throws IOException {
341+
writer.suppressWarnings("all", "unused");
342+
writer.privateField(Types.STRING, "test");
343+
344+
match("/testSuppressWarnings2", w.toString());
345+
}
338346
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@SuppressWarnings({"all", "unused"})
2+
private String test;

0 commit comments

Comments
 (0)