Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2015-07-17 18:50:30 +0000
committerBrian Vosburgh2015-07-17 18:50:30 +0000
commitb671990ca4154565a91a85217386360f20028c59 (patch)
tree0cd2fc86f81eef098bb6da521647c0196b24d98a
parent526080c4640d2f1735e97b8bb2f483cf312c7b99 (diff)
downloadwebtools.dali-b671990ca4154565a91a85217386360f20028c59.tar.gz
webtools.dali-b671990ca4154565a91a85217386360f20028c59.tar.xz
webtools.dali-b671990ca4154565a91a85217386360f20028c59.zip
add JDK 1.8 support to TypeDeclarationTools
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TypeDeclarationTools.java43
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ClasspathTests.java6
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SystemToolsTests.java36
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TypeDeclarationToolsTests.java30
4 files changed, 91 insertions, 24 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TypeDeclarationTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TypeDeclarationTools.java
index 26af4d231d..5d5298a7f9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TypeDeclarationTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TypeDeclarationTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -380,9 +380,9 @@ public final class TypeDeclarationTools {
* Return whether the specified "simple" class name is a public class in the
* current release of the <code>java.lang</code> package (i.e. a class that
* can be declared with a "simple" name and no corresponding
- * <code>import</code> statement).\
+ * <code>import</code> statement).
* <p>
- * The current release is jdk 1.7.
+ * The current release is jdk 1.8.
*/
public static boolean isJavaLangClass(String simpleClassName) {
return ArrayTools.binarySearch(JAVA_LANG_CLASS_NAMES_ARRAY, simpleClassName);
@@ -576,11 +576,42 @@ public final class TypeDeclarationTools {
*/
public static final Iterable<String> JAVA_LANG_CLASS_NAMES_7 = IterableTools.iterable(JAVA_LANG_CLASS_NAMES_ARRAY_7);
- // the current release is jdk 1.7
- private static final String[] JAVA_LANG_CLASS_NAMES_ARRAY = JAVA_LANG_CLASS_NAMES_ARRAY_7;
+ /**
+ * JDK 1.8
+ * @see #isJavaLangClass(String)
+ */
+ public static boolean isJavaLangClass8(String simpleClassName) {
+ return ArrayTools.binarySearch(JAVA_LANG_CLASS_NAMES_ARRAY_8, simpleClassName);
+ }
+
+ /**
+ * @see #isJavaLangClass8(String)
+ */
+ public static boolean isJavaLangClass8(char[] simpleClassName) {
+ return isJavaLangClass8(String.copyValueOf(simpleClassName));
+ }
+
+ // jdk 1.7
+ @SuppressWarnings("nls")
+ private static final String[] JAVA_LANG_CLASS_NAMES_ARRAY_8 = ArrayTools.sort(
+ ArrayTools.concatenate(
+ JAVA_LANG_CLASS_NAMES_ARRAY_7,
+ new String[] {
+ "FunctionalInterface"
+ }
+ )
+ );
+
+ /**
+ * JDK 1.8.
+ */
+ public static final Iterable<String> JAVA_LANG_CLASS_NAMES_8 = IterableTools.iterable(JAVA_LANG_CLASS_NAMES_ARRAY_8);
+
+ // the current release is jdk 1.8
+ private static final String[] JAVA_LANG_CLASS_NAMES_ARRAY = JAVA_LANG_CLASS_NAMES_ARRAY_8;
/**
- * The current release is jdk 1.7.
+ * The current release is jdk 1.8.
*/
public static final Iterable<String> JAVA_LANG_CLASS_NAMES = IterableTools.iterable(JAVA_LANG_CLASS_NAMES_ARRAY);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ClasspathTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ClasspathTests.java
index 5bb99b3603..5b888fa7f6 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ClasspathTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ClasspathTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -267,7 +267,7 @@ public class ClasspathTests extends TestCase {
}
public void testJavaExtensionClasspathEntries() {
- if (SystemTools.javaSpecificationVersionIsLessThan("1.4") || SystemTools.javaSpecificationVersionIsGreaterThan("1.7")) {
+ if (SystemTools.javaSpecificationVersionIsLessThan("1.4") || SystemTools.javaSpecificationVersionIsGreaterThan("1.8")) {
fail("we need to update this test for the current JDK: " + SystemTools.javaSpecificationVersion());
}
@@ -286,7 +286,7 @@ public class ClasspathTests extends TestCase {
}
public void testJavaExtensionClassNames() {
- if (SystemTools.javaSpecificationVersionIsLessThan("1.4") || SystemTools.javaSpecificationVersionIsGreaterThan("1.7")) {
+ if (SystemTools.javaSpecificationVersionIsLessThan("1.4") || SystemTools.javaSpecificationVersionIsGreaterThan("1.8")) {
fail("we need to update this test for the current JDK: " + SystemTools.javaSpecificationVersion());
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SystemToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SystemToolsTests.java
index 1a8bc4f266..a822ce1468 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SystemToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SystemToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2015 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -25,12 +25,14 @@ public class SystemToolsTests
String version = SystemTools.javaSpecificationVersion();
if (version.equals("1.4")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThan("1.3"));
- } else if(version.equals("1.5")) {
+ } else if (version.equals("1.5")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThan("1.4"));
- } else if(version.equals("1.6")) {
+ } else if (version.equals("1.6")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThan("1.5"));
- } else if(version.equals("1.7")) {
+ } else if (version.equals("1.7")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThan("1.6"));
+ } else if (version.equals("1.8")) {
+ assertTrue(SystemTools.javaSpecificationVersionIsGreaterThan("1.7"));
} else {
fail("untested Java specification version: " + version);
}
@@ -40,11 +42,13 @@ public class SystemToolsTests
String version = SystemTools.javaSpecificationVersion();
if (version.equals("1.4")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThan("1.5"));
- } else if(version.equals("1.5")) {
+ } else if (version.equals("1.5")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThan("1.6"));
- } else if(version.equals("1.6")) {
+ } else if (version.equals("1.6")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThan("1.7"));
- } else if(version.equals("1.7")) {
+ } else if (version.equals("1.7")) {
+ assertTrue(SystemTools.javaSpecificationVersionIsLessThan("2.0"));
+ } else if (version.equals("1.8")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThan("2.0"));
} else {
fail("untested Java specification version: " + version);
@@ -56,14 +60,17 @@ public class SystemToolsTests
if (version.equals("1.4")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.3"));
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.4"));
- } else if(version.equals("1.5")) {
+ } else if (version.equals("1.5")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.4"));
- } else if(version.equals("1.6")) {
+ } else if (version.equals("1.6")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.5"));
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.6"));
- } else if(version.equals("1.7")) {
+ } else if (version.equals("1.7")) {
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.6"));
assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.7"));
+ } else if (version.equals("1.8")) {
+ assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.7"));
+ assertTrue(SystemTools.javaSpecificationVersionIsGreaterThanOrEqualTo("1.8"));
} else {
fail("untested Java specification version: " + version);
}
@@ -74,15 +81,18 @@ public class SystemToolsTests
if (version.equals("1.4")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.5"));
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.4"));
- } else if(version.equals("1.5")) {
+ } else if (version.equals("1.5")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.5"));
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.6"));
- } else if(version.equals("1.6")) {
+ } else if (version.equals("1.6")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.6"));
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.7"));
- } else if(version.equals("1.7")) {
+ } else if (version.equals("1.7")) {
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.7"));
assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("2.0"));
+ } else if (version.equals("1.8")) {
+ assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.8"));
+ assertTrue(SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("2.0"));
} else {
fail("untested Java specification version: " + version);
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TypeDeclarationToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TypeDeclarationToolsTests.java
index f164a5bb35..a106006041 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TypeDeclarationToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TypeDeclarationToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2015 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -268,6 +268,7 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass("Object"));
assertTrue(TypeDeclarationTools.isJavaLangClass("String"));
assertTrue(TypeDeclarationTools.isJavaLangClass("AutoCloseable"));
+ assertTrue(TypeDeclarationTools.isJavaLangClass("FunctionalInterface"));
assertFalse(TypeDeclarationTools.isJavaLangClass(""));
assertFalse(TypeDeclarationTools.isJavaLangClass("Collection"));
}
@@ -276,6 +277,7 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass("Object".toCharArray()));
assertTrue(TypeDeclarationTools.isJavaLangClass("String".toCharArray()));
assertTrue(TypeDeclarationTools.isJavaLangClass("AutoCloseable".toCharArray()));
+ assertTrue(TypeDeclarationTools.isJavaLangClass("FunctionalInterface".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass("".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass("Collection".toCharArray()));
}
@@ -284,6 +286,7 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass5("Object"));
assertTrue(TypeDeclarationTools.isJavaLangClass5("String"));
assertFalse(TypeDeclarationTools.isJavaLangClass5("AutoCloseable"));
+ assertFalse(TypeDeclarationTools.isJavaLangClass5("FunctionalInterface"));
assertFalse(TypeDeclarationTools.isJavaLangClass5(""));
assertFalse(TypeDeclarationTools.isJavaLangClass5("Collection"));
}
@@ -292,6 +295,7 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass5("Object".toCharArray()));
assertTrue(TypeDeclarationTools.isJavaLangClass5("String".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass5("AutoCloseable".toCharArray()));
+ assertFalse(TypeDeclarationTools.isJavaLangClass5("FunctionalInterface".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass5("".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass5("Collection".toCharArray()));
}
@@ -300,6 +304,7 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass6("Object"));
assertTrue(TypeDeclarationTools.isJavaLangClass6("String"));
assertFalse(TypeDeclarationTools.isJavaLangClass6("AutoCloseable"));
+ assertFalse(TypeDeclarationTools.isJavaLangClass6("FunctionalInterface"));
assertFalse(TypeDeclarationTools.isJavaLangClass6(""));
assertFalse(TypeDeclarationTools.isJavaLangClass6("Collection"));
}
@@ -308,6 +313,7 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass6("Object".toCharArray()));
assertTrue(TypeDeclarationTools.isJavaLangClass6("String".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass6("AutoCloseable".toCharArray()));
+ assertFalse(TypeDeclarationTools.isJavaLangClass6("FunctionalInterface".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass6("".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass6("Collection".toCharArray()));
}
@@ -316,6 +322,7 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass7("Object"));
assertTrue(TypeDeclarationTools.isJavaLangClass7("String"));
assertTrue(TypeDeclarationTools.isJavaLangClass7("AutoCloseable"));
+ assertFalse(TypeDeclarationTools.isJavaLangClass7("FunctionalInterface"));
assertFalse(TypeDeclarationTools.isJavaLangClass7(""));
assertFalse(TypeDeclarationTools.isJavaLangClass7("Collection"));
}
@@ -324,12 +331,31 @@ public class TypeDeclarationToolsTests
assertTrue(TypeDeclarationTools.isJavaLangClass7("Object".toCharArray()));
assertTrue(TypeDeclarationTools.isJavaLangClass7("String".toCharArray()));
assertTrue(TypeDeclarationTools.isJavaLangClass7("AutoCloseable".toCharArray()));
+ assertFalse(TypeDeclarationTools.isJavaLangClass7("FunctionalInterface".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass7("".toCharArray()));
assertFalse(TypeDeclarationTools.isJavaLangClass7("Collection".toCharArray()));
}
+ public void testIsJavaLangClass8String() {
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("Object"));
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("String"));
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("AutoCloseable"));
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("FunctionalInterface"));
+ assertFalse(TypeDeclarationTools.isJavaLangClass8(""));
+ assertFalse(TypeDeclarationTools.isJavaLangClass8("Collection"));
+ }
+
+ public void testIsJavaLangClass8CharArray() {
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("Object".toCharArray()));
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("String".toCharArray()));
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("AutoCloseable".toCharArray()));
+ assertTrue(TypeDeclarationTools.isJavaLangClass8("FunctionalInterface".toCharArray()));
+ assertFalse(TypeDeclarationTools.isJavaLangClass8("".toCharArray()));
+ assertFalse(TypeDeclarationTools.isJavaLangClass8("Collection".toCharArray()));
+ }
+
public void testJDKVersion() {
assertTrue("update TypeDeclarationTools.JAVA_LANG_CLASS_NAMES for new JDK...",
- SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.7"));
+ SystemTools.javaSpecificationVersionIsLessThanOrEqualTo("1.8"));
}
}

Back to the top