mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#427 Allow to specify more than one processor option for one test
This commit is contained in:
parent
9737e0ba6e
commit
8a449e12fd
@ -19,6 +19,7 @@
|
||||
package org.mapstruct.ap.testutil.compilation.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
@ -31,6 +32,7 @@ import java.lang.annotation.Target;
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Repeatable( ProcessorOptions.class )
|
||||
public @interface ProcessorOption {
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* 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.mapstruct.ap.testutil.compilation.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Contains multiple {@link ProcessorOption} annotations
|
||||
*
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( { ElementType.TYPE, ElementType.METHOD } )
|
||||
public @interface ProcessorOptions {
|
||||
ProcessorOption[] value();
|
||||
}
|
@ -46,6 +46,7 @@ import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOptions;
|
||||
import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor;
|
||||
import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor;
|
||||
|
||||
@ -262,14 +263,35 @@ class CompilingStatement extends Statement {
|
||||
* @return A list containing the processor options to be used for this test
|
||||
*/
|
||||
private List<String> getProcessorOptions() {
|
||||
ProcessorOption processorOption = method.getAnnotation( ProcessorOption.class );
|
||||
List<ProcessorOption> processorOptions =
|
||||
getProcessorOptions(
|
||||
method.getAnnotation( ProcessorOptions.class ),
|
||||
method.getAnnotation( ProcessorOption.class ) );
|
||||
|
||||
if ( processorOption == null ) {
|
||||
processorOption = method.getMethod().getDeclaringClass().getAnnotation( ProcessorOption.class );
|
||||
if ( processorOptions.isEmpty() ) {
|
||||
processorOptions =
|
||||
getProcessorOptions(
|
||||
method.getMethod().getDeclaringClass().getAnnotation( ProcessorOptions.class ),
|
||||
method.getMethod().getDeclaringClass().getAnnotation( ProcessorOption.class ) );
|
||||
}
|
||||
|
||||
return processorOption != null ? Arrays.asList( asOptionString( processorOption ) )
|
||||
: Collections.<String>emptyList();
|
||||
List<String> result = new ArrayList<String>( processorOptions.size() );
|
||||
for ( ProcessorOption option : processorOptions ) {
|
||||
result.add( asOptionString( option ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<ProcessorOption> getProcessorOptions(ProcessorOptions options, ProcessorOption option) {
|
||||
if ( options != null ) {
|
||||
return Arrays.asList( options.value() );
|
||||
}
|
||||
else if ( option != null ) {
|
||||
return Arrays.asList( option );
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private String asOptionString(ProcessorOption processorOption) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user