本文整理汇总了Java中org.eclipse.jdt.core.IAnnotatable类的典型用法代码示例。如果您正苦于以下问题:Java IAnnotatable类的具体用法?Java IAnnotatable怎么用?Java IAnnotatable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAnnotatable类属于org.eclipse.jdt.core包,在下文中一共展示了IAnnotatable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isHiddenGeneratedElement
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
public static boolean isHiddenGeneratedElement(IJavaElement element) {
// generated elements are tagged with javax.annotation.Generated and
// they need to be filtered out
if (element instanceof IAnnotatable) {
try {
IAnnotation[] annotations = ((IAnnotatable) element).getAnnotations();
if (annotations.length != 0) {
for (IAnnotation annotation : annotations) {
if (isSilencedGeneratedAnnotation(annotation)) {
return true;
}
}
}
} catch (JavaModelException e) {
// ignore
}
}
return false;
}
示例2: isHiddenGeneratedElement
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
public static boolean isHiddenGeneratedElement(IJavaElement element) {
// generated elements are tagged with javax.annotation.Generated and
// they need to be filtered out
if (element instanceof IAnnotatable) {
try {
IAnnotation[] annotations = ((IAnnotatable) element).getAnnotations();
if (annotations.length != 0) {
for (IAnnotation annotation : annotations) {
if (isSilencedGeneratedAnnotation(annotation)) {
return true;
}
}
}
} catch (JavaModelException e) {
//ignore
}
}
return false;
}
示例3: appendFlags
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
protected void appendFlags(final IMember member) throws JavaModelException {
if (member instanceof IAnnotatable)
for (IAnnotation annotation : ((IAnnotatable) member).getAnnotations()) {
appendAnnotation(annotation);
}
int flags = member.getFlags();
final int kind = member.getElementType();
if (kind == IJavaElement.TYPE) {
flags &= ~Flags.AccSuper;
final IType type = (IType) member;
if (!type.isMember()) flags &= ~Flags.AccPrivate;
if (Flags.isEnum(flags)) flags &= ~Flags.AccAbstract;
}
if (Flags.isEnum(flags)) flags &= ~Flags.AccFinal;
if (kind == IJavaElement.METHOD) {
flags &= ~Flags.AccVarargs;
flags &= ~Flags.AccBridge;
}
if (flags != 0) fBuffer.append(Flags.toString(flags));
}
示例4: shouldWriteMarkers
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
private boolean shouldWriteMarkers(IJavaElement currentElement) {
IJavaElement parent = currentElement;
while (parent != null) {
if (parent instanceof IAnnotatable) {
IAnnotatable p = (IAnnotatable) parent;
try {
for (IAnnotation a : p.getAnnotations()) {
if (a.getElementName().equalsIgnoreCase("EvoIgnore")) {
return false;
}
}
} catch (JavaModelException e) {
e.printStackTrace();
}
}
parent = parent.getParent();
}
return true;
}
示例5: appendFlags
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
protected void appendFlags(final IMember member) throws JavaModelException {
if (member instanceof IAnnotatable)
for (IAnnotation annotation : ((IAnnotatable) member).getAnnotations()) {
appendAnnotation(annotation);
}
int flags= member.getFlags();
final int kind= member.getElementType();
if (kind == IJavaElement.TYPE) {
flags&= ~Flags.AccSuper;
final IType type= (IType) member;
if (!type.isMember())
flags&= ~Flags.AccPrivate;
if (Flags.isEnum(flags))
flags&= ~Flags.AccAbstract;
}
if (Flags.isEnum(flags))
flags&= ~Flags.AccFinal;
if (kind == IJavaElement.METHOD) {
flags&= ~Flags.AccVarargs;
flags&= ~Flags.AccBridge;
}
if (flags != 0)
fBuffer.append(Flags.toString(flags));
}
示例6: readMarkerAnnotation
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
public List<String> readMarkerAnnotation(IAnnotatable annotatable) throws JavaModelException
{
List<String> markers = new ArrayList<String>();
IAnnotation annotation = TapestryUtils.findAnnotation(annotatable.getAnnotations(),
TapestryUtils.ORG_APACHE_TAPESTRY5_IOC_ANNOTATIONS_MARKER);
if (annotation != null)
{
String[] typeLiterals = EclipseUtils.readValuesFromAnnotation(getEclipseProject(), annotation, "value");
for (String typeLiteral : typeLiterals)
{
String typeName = EclipseUtils.resolveTypeName(moduleClass, typeLiteral);
markers.add(typeName);
}
}
return markers;
}
示例7: extractMarkers
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
private List<String> extractMarkers(IAnnotatable annotatable, Set<String> skipAnnotations)
throws JavaModelException
{
List<String> markers = new ArrayList<String>();
for (IAnnotation annotation : annotatable.getAnnotations())
{
String typeName = EclipseUtils.resolveTypeName(
tapestryModule.getModuleClass(), annotation.getElementName());
if (skipAnnotations.contains(typeName))
{
continue;
}
markers.add(typeName);
}
return markers;
}
示例8: getAnnotation
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
/**
* Obtient une annotation d'un nom donné sur un objet donné.
*
* @param annotable Objet à inspecter.
* @param name Nom de l'annotation.
* @return Annotation, <code>null</code> sinon.
*/
public static IAnnotation getAnnotation(IAnnotatable annotable, String name) {
try {
for (IAnnotation annotation : annotable.getAnnotations()) {
String annotationName = StringUtils.getLastNameFragment(annotation.getElementName());
if (name.equals(annotationName)) {
return annotation;
}
}
} catch (JavaModelException e) {
ErrorUtils.handle(e);
}
return null;
}
示例9: convertAnnotations
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException {
IAnnotation[] annotations = element.getAnnotations();
int length = annotations.length;
Annotation[] astAnnotations = new Annotation[length];
if (length > 0) {
char[] cuSource = getSource();
int recordedAnnotations = 0;
for (int i = 0; i < length; i++) {
ISourceRange positions = annotations[i].getSourceRange();
int start = positions.getOffset();
int end = start + positions.getLength();
char[] annotationSource = CharOperation.subarray(cuSource, start, end);
if (annotationSource != null) {
Expression expression = parseMemberValue(annotationSource);
/*
* expression can be null or not an annotation if the source has changed between
* the moment where the annotation source positions have been retrieved and the moment were
* this parsing occurred.
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=90916
*/
if (expression instanceof Annotation) {
astAnnotations[recordedAnnotations++] = (Annotation) expression;
}
}
}
if (length != recordedAnnotations) {
// resize to remove null annotations
System.arraycopy(
astAnnotations,
0,
(astAnnotations = new Annotation[recordedAnnotations]),
0,
recordedAnnotations);
}
}
return astAnnotations;
}
示例10: getAnnotation
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
/**
* Gets the corresponding IAnnotation.
*
* @param qualifiedAnnotationName the fully qualified annotation type name
* @param annotatable the IAnnotatable java element which contains the
* annotation
* @param contextType the type which is used to lookup imports
* @return the IAnnotation or null
* @throws JavaModelException
*/
public static Object getAnnotation(String qualifiedAnnotationName,
Object annotatable, IType contextType) throws JavaModelException {
for (IAnnotation annotation : ((IAnnotatable) annotatable).getAnnotations()) {
if (qualifiedAnnotationName.equals(resolveTypeName(contextType,
annotation.getElementName()))) {
return annotation;
}
}
return null;
}
示例11: consumeAnnotation
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
public void consumeAnnotation() {
if (!(this.element instanceof IAnnotatable)) return;
int size = this.types.size();
if (size == 0) return;
IJavaElement annotationType = ((JavaElementFinder) this.types.get(size-1)).element;
this.element = ((IAnnotatable) this.element).getAnnotation(annotationType.getElementName());
}
示例12: convertAnnotations
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException {
IAnnotation[] annotations = element.getAnnotations();
int length = annotations.length;
Annotation[] astAnnotations = new Annotation[length];
if (length > 0) {
char[] cuSource = getSource();
int recordedAnnotations = 0;
for (int i = 0; i < length; i++) {
ISourceRange positions = annotations[i].getSourceRange();
int start = positions.getOffset();
int end = start + positions.getLength();
char[] annotationSource = CharOperation.subarray(cuSource, start, end);
if (annotationSource != null) {
Expression expression = parseMemberValue(annotationSource);
/*
* expression can be null or not an annotation if the source has changed between
* the moment where the annotation source positions have been retrieved and the moment were
* this parsing occurred.
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=90916
*/
if (expression instanceof Annotation) {
astAnnotations[recordedAnnotations++] = (Annotation) expression;
}
}
}
if (length != recordedAnnotations) {
// resize to remove null annotations
System.arraycopy(astAnnotations, 0, (astAnnotations = new Annotation[recordedAnnotations]), 0, recordedAnnotations);
}
}
return astAnnotations;
}
示例13: getAnnotationAt
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
public static IAnnotation getAnnotationAt(IAnnotatable annotatable, int offset)
throws JavaModelException
{
IAnnotation[] annotations = annotatable.getAnnotations();
for (IAnnotation annotation : annotations)
{
ISourceRange sourceRange = annotation.getSourceRange();
if (isInRange(sourceRange, offset))
{
return annotation;
}
}
return null;
}
示例14: getAnnotations
import org.eclipse.jdt.core.IAnnotatable; //导入依赖的package包/类
private static String getAnnotations(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) throws URISyntaxException, JavaModelException {
if (!(element instanceof IAnnotatable))
return null;
if (((IAnnotatable)element).getAnnotations().length == 0)
return null;
IBinding binding;
ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion);
if (node == null) {
ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
p.setProject(element.getJavaProject());
try {
binding= p.createBindings(new IJavaElement[] { element }, null)[0];
} catch (OperationCanceledException e) {
return null;
}
} else {
binding= resolveBinding(node);
}
if (binding == null)
return null;
IAnnotationBinding[] annotations= binding.getAnnotations();
if (annotations.length == 0)
return null;
StringBuffer buf= new StringBuffer();
for (int i= 0; i < annotations.length; i++) {
//TODO: skip annotations that don't have an @Documented annotation?
addAnnotation(buf, element, annotations[i]);
buf.append("<br>"); //$NON-NLS-1$
}
return buf.toString();
}
示例15: 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