You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sk...@apache.org on 2020/02/12 16:25:12 UTC
[netbeans] branch master updated: [NETBEANS-3317]: field
TypeVar.bound has been encapsulated and renamed to _bound - should use
getUpperBound() instead.
This is an automated email from the ASF dual-hosted git repository.
skygo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 05257f5 [NETBEANS-3317]: field TypeVar.bound has been encapsulated and renamed to _bound - should use getUpperBound() instead.
new e198d0d Merge pull request #1942 from jlahoda/NETBEANS-3317
05257f5 is described below
commit 05257f52f4ddda54fec2fdd9d201235c99d1c88a
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Wed Feb 12 08:47:17 2020 +0100
[NETBEANS-3317]: field TypeVar.bound has been encapsulated and renamed to _bound - should use getUpperBound() instead.
---
.../org/netbeans/api/java/source/SourceUtils.java | 6 +++++-
.../test/unit/data/sourceutils/TestGetBound.java | 23 ++++++++++++++++++++++
.../netbeans/api/java/source/SourceUtilsTest.java | 21 ++++++++++++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java b/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
index fac9ffa..0c60bdd 100644
--- a/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
+++ b/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
@@ -196,7 +196,11 @@ public class SourceUtils {
public static TypeMirror getBound(WildcardType wildcardType) {
Type.TypeVar bound = ((Type.WildcardType)wildcardType).bound;
- return bound != null ? bound.bound : null;
+ try {
+ return bound != null ? bound.bound : null;
+ } catch (NoSuchFieldError err) {
+ return bound != null ? bound.getUpperBound() : null;
+ }
}
/**
diff --git a/java/java.source.base/test/unit/data/sourceutils/TestGetBound.java b/java/java.source.base/test/unit/data/sourceutils/TestGetBound.java
new file mode 100644
index 0000000..9fee6a2
--- /dev/null
+++ b/java/java.source.base/test/unit/data/sourceutils/TestGetBound.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package sourceutils;
+
+public class TestGetBound<T extends TestGetBoundExtra<? extends String>> {
+}
+class TestGetBoundExtra<T extends CharSequence> {}
diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java
index 7e9a61a..a4f0659 100644
--- a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java
+++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java
@@ -19,6 +19,7 @@
package org.netbeans.api.java.source;
+import com.sun.source.tree.Tree;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@@ -38,7 +39,12 @@ import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.type.WildcardType;
import javax.lang.model.util.ElementFilter;
import javax.swing.event.ChangeListener;
import org.netbeans.api.java.classpath.ClassPath;
@@ -428,6 +434,21 @@ public class SourceUtilsTest extends ClassIndexTestCase {
assertEquals("TestDollarSourceName.java", f.getNameExt());
}
+ public void testGetBound() throws Exception {
+ //only a scatch of the test, add testcases as needed:
+ prepareTest();
+
+ TypeElement test = info.getElements().getTypeElement("sourceutils.TestGetBound");
+
+ assertNotNull(test);
+
+ TypeParameterElement typeParam = test.getTypeParameters().get(0);
+ TypeMirror outerBound = ((TypeVariable) typeParam.asType()).getUpperBound();
+
+ TypeMirror bound = SourceUtils.getBound((WildcardType) ((DeclaredType) outerBound).getTypeArguments().get(0));
+ assertEquals("java.lang.CharSequence", String.valueOf(bound));
+ }
+
//<editor-fold defaultstate="collapsed" desc="Helper methods & Mock services">
private void prepareTest() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists