本文整理汇总了Java中org.eclipse.jdt.core.IAnnotatable.getAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java IAnnotatable.getAnnotation方法的具体用法?Java IAnnotatable.getAnnotation怎么用?Java IAnnotatable.getAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IAnnotatable
的用法示例。
在下文中一共展示了IAnnotatable.getAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkAnnotations
import org.eclipse.jdt.core.IAnnotatable; //导入方法依赖的package包/类
private RefactoringStatus checkAnnotations(IAnnotatable source, IType sourceType, IAnnotatable target,
IType targetType) throws JavaModelException {
// a set of annotations from the source method.
Set<IAnnotation> sourceAnnotationSet = new HashSet<>(Arrays.asList(source.getAnnotations()));
// remove any annotations to not consider.
removeSpecialAnnotations(sourceAnnotationSet, sourceType);
// a set of source method annotation names.
Set<String> sourceMethodAnnotationElementNames = getAnnotationElementNames(sourceAnnotationSet);
// a set of annotations from the target method.
Set<IAnnotation> targetAnnotationSet = new HashSet<>(Arrays.asList(target.getAnnotations()));
// remove any annotations to not consider.
removeSpecialAnnotations(targetAnnotationSet, targetType);
// a set of target method annotation names.
Set<String> targetAnnotationElementNames = getAnnotationElementNames(targetAnnotationSet);
// if the source method annotation names don't match the target method
// annotation names.
if (!sourceMethodAnnotationElementNames.equals(targetAnnotationElementNames))
return RefactoringStatus.createErrorStatus(PreconditionFailure.AnnotationNameMismatch.getMessage(),
new RefactoringStatusContext() {
@Override
public Object getCorrespondingElement() {
return source;
}
});
else
// otherwise, we have the same annotations names. Check the values.
for (IAnnotation sourceAnnotation : sourceAnnotationSet) {
IMemberValuePair[] sourcePairs = sourceAnnotation.getMemberValuePairs();
IAnnotation targetAnnotation = target.getAnnotation(sourceAnnotation.getElementName());
IMemberValuePair[] targetPairs = targetAnnotation.getMemberValuePairs();
if (sourcePairs.length != targetPairs.length) {
// TODO: Can perhaps analyze this situation further by
// looking up default field values.
logWarning(
"There may be differences in the length of the value vectors as some annotations may use default field values.");
return new RefactoringStatus();
}
Arrays.parallelSort(sourcePairs, Comparator.comparing(IMemberValuePair::getMemberName));
Arrays.parallelSort(targetPairs, Comparator.comparing(IMemberValuePair::getMemberName));
for (int i = 0; i < sourcePairs.length; i++)
if (!sourcePairs[i].getMemberName().equals(targetPairs[i].getMemberName())
|| sourcePairs[i].getValueKind() != targetPairs[i].getValueKind()
|| !(sourcePairs[i].getValue().equals(targetPairs[i].getValue())))
return RefactoringStatus.createErrorStatus(
formatMessage(PreconditionFailure.AnnotationValueMismatch.getMessage(),
sourceAnnotation, targetAnnotation),
JavaStatusContext.create(findEnclosingMember(sourceAnnotation)));
}
return new RefactoringStatus(); // OK.
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:62,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java
示例2: transplantHandle
import org.eclipse.jdt.core.IAnnotatable; //导入方法依赖的package包/类
protected IAnnotation transplantHandle(IAnnotatable parent, IAnnotation element) {
return parent.getAnnotation(element.getElementName());
}
示例3: transplantHandle
import org.eclipse.jdt.core.IAnnotatable; //导入方法依赖的package包/类
protected IAnnotation transplantHandle(IAnnotatable parent, IAnnotation element) {
return parent.getAnnotation(element.getElementName());
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:4,代码来源:GenericRefactoringHandleTransplanter.java