sdedic commented on code in PR #5535:
URL: https://github.com/apache/netbeans/pull/5535#discussion_r1111327333
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -685,87 +708,10 @@ private void inspectObjectAndValues0(Class clazz, Object
object, String prefix,
NamedDomainObjectContainer nc =
(NamedDomainObjectContainer)value;
Map<String, ?> m = new HashMap<>(nc.getAsMap());
- List<String> ss = new ArrayList<>(m.keySet());
- propertyTypes.put(prefix + propName +
COLLECTION_KEYS_MARKER, String.join(";;", ss));
- for (String k : m.keySet()) {
- newPrefix = prefix + propName + "." + k + "."; //
NOI18N
- Object v = m.get(k);
- defaultValues.put(prefix + propName + "." + k,
Objects.toString(v)); // NOI18N
- inspectObjectAndValues(v.getClass(), v, newPrefix,
globalTypes, propertyTypes, defaultValues, null, false);
- }
+ dumpContainerProperties(m, prefix + propName,
defaultValues);
Review Comment:
Extracted into a method, to allow call from `inspectExtensions'.
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -538,32 +545,45 @@ private boolean isMutableType(Object potentialValue) {
return adapter.isMutableType(potentialValue);
}
+ private void addNestedKeys(String prefix, Map<String, String>
propertyTypes, Collection<String> keys) {
+ propertyTypes.merge(prefix + COLLECTION_KEYS_MARKER,
String.join(";;", keys), (old, add) -> {
+ List<String> oldList = new
ArrayList<>(Arrays.asList(old.split(";;")));
+ List<String> newList = Arrays.asList(add.split(";;"));
+ oldList.addAll(newList);
+ return String.join(";;", oldList);
+ });
+ }
+
private void inspectObjectAndValues0(Class clazz, Object object, String
prefix, Map<String, Map<String, String>> globalTypes, Map<String, String>
propertyTypes, Map<String, Object> defaultValues, Set<String> excludes, boolean
type) {
Class nonDecorated = findNonDecoratedClass(clazz);
// record object's type first, even though the value may be excluded
(i.e. ignored class). Do not add types for collection or map items -- to much
clutter.
+ String typeKey = prefix;
+ if (prefix.endsWith(".")) {
+ typeKey = prefix.substring(0, prefix.length() - 1);
+ } else {
+ typeKey = prefix;
+ }
if (type) {
- String typeKey = prefix;
- if (prefix.endsWith(".")) {
- typeKey = prefix.substring(0, prefix.length() - 1);
- } else {
- typeKey = prefix;
- }
if (propertyTypes.putIfAbsent(typeKey, nonDecorated.getName()) !=
null && object == null) {
// type already introspected, no value to fetch properties
from.
return;
}
}
- if (clazz == null || (excludes == null &&
ignoreClassesPattern.matcher(clazz.getName()).matches())) {
+
+ if (clazz == null || clazz.isEnum()) {
return;
}
- if (clazz.isEnum() || clazz.isArray()) {
+ if (clazz.isArray() || (excludes == null &&
ignoreClassesPattern.matcher(clazz.getName()).matches())) {
Review Comment:
The condition for shortcut path remain the same; but now the implementation
tries to export Maps and Lists. Covers the case when `inspectObjectAndValues0`
is called for e.g. java.util.HashMap object, which is otherwise excluded by
filters - i.e. Map inside a Map.
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -685,87 +708,10 @@ private void inspectObjectAndValues0(Class clazz, Object
object, String prefix,
NamedDomainObjectContainer nc =
(NamedDomainObjectContainer)value;
Map<String, ?> m = new HashMap<>(nc.getAsMap());
- List<String> ss = new ArrayList<>(m.keySet());
- propertyTypes.put(prefix + propName +
COLLECTION_KEYS_MARKER, String.join(";;", ss));
- for (String k : m.keySet()) {
- newPrefix = prefix + propName + "." + k + "."; //
NOI18N
- Object v = m.get(k);
- defaultValues.put(prefix + propName + "." + k,
Objects.toString(v)); // NOI18N
- inspectObjectAndValues(v.getClass(), v, newPrefix,
globalTypes, propertyTypes, defaultValues, null, false);
- }
+ dumpContainerProperties(m, prefix + propName,
defaultValues);
dumped = true;
- } else if (Iterable.class.isAssignableFrom(t)) {
- itemClass = findIterableItemClass(t);
- if (itemClass == null && typeParameters != null &&
!typeParameters.isEmpty()) {
- if (typeParameters.get(0) instanceof Class) {
- itemClass = (Class)typeParameters.get(0);
- }
- }
-
- propertyTypes.put(prefix + propName +
COLLECTION_TYPE_MARKER, COLLECTION_TYPE_LIST);
- if (itemClass != null) {
- cn = findNonDecoratedClass(itemClass).getName();
- propertyTypes.put(prefix + propName +
COLLECTION_ITEM_MARKER, cn);
- String newPrefix = prefix + propName +
COLLECTION_ITEM_PREFIX; // NOI18N
- if (!cn.startsWith("java.lang.") &&
!Provider.class.isAssignableFrom(t)) { //NOI18N
- inspectObjectAndValues(itemClass, null, newPrefix,
globalTypes, propertyTypes, defaultValues);
- }
- }
-
- if (value instanceof Iterable) {
- int index = 0;
- try {
- for (Object o : (Iterable)value) {
- String newPrefix = prefix + propName + "[" +
index + "]."; // NOI18N
- defaultValues.put(prefix + propName + "[" +
index + "]", Objects.toString(o)); //NOI18N
- inspectObjectAndValues(o.getClass(), o,
newPrefix, globalTypes, propertyTypes, defaultValues, null, false);
- index++;
- }
- } catch (RuntimeException ex) {
- // values cannot be obtained
- }
- dumped = true;
- }
- } else if (value instanceof Map) {
- Map mvalue = (Map)value;
- Set<Object> ks = mvalue.keySet();
- Class keyClass = findIterableItemClass(ks.getClass());
- if (keyClass == null || keyClass ==
java.lang.Object.class) {
- boolean ok = true;
- for (Object k : ks) {
- if (!(k instanceof String)) {
- ok = false;
- }
- }
- if (ok) {
- keyClass = String.class;
- }
- }
- if (keyClass == String.class) {
- itemClass =
findIterableItemClass(mvalue.values().getClass());
-
- String keys = ks.stream().map(k ->
k.toString()).map((String k) -> k.replace(";",
"\\;")).collect(Collectors.joining(";;"));
- propertyTypes.put(prefix + propName +
COLLECTION_KEYS_MARKER, keys);
-
- propertyTypes.put(prefix + propName +
COLLECTION_TYPE_MARKER, COLLECTION_TYPE_MAP);
- if (itemClass != null) {
- cn = findNonDecoratedClass(itemClass).getName();
- propertyTypes.put(prefix + propName +
COLLECTION_ITEM_MARKER, cn);
- String newPrefix = prefix + propName +
COLLECTION_ITEM_PREFIX; // NOI18N
- if (!cn.startsWith("java.lang.") &&
!Provider.class.isAssignableFrom(t)) { //NOI18N
- inspectObjectAndValues(itemClass, null,
newPrefix, globalTypes, propertyTypes, defaultValues);
- }
- }
-
- for (Object o : ks) {
- String k = o.toString();
- String newPrefix = prefix + propName + "[" + k +
"]"; // NOI18N
- Object v = mvalue.get(o);
- defaultValues.put(newPrefix, Objects.toString(v));
// NOI18N
- inspectObjectAndValues(v.getClass(), v, newPrefix
+ ".", globalTypes, propertyTypes, defaultValues, null, itemClass == null);
- }
- dumped = true;
- }
+ } else {
+ dumped = dumpValue(value, prefix + propName,
propertyTypes, defaultValues, t, typeParameters);
Review Comment:
extracted into a method so that inspectObjectAndValues can call that for
j.u.HashMap from line 579
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -811,14 +885,23 @@ private void inspectExtensions(String prefix,
ExtensionContainer container) {
Object ext;
try {
- ext = project.getExtensions().getByName(extName);
+ ext = container.getByName(extName);
Review Comment:
this was a bug !! The extension enumerated from a domain object was always
looked up as extension of a project itself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists