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 java.util.List;
import com.sun.mirror.declaration.AnnotationMirror;
import com.sun.mirror.declaration.MethodDeclaration;
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.JavaMethodInfo;
import org.apache.beehive.wsm.model.java.JavaParameterInfo;
public class MirrorMethodInfo implements JavaMethodInfo {
protected MethodDeclaration decl;
protected AnnotationProcessorEnvironment env;
protected Class returnType;
protected List<JavaParameterInfo> parameters = new ArrayList<JavaParameterInfo>();
public MirrorMethodInfo(MethodDeclaration decl, AnnotationProcessorEnvironment env) {
if (null == decl) {
throw new IllegalArgumentException("method declaration: <null>");
}
this.decl = decl;
this.env = env;
try {
returnType = TypeMirrorUtil.classForName(decl.getReturnType());
}
catch (ClassNotFoundException e) {
logError("cannot find return type: " + decl.getReturnType());
}
Collection<ParameterDeclaration> pdecls = decl.getParameters();
if (null != pdecls) {
for (ParameterDeclaration pdecl : pdecls) {
parameters.add(new MirrorParameterInfo(pdecl, env));
}
}
}
public void logError(String msg) {
env.getMessager().printError(decl.getPosition(), msg);
}
public boolean isPublic() {
return decl.getModifiers().contains(Modifier.PUBLIC);
}
public boolean throwsExceptions() {
return 0 < decl.getThrownTypes().size();
}
public String getMethodName() {
return decl.getSimpleName();
}
public Class getReturnType() {
return returnType;
}
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;
}
public List<JavaParameterInfo> getParameters() {
return parameters;
}
}