mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Add support for multi-value SuppressWarnings
This commit is contained in:
parent
7c85a8522c
commit
791aeeeeaa
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ test-output
|
||||
/.metadata
|
||||
.cache
|
||||
derby.log
|
||||
nb-configuration.xml
|
||||
|
||||
@ -109,4 +109,6 @@ public interface CodeWriter extends Appendable {
|
||||
|
||||
CodeWriter suppressWarnings(String type) throws IOException;
|
||||
|
||||
CodeWriter suppressWarnings(String... types) throws IOException;
|
||||
|
||||
}
|
||||
@ -481,6 +481,11 @@ public final class JavaWriter extends AbstractCodeWriter<JavaWriter> {
|
||||
return line("@SuppressWarnings(\"" + type + "\")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeWriter suppressWarnings(String... types) throws IOException {
|
||||
return annotation(new MultiSuppressWarnings(types));
|
||||
}
|
||||
|
||||
private <T> Parameter[] transform(Collection<T> parameters,
|
||||
Function<T, Parameter> transformer) {
|
||||
Parameter[] rv = new Parameter[parameters.size()];
|
||||
|
||||
40
src/main/java/com/mysema/codegen/MultiSuppressWarnings.java
Normal file
40
src/main/java/com/mysema/codegen/MultiSuppressWarnings.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
|
||||
*
|
||||
* 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 com.mysema.codegen;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
|
||||
@SuppressWarnings("AnnotationAsSuperInterface") // Internal helper class
|
||||
class MultiSuppressWarnings implements SuppressWarnings {
|
||||
|
||||
private final String[] values;
|
||||
|
||||
public MultiSuppressWarnings(String... values) {
|
||||
this.values = Arrays.copyOf(values, values.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("ReturnOfCollectionOrArrayField")
|
||||
public String[] value() {
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return SuppressWarnings.class;
|
||||
}
|
||||
}
|
||||
@ -579,6 +579,11 @@ public class ScalaWriter extends AbstractCodeWriter<ScalaWriter> {
|
||||
return line("@SuppressWarnings(\"" + type + "\")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeWriter suppressWarnings(String... types) throws IOException {
|
||||
return annotation(new MultiSuppressWarnings(types));
|
||||
}
|
||||
|
||||
private <T> Parameter[] transform(Collection<T> parameters,
|
||||
Function<T, Parameter> transformer) {
|
||||
Parameter[] rv = new Parameter[parameters.size()];
|
||||
|
||||
@ -45,7 +45,7 @@ public class JavaWriterTest {
|
||||
|
||||
private static void match(String resource, String text) throws IOException {
|
||||
// TODO : try to compile ?
|
||||
String expected = Resources.toString(JavaWriterTest.class.getResource(resource), Charsets.UTF_8)
|
||||
String expected = Resources.toString(JavaWriterTest.class.getResource(resource), Charsets.UTF_8)
|
||||
.replace("\r\n", "\n").trim();
|
||||
String actual = text.trim();
|
||||
assertEquals(expected, actual);
|
||||
@ -335,4 +335,12 @@ public class JavaWriterTest {
|
||||
|
||||
match("/testSuppressWarnings", w.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SuppressWarnings2() throws IOException {
|
||||
writer.suppressWarnings("all", "unused");
|
||||
writer.privateField(Types.STRING, "test");
|
||||
|
||||
match("/testSuppressWarnings2", w.toString());
|
||||
}
|
||||
}
|
||||
|
||||
2
src/test/resources/testSuppressWarnings2
Normal file
2
src/test/resources/testSuppressWarnings2
Normal file
@ -0,0 +1,2 @@
|
||||
@SuppressWarnings({"all", "unused"})
|
||||
private String test;
|
||||
Loading…
Reference in New Issue
Block a user