From a94a775ff2f0f5c8d48f007d495f43c0dac8516d Mon Sep 17 00:00:00 2001 From: Leo Dos Santos Date: Fri, 27 Apr 2012 11:30:41 -0700 Subject: [PATCH] IDE-1244: RequestMappings does not include mappings defined on interfaces https://jira.springsource.org/browse/IDE-1244 --- .../JdtBasedAnnotationMetadata.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/annotation/JdtBasedAnnotationMetadata.java b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/annotation/JdtBasedAnnotationMetadata.java index ed08655eee..288d2bd08d 100644 --- a/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/annotation/JdtBasedAnnotationMetadata.java +++ b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/annotation/JdtBasedAnnotationMetadata.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Spring IDE Developers + * Copyright (c) 2009 - 2012 Spring IDE Developers * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -33,6 +33,7 @@ * {@link IAnnotationMetadata} implementation that uses Eclipse JDT core model information for * extracting the metadata. * @author Christian Dupuis + * @author Leo Dos Santos * @since 2.2.2 */ public class JdtBasedAnnotationMetadata implements IAnnotationMetadata { @@ -72,6 +73,10 @@ private void init() { for (IAnnotation annotation : method.getAnnotations()) { modelAnnotations.add(processAnnotation(annotation)); } + if (modelAnnotations.size() <= 0) { + // If no annotations found on concrete method, look for them on the interface + modelAnnotations = processInterfaceMethods(method); + } if (modelAnnotations.size() > 0) { methodAnnotations.put(method, modelAnnotations); } @@ -100,13 +105,13 @@ private void init() { } } - private Annotation processAnnotation(IAnnotation annotation) { + private Annotation processAnnotation(IAnnotation annotation, IType itype) { Annotation modelAnnotation; - if (type.isBinary()) { + if (itype.isBinary()) { modelAnnotation = new Annotation(annotation.getElementName()); } else { - modelAnnotation = new Annotation(JdtUtils.resolveClassName(annotation.getElementName(), type)); + modelAnnotation = new Annotation(JdtUtils.resolveClassName(annotation.getElementName(), itype)); } try { for (IMemberValuePair member : annotation.getMemberValuePairs()) { @@ -136,6 +141,25 @@ else if (member.getValue() != null) { } return modelAnnotation; } + + private Annotation processAnnotation(IAnnotation annotation) { + return processAnnotation(annotation, type); + } + + private Set processInterfaceMethods(IMethod method) throws JavaModelException { + Set modelAnnotations = new LinkedHashSet(); + Set interfaces = Introspector.getAllImplementedInterfaces(type); + for (IType iface : interfaces) { + IMethod[] interfaceMethod = iface.findMethods(method); + if (interfaceMethod != null && interfaceMethod.length > 0) { + for (IAnnotation annotation : interfaceMethod[0].getAnnotations()) { + modelAnnotations.add(processAnnotation(annotation, iface)); + } + } + } + return modelAnnotations; + } + private void processStringValue(IMemberValuePair member, StringBuilder builder, String value) { // class value