Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010-2012 eBusiness Information, Excilys Group 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.googlecode.androidannotations.helper;
 
 import static com.googlecode.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;
 
 import java.util.List;
 
 
 public class AnnotationHelper {
 
 
 	public AnnotationHelper(ProcessingEnvironment processingEnv) {
 		this. = processingEnv;
 	}

Tests whether one type is a subtype of another. Any type is considered to be a subtype of itself. This method adds additional behavior : if Types.isSubtype(TypeMirror, TypeMirror) returns false, and the inheritance chain of potentialSubtype contains an ErrorType that ends with a "_" at the end of its name, we return true. That's because when the code is cleaned and regenerated all at once, the "_" don't exist any more. Our assumption is that it can't do much harm in those cases. A better implementation would be to take advantage of the multiple rounds of annotation processing, and do those checks in later rounds.

Parameters:
potentialSubtype the first type
potentialSupertype the second type
Returns:
true if and only if the first type is a subtype of the second
Throws:
java.lang.IllegalArgumentException if given an executable or package type
See also:
javax.lang.model.util.Types.isSubtype(javax.lang.model.type.TypeMirror,javax.lang.model.type.TypeMirror)
 
 	public boolean isSubtype(TypeMirror potentialSubtypeTypeMirror potentialSupertype) {
 
 		if (.getTypeUtils().isSubtype(potentialSubtypepotentialSupertype)) {
 			return true;
 		} else {
 
 			if (potentialSubtype instanceof DeclaredType) {
 
 				DeclaredType potentialDeclaredSubtype = (DeclaredTypepotentialSubtype;
 
 				Element potentialSubElement = potentialDeclaredSubtype.asElement();
 				if (potentialSubElement instanceof TypeElement) {
 					TypeElement potentialSubDeclaredElement = (TypeElementpotentialSubElement;
 
 					TypeMirror superclassTypeMirror = potentialSubDeclaredElement.getSuperclass();
 
 					if (isRootObjectClass(superclassTypeMirror)) {
 						return false;
 					} else {
 						if (superclassTypeMirror instanceof ErrorType) {
 
 							ErrorType errorType = (ErrorTypesuperclassTypeMirror;
 
 							Element errorElement = errorType.asElement();
 
 							String errorElementSimpleName = errorElement.getSimpleName().toString();
 							if (errorElementSimpleName.endsWith()) {
 								return true;
 							} else {
 								.getMessager().printMessage(., String.format("The supertype %s of the potential subElement %s of potential supertype %s is an ErrorType that doesn't end with %s"errorElementpotentialSubElementpotentialSupertype));
 								return false;
 							}
else {
							return isSubtype(superclassTypeMirrorpotentialSupertype);
						}
					}
else {
					.getMessager().printMessage(., String.format("The potential subElement %s of potential supertype %s is not a TypeElement but a %s"potentialSubElementpotentialSupertypepotentialSubElement.getClass()));
					return false;
				}
else {
				.getMessager().printMessage(., String.format("The potential subtype %s of potential supertype %s is not a DeclaredType but a %s"potentialSubtypepotentialSupertypepotentialSubtype.getClass()));
				return false;
			}
		}
	}
	private boolean isRootObjectClass(TypeMirror superclassTypeMirror) {
		return superclassTypeMirror.getKind() == .;
	}
	public boolean isSubtype(TypeElement t1TypeElement t2) {
		return isSubtype(t1.asType(), t2.asType());
	}

This method may return null if the javax.lang.model.element.TypeElement cannot be found in the processor classpath
	}
	public AnnotationMirror findAnnotationMirror(Element annotatedElementClass<? extends AnnotationannotationClass) {
		List<? extends AnnotationMirrorannotationMirrors = annotatedElement.getAnnotationMirrors();
		for (AnnotationMirror annotationMirror : annotationMirrors) {
			TypeElement annotationElement = (TypeElementannotationMirror.getAnnotationType().asElement();
			if (isAnnotation(annotationElementannotationClass)) {
				return annotationMirror;
			}
		}
		return null;
	}
	public boolean isAnnotation(TypeElement annotationClass<? extends AnnotationannotationClass) {
		return annotation.getQualifiedName().toString().equals(annotationClass.getName());
	}
	public void printAnnotationError(Element annotatedElementClass<? extends AnnotationannotationClassString message) {
		printAnnotationMessage(..annotatedElementannotationClassmessage);
	}
	public void printAnnotationWarning(Element annotatedElementClass<? extends AnnotationannotationClassString message) {
		printAnnotationMessage(..annotatedElementannotationClassmessage);
	}
	public void printAnnotationMessage(Diagnostic.Kind diagnosticKindElement annotatedElementClass<? extends AnnotationannotationClassString message) {
		AnnotationMirror annotationMirror = findAnnotationMirror(annotatedElementannotationClass);
		if (annotationMirror != null) {
			.getMessager().printMessage(diagnosticKindmessageannotatedElementannotationMirror);
else {
			printError(annotatedElementmessage);
		}
	}
	public void printError(Element elementString message) {
	}
	public boolean isPrivate(Element element) {
	}
	public boolean isAbstract(Element element) {
	}
	public boolean isInterface(TypeElement element) {
		return element.getKind().isInterface();
	}
	public boolean isTopLevel(TypeElement element) {
		return element.getNestingKind() == .;
	}
	public boolean isFinal(Element element) {
		return element.getModifiers().contains(.);
	}
	public boolean isSynchronized(Element element) {
	}
	}
	public Types getTypeUtils() {
	}
New to GrepCode? Check out our FAQ X