-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-26535] added support for parameterized parameter types #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,47 +61,47 @@ static ParameterType of(Type type) { | |
if (c.isArray()) { | ||
return new ArrayType(c); | ||
} | ||
// Assume it is a nested object of some sort. | ||
Set<Class<?>> subtypes = DescribableModel.findSubtypes(c); | ||
if ((subtypes.isEmpty() && !Modifier.isAbstract(c.getModifiers())) || subtypes.equals(Collections.singleton(c))) { | ||
// Probably homogeneous. (Might be concrete but subclassable.) | ||
return new HomogeneousObjectType(c); | ||
} else { | ||
// Definitely heterogeneous. | ||
Map<String,List<Class<?>>> subtypesBySimpleName = new HashMap<String,List<Class<?>>>(); | ||
for (Class<?> subtype : subtypes) { | ||
String simpleName = subtype.getSimpleName(); | ||
List<Class<?>> bySimpleName = subtypesBySimpleName.get(simpleName); | ||
if (bySimpleName == null) { | ||
subtypesBySimpleName.put(simpleName, bySimpleName = new ArrayList<Class<?>>()); | ||
} | ||
bySimpleName.add(subtype); | ||
} | ||
if (Types.isSubClassOf(type, Collection.class)) { | ||
return new ArrayType(type, of(Types.getTypeArgument(Types.getBaseClass(type,Collection.class), 0, Object.class))); | ||
} | ||
Class<?> c = Types.erasure(type); | ||
// Assume it is a nested object of some sort. | ||
Set<Class<?>> subtypes = DescribableModel.findSubtypes(type); | ||
if ((subtypes.isEmpty() && !Modifier.isAbstract(c.getModifiers())) || subtypes.equals(Collections.singleton(c))) { | ||
// Probably homogeneous. (Might be concrete but subclassable.) | ||
return new HomogeneousObjectType(c); | ||
} else { | ||
// Definitely heterogeneous. | ||
Map<String, List<Class<?>>> subtypesBySimpleName = new HashMap<String, List<Class<?>>>(); | ||
for (Class<?> subtype : subtypes) { | ||
String simpleName = subtype.getSimpleName(); | ||
List<Class<?>> bySimpleName = subtypesBySimpleName.get(simpleName); | ||
if (bySimpleName == null) { | ||
subtypesBySimpleName.put(simpleName, bySimpleName = new ArrayList<Class<?>>()); | ||
} | ||
Map<String,DescribableModel<?>> types = new TreeMap<String,DescribableModel<?>>(); | ||
for (Map.Entry<String,List<Class<?>>> entry : subtypesBySimpleName.entrySet()) { | ||
if (entry.getValue().size() == 1) { // normal case: unambiguous via simple name | ||
bySimpleName.add(subtype); | ||
} | ||
Map<String, DescribableModel<?>> types = new TreeMap<String, DescribableModel<?>>(); | ||
for (Map.Entry<String, List<Class<?>>> entry : subtypesBySimpleName.entrySet()) { | ||
if (entry.getValue().size() == 1) { // normal case: unambiguous via simple name | ||
try { | ||
types.put(entry.getKey(), DescribableModel.of(entry.getValue().get(0))); | ||
} catch (Exception x) { | ||
LOGGER.log(Level.FINE, "skipping subtype", x); | ||
} | ||
} else { // have to diambiguate via FQN | ||
for (Class<?> subtype : entry.getValue()) { | ||
try { | ||
types.put(entry.getKey(), DescribableModel.of(entry.getValue().get(0))); | ||
types.put(subtype.getName(), DescribableModel.of(subtype)); | ||
} catch (Exception x) { | ||
LOGGER.log(Level.FINE, "skipping subtype", x); | ||
} | ||
} else { // have to diambiguate via FQN | ||
for (Class<?> subtype : entry.getValue()) { | ||
try { | ||
types.put(subtype.getName(), DescribableModel.of(subtype)); | ||
} catch (Exception x) { | ||
LOGGER.log(Level.FINE, "skipping subtype", x); | ||
} | ||
} | ||
} | ||
} | ||
return new HeterogeneousObjectType(c, types); | ||
} | ||
return new HeterogeneousObjectType(c, types); | ||
} | ||
if (Types.isSubClassOf(type, Collection.class)) { | ||
return new ArrayType(type, of(Types.getTypeArgument(Types.getBaseClass(type,Collection.class), 0, Object.class))); | ||
} | ||
throw new UnsupportedOperationException("do not know how to categorize attributes of type " + type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to have been removed and I am not sure why. Where is the fallback? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it is just not necessary any more and whatever sanity-checking was needed is already done in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback became unreachable, so I removed it. I was surprised that no unit tests failed. There is not much sanity-checking in I thought about limiting support for |
||
} catch (Exception x) { | ||
return new ErrorType(x, type); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this is actually reindentation, making the diff look a lot bigger than it actually is. Had to apply the WS ignore setting in GitHub to see it.