From e771f3f56dba5a33ada238dc7d733f1b68fc5dd8 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 27 Apr 2005 03:59:06 +0000 Subject: [PATCH] fixed override of ancestor fields with locally declared ones in parameter processing git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164942 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/JavaMojoDescriptorExtractor.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index 8ed605ce7e..8810148759 100644 --- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -37,7 +37,10 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; +import java.util.Map.Entry; /** * @todo add example usage tag that can be shown in the doco @@ -227,7 +230,7 @@ public class JavaMojoDescriptorExtractor // We're resolving class-level, ancestor-class-field, local-class-field order here. // --------------------------------------------------------------------------------- - List rawParams = new ArrayList(); + Map rawParams = new TreeMap(); // for backward compat, we'll toss on the params declared at the class level. DocletTag[] classLevelParams = javaClass.getTagsByName( PARAMETER ); @@ -252,31 +255,34 @@ public class JavaMojoDescriptorExtractor System.err.println( message ); } - rawParams.add( tag ); + rawParams.put( tag.getNamedParameter("name"), tag ); } } - + extractFieldParameterTags( javaClass, rawParams ); Set parameters = new HashSet(); - for ( Iterator it = rawParams.iterator(); it.hasNext(); ) + for ( Iterator it = rawParams.entrySet().iterator(); it.hasNext(); ) { - Object parameterInfo = it.next(); - + Map.Entry entry = (Entry) it.next(); + String paramName = (String) entry.getKey(); + + Object val = entry.getValue(); + JavaField field = null; DocletTag parameter = null; // FIXME: ICK! This is only here for backward compatibility to the class-level annotations of params. - if ( parameterInfo instanceof JavaField ) + if ( val instanceof JavaField ) { - field = (JavaField) parameterInfo; + field = (JavaField) val; parameter = field.getTagByName( PARAMETER ); } else { - parameter = (DocletTag) parameterInfo; + parameter = (DocletTag) val; } Parameter pd = new Parameter(); @@ -285,7 +291,7 @@ public class JavaMojoDescriptorExtractor // TODO: remove when backward compatibility is no longer an issue. if ( field == null ) { - pd.setName( parameter.getNamedParameter( "name" ) ); + pd.setName( paramName ); pd.setType( parameter.getNamedParameter( "type" ) ); @@ -295,7 +301,7 @@ public class JavaMojoDescriptorExtractor } else { - pd.setName( field.getName() ); + pd.setName( paramName ); pd.setType( field.getType().getValue() ); @@ -326,7 +332,7 @@ public class JavaMojoDescriptorExtractor } } - private void extractFieldParameterTags( JavaClass javaClass, List rawParams ) + private void extractFieldParameterTags( JavaClass javaClass, Map rawParams ) { // we have to add the parent fields first, so that they will be overwritten by the local fields if // that actually happens... @@ -349,7 +355,7 @@ public class JavaMojoDescriptorExtractor if ( paramTag != null ) { - rawParams.add( field ); + rawParams.put( field.getName(), field ); } } }