All Downloads are FREE. Search and download functionalities are using the official Maven repository.

groovy.transform.stc.SecondParam Maven / Gradle / Ivy

There is a newer version: 3.0.22
Show newest version
/*
 * Copyright 2003-2013 the original author or authors.
 *
 * 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 groovy.transform.stc;

import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.SourceUnit;

/**
 * 

A hint used to instruct the type checker to pick the second parameter type. For example:

* public <T,U> def doWith(T first, U second, @ClosureParams(SecondParam.class) Closure c) { c.call(src); } * *

This class has several inner classes that also helps picking generic argument types instead of the parameter type.

* * @author Cédric Champeau * @since 2.3.0 */ public class SecondParam extends PickAnyArgumentHint { public SecondParam() { super(1,-1); } /** *

A hint used to instruct the type checker to pick the first generic type of the second parameter type. For example:

* void <T> doWithElements(String base, List<T> src, @ClosureParams(SecondParam.FirstGenericType.class) Closure c) { ... } } * * @author Cédric Champeau * @since 2.3.0 */ public static class FirstGenericType extends PickAnyArgumentHint { public FirstGenericType() { super(1,0); } } /** *

A hint used to instruct the type checker to pick the second generic type of the second parameter type. For example:

* void <T,U> doWithElements(String base, Tuple<T,U> src, @ClosureParams(SecondParam.SecondGenericType.class) Closure c) { ... } * * @author Cédric Champeau * @since 2.3.0 */ public static class SecondGenericType extends PickAnyArgumentHint { public SecondGenericType() { super(1,1); } } /** *

A hint used to instruct the type checker to pick the second generic type of the second parameter type. For example:

* void <T,U,V> doWithElements(String base, Triple<T,U,V> src, @ClosureParams(SecondParam.ThirdGenericType.class) Closure c) { ... } * * @author Cédric Champeau * @since 2.3.0 */ public static class ThirdGenericType extends PickAnyArgumentHint { public ThirdGenericType() { super(1,2); } } /** *

A hint used to instruct the type checker to pick the type of the component of the second parameter type, which is therefore * expected to be an array, like in this example:

* void <T> doWithArray(String first, T[] array, @ClosureParams(FirstParam.Component.class) Closure c) { ... } */ public static class Component extends SecondParam { @Override public ClassNode[] getParameterTypes(final MethodNode node, final String[] options, final SourceUnit sourceUnit, final CompilationUnit unit, final ASTNode usage) { final ClassNode[] parameterTypes = super.getParameterTypes(node, options, sourceUnit, unit, usage); parameterTypes[0] = parameterTypes[0].getComponentType(); return parameterTypes; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy