Package org.apache.beehive.wsm.processor.apt

Source Code of org.apache.beehive.wsm.processor.apt.MirrorParameterInfo

package org.apache.beehive.wsm.processor.apt;

/*
* Copyright 2004 The Apache Software Foundation
*
* 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.
*
* $Header:$Factory
*/

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;

import com.sun.mirror.declaration.AnnotationMirror;
import com.sun.mirror.declaration.Modifier;
import com.sun.mirror.declaration.ParameterDeclaration;

import com.sun.mirror.apt.AnnotationProcessorEnvironment;

import com.sun.mirror.type.AnnotationType;

import org.apache.beehive.wsm.model.java.JavaParameterInfo;

public class MirrorParameterInfo implements JavaParameterInfo {
   
    protected ParameterDeclaration decl;
    protected AnnotationProcessorEnvironment env;
    protected Class clazz;
   
    public MirrorParameterInfo(ParameterDeclaration decl, AnnotationProcessorEnvironment env) {
        if (null == decl) {
            throw new IllegalArgumentException("parameter declaration: <null>");
        }
        this.decl = decl;
        this.env = env;
       
        // ensure required properties
        try {
            clazz = TypeMirrorUtil.classForName(decl.getType());
        }
        catch (ClassNotFoundException e) {
            logError("cannot find parameter type: " + decl.getType());       
        }
    }
   
    public void logError(String msg) {
        if (null != env) {
            env.getMessager().printError(decl.getPosition(), msg);
        }
    }

    public boolean isFinal() {
        return decl.getModifiers().contains(Modifier.FINAL);
    }

    public String getName() {
        return decl.getSimpleName();
    }
   
    public Class getType() {
        return clazz;
    }
   
    public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
        return decl.getAnnotation(annotationType);
    }
   
    public Collection<Annotation> getAnnotations() {
        Collection<Annotation> annotations = new ArrayList<Annotation>();
        for (AnnotationMirror am : decl.getAnnotationMirrors()) {
            AnnotationType at = am.getAnnotationType();
            try {
                Class clazz = Class.forName(at.getDeclaration().getQualifiedName());
                Annotation a = decl.getAnnotation(clazz);
                if (null != a) {
                    annotations.add(a);
                }
            }
            catch (ClassNotFoundException e) {
            }
        }
        return annotations;
    }
}
TOP

Related Classes of org.apache.beehive.wsm.processor.apt.MirrorParameterInfo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.