当前位置: 首页>>代码示例>>Java>>正文


Java IAnnotatable.getAnnotation方法代码示例

本文整理汇总了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());
}
 
开发者ID:eclipse,项目名称:che,代码行数:4,代码来源:GenericRefactoringHandleTransplanter.java

示例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


注:本文中的org.eclipse.jdt.core.IAnnotatable.getAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。