Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.facebook.presto.bytecode;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Primitives;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import static com.facebook.presto.bytecode.ParameterizedType.type;
import static java.util.Objects.requireNonNull;
public class AnnotationDefinition
{
private static final Set> ALLOWED_TYPES = ImmutableSet.>builder()
.addAll(Primitives.allWrapperTypes())
.add(String.class)
.add(Class.class)
.add(ParameterizedType.class)
.add(AnnotationDefinition.class)
.add(Enum.class)
.build();
private final ParameterizedType type;
private final Map values = new LinkedHashMap<>();
public AnnotationDefinition(Class> type)
{
this.type = type(type);
}
public AnnotationDefinition(ParameterizedType type)
{
this.type = type;
}
public AnnotationDefinition setValue(String name, Byte value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Boolean value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Character value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Short value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Integer value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Long value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Float value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Double value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, String value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Class> value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, ParameterizedType value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, AnnotationDefinition value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, Enum> value)
{
return setValueInternal(name, value);
}
public AnnotationDefinition setValue(String name, List> value)
{
return setValueInternal(name, value);
}
private AnnotationDefinition setValueInternal(String name, Object value)
{
requireNonNull(name, "name is null");
requireNonNull(value, "value is null");
isValidType(value);
values.put(name, value);
return this;
}
public ParameterizedType getType()
{
return type;
}
public Map getValues()
{
// todo we need an unmodifiable view
return values;
}
private static void isValidType(Object value)
{
if (value instanceof List) {
// todo verify list contains single type
for (Object v : (List