本文整理汇总了Java中com.sun.mirror.declaration.Declaration类的典型用法代码示例。如果您正苦于以下问题:Java Declaration类的具体用法?Java Declaration怎么用?Java Declaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Declaration类属于com.sun.mirror.declaration包,在下文中一共展示了Declaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProcessedHttpUrlAnnotation
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
public ProcessedHttpUrlAnnotation(String typeName, Declaration declaration, String value, int weight) {
MethodDeclaration methodDeclaration = (MethodDeclaration) declaration;
String className = methodDeclaration.getDeclaringType().getQualifiedName();
this.methodName = declaration.getSimpleName();
this.docComment = declaration.getDocComment();
this.className = className;
this.value = value;
this.weight = weight;
this.setParams(methodDeclaration.getParameters());
String typeNameShort = typeName.substring(typeName.lastIndexOf("."));
SourcePosition positionInCode = declaration.getPosition();
sourceRef = positionInCode.file().getName() + ":" + positionInCode.line();
if (!(declaration instanceof MethodDeclaration)) {
messager.printWarning(positionInCode, "@" + typeNameShort + " declared on a non-method " + positionInCode);
}
if (showPositionsOfAnnotations) {
messager.printNotice(positionInCode, "@" + typeNameShort + " value " + value + " weight " + weight);
}
}
示例2: getAllAnnotations
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Gets all the annotations on the given declaration.
*/
private Annotation[] getAllAnnotations(Declaration decl, Locatable srcPos) {
List<Annotation> r = new ArrayList<Annotation>();
for( AnnotationMirror m : decl.getAnnotationMirrors() ) {
try {
String fullName = m.getAnnotationType().getDeclaration().getQualifiedName();
Class<? extends Annotation> type =
getClass().getClassLoader().loadClass(fullName).asSubclass(Annotation.class);
Annotation annotation = decl.getAnnotation(type);
if(annotation!=null)
r.add( LocatableAnnotation.create(annotation,srcPos) );
} catch (ClassNotFoundException e) {
// just continue
}
}
return r.toArray(EMPTY_ANNOTATION);
}
示例3: getFilter
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects declarations containing all of a
* collection of modifiers.
*
* @param mods the modifiers to match (non-null)
* @return a filter that matches declarations containing <tt>mods</tt>
*/
public static DeclarationFilter getFilter(
final Collection<Modifier> mods) {
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return d.getModifiers().containsAll(mods);
}
};
}
示例4: and
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects those declarations selected
* by both this filter and another.
*
* @param f filter to be composed with this one
* @return a filter that selects those declarations selected by
* both this filter and another
*/
public DeclarationFilter and(DeclarationFilter f) {
final DeclarationFilter f1 = this;
final DeclarationFilter f2 = f;
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return f1.matches(d) && f2.matches(d);
}
};
}
示例5: or
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects those declarations selected
* by either this filter or another.
*
* @param f filter to be composed with this one
* @return a filter that selects those declarations selected by
* either this filter or another
*/
public DeclarationFilter or(DeclarationFilter f) {
final DeclarationFilter f1 = this;
final DeclarationFilter f2 = f;
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return f1.matches(d) || f2.matches(d);
}
};
}
示例6: not
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects those declarations not selected
* by this filter.
*
* @return a filter that selects those declarations not selected
* by this filter
*/
public DeclarationFilter not() {
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return !DeclarationFilter.this.matches(d);
}
};
}
示例7: matches
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
public boolean matches(Declaration d) {
Collection<Modifier> mods = d.getModifiers();
if (mod1 == null) { // looking for package private
return !(mods.contains(PUBLIC) ||
mods.contains(PROTECTED) ||
mods.contains(PRIVATE));
}
return mods.contains(mod1) &&
(mod2 == null || mods.contains(mod2));
}
示例8: getFilter
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects declarations containing all of a
* collection of modifiers.
*
* @param mods the modifiers to match (non-null)
* @return a filter that matches declarations containing <tt>mods</tt>
*/
public static DeclarationFilter getFilter(
final Collection<Modifier> mods) {
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return d.getModifiers().containsAll(mods);
}
};
}
示例9: and
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects those declarations selected
* by both this filter and another.
*
* @param f filter to be composed with this one
* @return a filter that selects those declarations selected by
* both this filter and another
*/
public DeclarationFilter and(DeclarationFilter f) {
final DeclarationFilter f1 = this;
final DeclarationFilter f2 = f;
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return f1.matches(d) && f2.matches(d);
}
};
}
示例10: or
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects those declarations selected
* by either this filter or another.
*
* @param f filter to be composed with this one
* @return a filter that selects those declarations selected by
* either this filter or another
*/
public DeclarationFilter or(DeclarationFilter f) {
final DeclarationFilter f1 = this;
final DeclarationFilter f2 = f;
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return f1.matches(d) || f2.matches(d);
}
};
}
示例11: not
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Returns a filter that selects those declarations not selected
* by this filter.
*
* @return a filter that selects those declarations not selected
* by this filter
*/
public DeclarationFilter not() {
return new DeclarationFilter() {
public boolean matches(Declaration d) {
return !DeclarationFilter.this.matches(d);
}
};
}
示例12: matches
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
public boolean matches(Declaration d) {
Collection<Modifier> mods = d.getModifiers();
if (mod1 == null) { // looking for package private
return !(mods.contains(PUBLIC) ||
mods.contains(PROTECTED) ||
mods.contains(PRIVATE));
}
return mods.contains(mod1) &&
(mod2 == null || mods.contains(mod2));
}
示例13: processHttpExceptionHandlerAnnotation
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
private ProcessedHttpExceptionAnnotation processHttpExceptionHandlerAnnotation(Declaration declaration) {
SourcePosition position = declaration.getPosition();
if (!(declaration instanceof MethodDeclaration)) {
messager.printWarning(declaration.getPosition(), "@HttpExceptionHandler declared on a non-method " + position);
return null;
}
MethodDeclaration methodDeclaration = (MethodDeclaration) declaration;
HttpExceptionHandler httpExceptionHandler = declaration.getAnnotation(HttpExceptionHandler.class);
String className = methodDeclaration.getDeclaringType().getQualifiedName();
ProcessedHttpExceptionAnnotation ea = new ProcessedHttpExceptionAnnotation();
ea.exceptionName = httpExceptionHandler.value(); //.getName();
ea.methodName = declaration.getSimpleName();
ea.docComment = declaration.getDocComment();
ea.className = className;
ea.setParams(methodDeclaration.getParameters());
// out exceptionName might not be set
if ("[ unassigned ]".equals(ea.exceptionName) && methodDeclaration.getParameters().size() > 0) {
// use first param
ea.exceptionName = methodDeclaration.getParameters().iterator().next().getType().toString();
}
if (showPositionsOfAnnotations) {
messager.printNotice(position, "@HttpExceptionHandlerUrl value " + ea.value + " weight " + ea.weight);
}
return ea;
}
示例14: Reference
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
/**
* Creates a reference by providing two values independently.
*/
public Reference(TypeMirror type, Declaration annotations) {
if(type==null || annotations==null)
throw new IllegalArgumentException();
this.type = type;
this.annotations = annotations;
}
示例15: sort
import com.sun.mirror.declaration.Declaration; //导入依赖的package包/类
private <A extends Declaration> List<A> sort(List<A> l) {
if(l.isEmpty()) return l;
// APT supports the operation mode where it creates Declarations from
// a class file, in which case the source position is not available
// use that as a key to sort them correctly. This isn't "correct" in
// the sense that it relies on undocumented behavior of APT where
// it returns declarations in the reverse order, but this makes things work.
SourcePosition pos = l.get(0).getPosition();
if(pos!=null)
Collections.sort(l,SOURCE_POS_COMPARATOR);
else
Collections.reverse(l);
return l;
}