diff --git a/core/org.eclipse.cdt.core.tests/.classpath b/core/org.eclipse.cdt.core.tests/.classpath index 5b2e2ed7c08..8be460c94fe 100644 --- a/core/org.eclipse.cdt.core.tests/.classpath +++ b/core/org.eclipse.cdt.core.tests/.classpath @@ -7,7 +7,7 @@ - + diff --git a/core/org.eclipse.cdt.core.tests/.settings/org.eclipse.jdt.core.prefs b/core/org.eclipse.cdt.core.tests/.settings/org.eclipse.jdt.core.prefs index b207adcbeb3..67b45007e60 100644 --- a/core/org.eclipse.cdt.core.tests/.settings/org.eclipse.jdt.core.prefs +++ b/core/org.eclipse.cdt.core.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ -#Mon Oct 09 10:54:22 CEST 2006 +#Wed Jan 02 10:16:52 EST 2008 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -15,7 +15,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fieldHiding=warning org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning @@ -59,4 +59,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.4 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java index 80ea079196d..d6e09fc9212 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java @@ -64,9 +64,9 @@ public class CharArrayMapTest extends TestCase { private static long timeMap(char[][] keys) { long start = System.currentTimeMillis(); - CharArrayMap/**/ map = new CharArrayMap/**/(keys.length); + CharArrayMap map = new CharArrayMap(keys.length); for(int i = 0; i < keys.length; i++) { - map.put(keys[i], new Integer(i)); + map.put(keys[i], i); } assertEquals(keys.length, map.size()); for(int i = 0; i < keys.length; i++) { @@ -96,14 +96,14 @@ public class CharArrayMapTest extends TestCase { char[] key3 = "third key".toCharArray(); char[] key4 = "forth key".toCharArray(); - CharArrayMap/**/ map = new CharArrayMap/**/(); + CharArrayMap map = new CharArrayMap(); assertTrue(map.isEmpty()); assertEquals(0, map.size()); - map.put(key1, new Integer(1)); - map.put(key2, new Integer(2)); - map.put(key3, new Integer(3)); - map.put(key4, new Integer(4)); + map.put(key1, 1); + map.put(key2, 2); + map.put(key3, 3); + map.put(key4, 4); assertFalse(map.isEmpty()); assertEquals(4, map.size()); @@ -118,19 +118,19 @@ public class CharArrayMapTest extends TestCase { assertTrue(map.containsKey(key3)); assertTrue(map.containsKey(key4)); - assertTrue(map.containsValue(new Integer(1))); - assertTrue(map.containsValue(new Integer(2))); - assertTrue(map.containsValue(new Integer(3))); - assertTrue(map.containsValue(new Integer(4))); + assertTrue(map.containsValue(1)); + assertTrue(map.containsValue(2)); + assertTrue(map.containsValue(3)); + assertTrue(map.containsValue(4)); - Set/**/ values = new HashSet/**/(); - values.add(new Integer(1)); - values.add(new Integer(2)); - values.add(new Integer(3)); - values.add(new Integer(4)); - Collection c = map.values(); - for(Iterator iter = c.iterator(); iter.hasNext();) { - assertTrue(values.remove(iter.next())); + Set values = new HashSet(); + values.add(1); + values.add(2); + values.add(3); + values.add(4); + + for(int i : map.values()) { + assertTrue(values.remove(i)); } // remove a mapping @@ -138,7 +138,7 @@ public class CharArrayMapTest extends TestCase { assertEquals(3, map.size()); assertNull(map.get(key1)); assertFalse(map.containsKey(key1)); - assertFalse(map.containsValue(new Integer(1))); + assertFalse(map.containsValue(1)); assertNull(map.remove(key1)); // its already removed map.clear(); @@ -153,17 +153,17 @@ public class CharArrayMapTest extends TestCase { assertTrue(map.containsValue(null)); // overrideing values should - map.put(key1, new Integer(100)); + map.put(key1, 100); assertEquals(1, map.size()); assertEquals(new Integer(100), map.get(key1)); - assertTrue(map.containsValue(new Integer(100))); + assertTrue(map.containsValue(100)); assertFalse(map.containsValue(null)); // override the value - map.put(key1, new Integer(200)); + map.put(key1, 200); assertEquals(1, map.size()); assertEquals(new Integer(200), map.get(key1)); - assertTrue(map.containsValue(new Integer(200))); - assertFalse(map.containsValue(new Integer(100))); + assertTrue(map.containsValue(200)); + assertFalse(map.containsValue(100)); } @@ -189,13 +189,13 @@ public class CharArrayMapTest extends TestCase { keys[6] = "carcass".toCharArray(); - CharArrayMap/**/ map = new CharArrayMap/**/(); + CharArrayMap map = new CharArrayMap(); assertTrue(map.isEmpty()); assertEquals(0, map.size()); for(int i = 0; i < slices.length; i++) { Slice slice = slices[i]; - map.put(slice.chars, slice.start, slice.length, new Integer(i)); + map.put(slice.chars, slice.start, slice.length, i); } assertFalse(map.isEmpty()); @@ -208,16 +208,16 @@ public class CharArrayMapTest extends TestCase { assertEquals(new Integer(i), map.get(keys[i])); assertTrue(map.containsKey(slice.chars, slice.start, slice.length)); assertTrue(map.containsKey(keys[i])); - assertTrue(map.containsValue(new Integer(i))); + assertTrue(map.containsValue(i)); } - Set/**/ values = new HashSet/**/(); + Set values = new HashSet(); for(int i = 0; i < keys.length; i++) { - values.add(new Integer(i)); + values.add(i); } - Collection c = map.values(); - for(Iterator iter = c.iterator(); iter.hasNext();) { - assertTrue(values.remove(iter.next())); + + for(int i : map.values()) { + assertTrue(values.remove(i)); } // remove the last two keys @@ -233,7 +233,7 @@ public class CharArrayMapTest extends TestCase { assertEquals(new Integer(i), map.get(keys[i])); assertTrue(map.containsKey(slice.chars, slice.start, slice.length)); assertTrue(map.containsKey(keys[i])); - assertTrue(map.containsValue(new Integer(i))); + assertTrue(map.containsValue(i)); } map.clear(); @@ -244,7 +244,7 @@ public class CharArrayMapTest extends TestCase { public void testProperFail() { char[] hello = "hello".toCharArray(); - CharArrayMap/**/ map = new CharArrayMap/**/(); + CharArrayMap map = new CharArrayMap(); Integer value = new Integer(9); @@ -333,7 +333,7 @@ public class CharArrayMapTest extends TestCase { try { - new CharArrayMap/**/(-1); + new CharArrayMap(-1); } catch(IllegalArgumentException _) {} } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java index 15155e713ce..eba7dcb84a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java @@ -22,7 +22,7 @@ import java.util.Map; * section of a char[] as the key (a slice), and one that uses * the entire char[] as the key. * - * ex) + * ex: * char[] key = "one two three".toCharArray(); * map.put(key, 4, 3, new Integer(99)); * map.get(key, 4, 3); // returns 99 @@ -31,7 +31,7 @@ import java.util.Map; * * @author Mike Kucera */ -public final class CharArrayMap/**/ { +public final class CharArrayMap implements ICharArrayMap { /** * Wrapper class used as keys in the map. The purpose @@ -63,7 +63,7 @@ public final class CharArrayMap/**/ { this.start = 0; } - public boolean equals(Object x) { + @Override public boolean equals(Object x) { if(this == x) return true; if(!(x instanceof Key)) @@ -81,7 +81,7 @@ public final class CharArrayMap/**/ { return true; } - public int hashCode() { + @Override public int hashCode() { int result = 17; for(int i = start; i < start+length; i++) { result = 37 * result + buffer[i]; @@ -89,7 +89,7 @@ public final class CharArrayMap/**/ { return result; } - public String toString() { + @Override public String toString() { return "'" + new String(buffer, start, length) + "'@(" + start + "," + length + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } @@ -97,29 +97,28 @@ public final class CharArrayMap/**/ { /** - * Used to enforce preconditions. Note that the NPE thats thrown by - * mutator methods is thrown from the Key constructor. + * Used to enforce preconditions. + * + * Note that the NPE thrown by mutator methods is thrown from the Key constructor. + * + * @throws IndexOutOfBoundsException if boundaries are wrong in any way */ private static void checkBoundaries(char[] chars, int start, int length) { - if(start < 0) - throw new IndexOutOfBoundsException("start must be non-negative, got: " + start);//$NON-NLS-1$ - if(length < 0) - throw new IndexOutOfBoundsException("length must be non-negative, got: " + length);//$NON-NLS-1$ - if(start >= chars.length) - throw new IndexOutOfBoundsException("start is out of bounds, got: " + start);//$NON-NLS-1$ - if(start + length > chars.length) - throw new IndexOutOfBoundsException("end is out of bounds, got: " + (start+length));//$NON-NLS-1$ + if(start < 0 || length < 0 || start >= chars.length || start + length > chars.length) + throw new IndexOutOfBoundsException("Buffer length: " + chars.length + //$NON-NLS-1$ + ", Start index: " + start + //$NON-NLS-1$ + ", Length: " + length); //$NON-NLS-1$ } - private final Map/**/ map; + private final Map map; /** * Constructs an empty CharArrayMap with default initial capacity. */ public CharArrayMap() { - map = new HashMap/**/(); + map = new HashMap(); } /** @@ -127,127 +126,74 @@ public final class CharArrayMap/**/ { * @throws IllegalArgumentException if the initial capacity is negative */ public CharArrayMap(int initialCapacity) { - map = new HashMap/**/(initialCapacity); + map = new HashMap(initialCapacity); } - /** - * Creates a new mapping in this map, uses the given array slice as the key. - * If the map previously contained a mapping for this key, the old value is replaced. - * @throws NullPointerException if chars is null - * @throws IllegalArgumentException if the boundaries specified by start and length are out of range - */ - public void put(char[] chars, int start, int length, /*V*/Object value) { + public void put(char[] chars, int start, int length, V value) { checkBoundaries(chars, start, length); map.put(new Key(chars, start, length), value); } - /** - * Creates a new mapping in this map, uses all of the given array as the key. - * If the map previously contained a mapping for this key, the old value is replaced. - * @throws NullPointerException if chars is null - */ - public void put(char[] chars, /*V*/Object value) { + + public void put(char[] chars, V value) { map.put(new Key(chars), value); } - /** - * Returns the value to which the specified array slice is mapped in this map, - * or null if the map contains no mapping for this key. - * @throws NullPointerException if chars is null - * @throws IllegalArgumentException if the boundaries specified by start and length are out of range - */ - public /*V*/Object get(char[] chars, int start, int length) { + + public V get(char[] chars, int start, int length) { checkBoundaries(chars, start, length); return map.get(new Key(chars, start, length)); } - /** - * Returns the value to which the specified array is mapped in this map, - * or null if the map contains no mapping for this key. - * @throws NullPointerException if chars is null - */ - public /*V*/Object get(char[] chars) { + + public V get(char[] chars) { return map.get(new Key(chars)); } - /** - * Removes the mapping for the given array slice if present. - * Returns the value object that corresponded to the key - * or null if the key was not in the map. - * @throws NullPointerException if chars is null - * @throws IllegalArgumentException if the boundaries specified by start and length are out of range - */ - public /*V*/Object remove(char[] chars, int start, int length) { + public V remove(char[] chars, int start, int length) { checkBoundaries(chars, start, length); return map.remove(new Key(chars, start, length)); } - /** - * Removes the mapping for the given array if present. - * Returns the value object that corresponded to the key - * or null if the key was not in the map. - * @throws NullPointerException if chars is null - * @throws IllegalArgumentException if the boundaries specified by start and length are out of range - */ - public /*V*/Object remove(char[] chars) { + public V remove(char[] chars) { return map.remove(new Key(chars)); } + - /** - * Returns true if the given key has a value associated with it in the map. - * @throws NullPointerException if chars is null - * @throws IllegalArgumentException if the boundaries specified by start and length are out of range - */ public boolean containsKey(char[] chars, int start, int length) { checkBoundaries(chars, start, length); return map.containsKey(new Key(chars, start, length)); } + - /** - * Returns true if the given key has a value associated with it in the map. - * @throws NullPointerException if chars is null - * @throws IllegalArgumentException if the boundaries specified by start and length are out of range - */ public boolean containsKey(char[] chars) { return map.containsKey(new Key(chars)); } - /** - * Returns true if the given value is contained in the map. - */ - public boolean containsValue(/*V*/Object value) { + + public boolean containsValue(V value) { return map.containsValue(value); } + - /** - * Use this in a foreach loop. - */ - public Collection/**/ values() { + public Collection values() { return map.values(); } + - /** - * Removes all mappings from the map. - */ public void clear() { map.clear(); } + - - /** - * Returns the number of mappings. - */ public int size() { return map.size(); } - - /** - * Returns true if the map is empty. - */ + public boolean isEmpty() { return map.isEmpty(); } @@ -256,7 +202,7 @@ public final class CharArrayMap/**/ { /** * Returns a String representation of the map. */ - public String toString() { + @Override public String toString() { return map.toString(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ICharArrayMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ICharArrayMap.java new file mode 100644 index 00000000000..6c8a2391a52 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ICharArrayMap.java @@ -0,0 +1,94 @@ +package org.eclipse.cdt.core.parser.util; + +import java.util.Collection; + +public interface ICharArrayMap { + + /** + * Creates a new mapping in this map, uses the given array slice as the key. + * If the map previously contained a mapping for this key, the old value is replaced. + * @throws NullPointerException if chars is null + * @throws IllegalArgumentException if the boundaries specified by start and length are out of range + */ + void put(char[] chars, int start, int length, V value); + + /** + * Creates a new mapping in this map, uses all of the given array as the key. + * If the map previously contained a mapping for this key, the old value is replaced. + * @throws NullPointerException if chars is null + */ + void put(char[] chars, V value); + + /** + * Returns the value to which the specified array slice is mapped in this map, + * or null if the map contains no mapping for this key. + * @throws NullPointerException if chars is null + * @throws IllegalArgumentException if the boundaries specified by start and length are out of range + */ + V get(char[] chars, int start, int length); + + /** + * Returns the value to which the specified array is mapped in this map, + * or null if the map contains no mapping for this key. + * @throws NullPointerException if chars is null + */ + V get(char[] chars); + + /** + * Removes the mapping for the given array slice if present. + * Returns the value object that corresponded to the key + * or null if the key was not in the map. + * @throws NullPointerException if chars is null + * @throws IllegalArgumentException if the boundaries specified by start and length are out of range + */ + V remove(char[] chars, int start, int length); + + /** + * Removes the mapping for the given array if present. + * Returns the value object that corresponded to the key + * or null if the key was not in the map. + * @throws NullPointerException if chars is null + * @throws IllegalArgumentException if the boundaries specified by start and length are out of range + */ + V remove(char[] chars); + + /** + * Returns true if the given key has a value associated with it in the map. + * @throws NullPointerException if chars is null + * @throws IllegalArgumentException if the boundaries specified by start and length are out of range + */ + boolean containsKey(char[] chars, int start, int length); + + /** + * Returns true if the given key has a value associated with it in the map. + * @throws NullPointerException if chars is null + * @throws IllegalArgumentException if the boundaries specified by start and length are out of range + */ + boolean containsKey(char[] chars); + + /** + * Returns true if the given value is contained in the map. + */ + boolean containsValue(V value); + + /** + * Use this in a foreach loop. + */ + Collection values(); + + /** + * Removes all mappings from the map. + */ + void clear(); + + /** + * Returns the number of mappings. + */ + int size(); + + /** + * Returns true if the map is empty. + */ + boolean isEmpty(); + +} \ No newline at end of file