JDT-based CAst front end from Berkeley
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3170 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
2b2cb065cb
commit
7935177e3a
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ `uname` = "Linux" ]]; then
|
||||
REAL_NAME=`realpath $0`
|
||||
MY_DIR=`dirname $REAL_NAME`
|
||||
else
|
||||
MY_DIR=`pwd`
|
||||
fi
|
||||
|
||||
TMP=$MY_DIR/tmp
|
||||
|
||||
if [[ ! -e $MY_DIR/JLex/Main.java ]]; then
|
||||
mkdir -p $TMP
|
||||
|
||||
cd $TMP
|
||||
|
||||
mkdir JLex
|
||||
wget -O JLex/Main.java http://www.cs.princeton.edu/~appel/modern/java/JLex/current/Main.java
|
||||
|
||||
cp -r JLex $MY_DIR/src
|
||||
|
||||
cd $MY_DIR
|
||||
rm -rf $TMP
|
||||
fi
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package alreadywalaunittests;
|
||||
|
||||
//other stranger test cases
|
||||
//
|
||||
// combininations of:
|
||||
// o.new() form
|
||||
// function calls
|
||||
// getting enclosings from one AND multiple levels up
|
||||
// new Foo() which requires an enclosing instruction before (ie calling new Inner() from ReallyInner()
|
||||
// invariants and non-invariants (immediate 'new' in that function)
|
||||
// subclasses
|
||||
|
||||
public class InnerClassA {
|
||||
int a_x;
|
||||
|
||||
public static void main(String args[]) {
|
||||
// prints out 5 5 9 7 5 5 7 5 7 5
|
||||
InnerClassA a = new InnerClassA();
|
||||
a.doAllThis();
|
||||
}
|
||||
|
||||
public void doAllThis() {
|
||||
InnerClassA a = this;
|
||||
AA aa = new AA();
|
||||
aa = a.new AA();
|
||||
AB ab = aa.makeAB();
|
||||
a.a_x = 5;
|
||||
|
||||
// tests
|
||||
int myx = ab.getA_X_from_AB();
|
||||
System.out.println(myx); // 5
|
||||
int myx2 = ab.getA_X_thru_AB();
|
||||
System.out.println(myx2); // 5
|
||||
|
||||
aa.doSomeCrazyStuff();
|
||||
}
|
||||
|
||||
public int getA_X() {
|
||||
return a_x;
|
||||
}
|
||||
|
||||
class AA {
|
||||
int a2a_var;
|
||||
|
||||
public AB makeAB() {
|
||||
return new AB();
|
||||
}
|
||||
|
||||
public void doSomeCrazyStuff() {
|
||||
AB ab = new AB();
|
||||
AB.ABSubA absuba = ab.new ABSubA();
|
||||
absuba.aba_x = 7;
|
||||
AB.ABA.ABAA abaa2 = ab.new ABA().new ABAA(); // just used to add ABA instance key in ABAA.getABA_X()
|
||||
|
||||
AB.ABA aba = ab.new ABA();
|
||||
aba.aba_x = 9;
|
||||
AB.ABA.ABAB abab = aba.new ABAB();
|
||||
System.out.println(abab.getABA_X()); // 9
|
||||
|
||||
AB.ABA.ABAA abaa = absuba.new ABAA();
|
||||
int myaba_x = abaa.getABA_X();
|
||||
int mya_x = abaa.getA_X();
|
||||
System.out.println(myaba_x); // 7
|
||||
System.out.println(mya_x); // 5
|
||||
|
||||
|
||||
doMoreWithABSubA(absuba);
|
||||
}
|
||||
|
||||
private void doMoreWithABSubA(InnerClassA.AB.ABSubA absuba) {
|
||||
System.out.println(absuba.getA_X()); // 5
|
||||
|
||||
AB.ABSubA.ABSubAA absubaa = absuba.new ABSubAA();
|
||||
int myaba_x2 = absubaa.getABA_X();
|
||||
int mya_x2 = absubaa.getA_X();
|
||||
System.out.println(myaba_x2); // 7
|
||||
System.out.println(mya_x2); // 5
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
AB.ABA.ABAA abaa = absubaa.makeABAA();
|
||||
int myaba_x3 = abaa.getABA_X();
|
||||
int mya_x3 = abaa.getA_X();
|
||||
System.out.println(myaba_x3); // 7
|
||||
System.out.println(mya_x3); // 5
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class AB {
|
||||
public int getA_X_from_AB() {
|
||||
return a_x; // CHECK enclosing is an A
|
||||
}
|
||||
|
||||
public int getA_X_thru_AB() {
|
||||
return getA_X(); // CHECK enclosing is an A
|
||||
}
|
||||
|
||||
class ABA {
|
||||
int aba_x;
|
||||
class ABAA {
|
||||
int getABA_X() {
|
||||
return aba_x; // CHECK enclosing is an ABA or ABSubA
|
||||
}
|
||||
int getA_X() {
|
||||
return a_x; // CHECK enclosing is an A
|
||||
}
|
||||
}
|
||||
class ABAB {
|
||||
int getABA_X() {
|
||||
return aba_x; // CHECK enclosing is an ABA
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ABSubA extends ABA {
|
||||
class ABSubAA {
|
||||
int getABA_X() {
|
||||
return aba_x; // CHECK enclosing is an ABSubA
|
||||
}
|
||||
int getA_X() {
|
||||
return a_x; // CHECK enclosing is an A
|
||||
}
|
||||
ABA.ABAA makeABAA() {
|
||||
return new ABAA(); // this new instruction requires us to know that ABSubA is a subclass of ABA.
|
||||
// thus when we call getABA_X() on the result, it will need to find a EORK(this site,class ABA) -> THIS (of type ABSubAA)
|
||||
}
|
||||
}
|
||||
int getA_X() {
|
||||
return a_x; // CHECK enclosing is an A
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package alreadywalaunittests;
|
||||
|
||||
public class InnerClassSuper {
|
||||
int x = 5;
|
||||
class SuperOuter {
|
||||
public void test() {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
public static void main(String args[]) {
|
||||
new Sub().new SubInner();
|
||||
}
|
||||
}
|
||||
class Sub extends InnerClassSuper {
|
||||
class SubInner {
|
||||
public SubInner() {
|
||||
InnerClassSuper.SuperOuter so = new InnerClassSuper.SuperOuter();
|
||||
so.test();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package bugfixes;
|
||||
|
||||
public class VarDeclInSwitch {
|
||||
static int y = 7;
|
||||
public static void main(String args[]) {
|
||||
int x = 5;
|
||||
x = x + x;
|
||||
switch ( x ) {
|
||||
case 5:
|
||||
break;
|
||||
case 10:
|
||||
int y = 6;
|
||||
System.out.println(y);
|
||||
default:
|
||||
y = 7;
|
||||
System.out.println(y);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,40 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package com.ibm.wala.cast.java.test.data;
|
||||
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo;
|
||||
|
||||
public class QualifiedNames {
|
||||
static int field;
|
||||
int x;
|
||||
public QualifiedNames(int xx) {
|
||||
x = xx;
|
||||
}
|
||||
public static void main(String args[]) {
|
||||
QualifiedNames qn = new QualifiedNames(5);
|
||||
int y = 3;
|
||||
y = y + qn.x;
|
||||
}
|
||||
public void test() {
|
||||
int x = 2;
|
||||
x = x / x / x;
|
||||
|
||||
field = 5;
|
||||
field = QualifiedNames.field + field;
|
||||
this.x = 6;
|
||||
QualifiedNames.field = 6;
|
||||
QualifiedNames.this.x = 6;
|
||||
|
||||
foo.QualifiedNames.field = 6;
|
||||
foo.QualifiedNames.this.x = 7;
|
||||
|
||||
// TODO FIXME IMPORTANT: ENABLE WHEN WE SUPPORT FUNCTIONSIN JDT BRIDGE!!!
|
||||
foo.QualifiedNames.empty();
|
||||
emptyInstance();
|
||||
foo.QualifiedNames.this.emptyInstance();
|
||||
}
|
||||
public static void empty() {}
|
||||
public void emptyInstance() {}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo;
|
||||
|
||||
// need inner classes to run this test
|
||||
|
||||
public class SimpleNames {
|
||||
int f;
|
||||
static int s;
|
||||
public void hello() {
|
||||
f = 3; // this.f = 3
|
||||
s = 4; // SimpleNames.f = 4
|
||||
|
||||
SimpleNames.s = foo.SimpleNames.s;
|
||||
if ( false ) {
|
||||
foo.SimpleNames.this.hello();
|
||||
hello();
|
||||
this.hello();
|
||||
}
|
||||
|
||||
final int i = 5;
|
||||
new Object() {
|
||||
public int hashCode() {
|
||||
f = 5; // SimpleNames.this = 5
|
||||
s = 6; // SimpleNames.s = 6
|
||||
|
||||
SimpleNames.this.f = 5;
|
||||
SimpleNames.s = 6;
|
||||
|
||||
if ( false ) {
|
||||
foo.SimpleNames.this.hello();
|
||||
SimpleNames.this.hello();
|
||||
hello(); // this should expand to above
|
||||
this.hashCode();
|
||||
hashCode(); // should expand to above
|
||||
}
|
||||
|
||||
return i; // just plain "i" in polyglot, treats like local.
|
||||
}
|
||||
};
|
||||
}
|
||||
public static void main(String args[]) {
|
||||
new SimpleNames().hello();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class ArraysAndSuch {
|
||||
|
||||
public static void main(String args[]) {
|
||||
ArraysAndSuch.main();
|
||||
}
|
||||
public static void main() {
|
||||
Object o1 = null;
|
||||
Object[] os1 = new Object[] { null, o1, null };
|
||||
Object[] os2 = { null };
|
||||
os1 = new Object[] { null };
|
||||
os1 = new String[][] { { null, null }, { null} };
|
||||
os1 = new Object[][] { { null, o1 }, { null}, {os2}, {null,os1,null} };
|
||||
System.out.println(os1[1]);
|
||||
os1[1] = null;
|
||||
|
||||
os1.clone();
|
||||
if ( os1.equals(os2) ) {
|
||||
Class x = os1.getClass();
|
||||
os1.notify();
|
||||
os1.toString();
|
||||
try {
|
||||
x.getClasses().wait(x.getClasses().length,o1.hashCode());
|
||||
os1.wait(os1.length);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
float x[] = new float[4+5];
|
||||
int[][][][] y = new int[2][x.length][1][1+1];
|
||||
int z[] = new int[] { 2+3, 4+3 };
|
||||
boolean[] a = new boolean[] { };
|
||||
Object b = new String[] { };
|
||||
Object c[] = new String[] {};
|
||||
String d[] = new String[3];
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
class Super {
|
||||
String s;
|
||||
|
||||
Super(String x) {
|
||||
super();
|
||||
s = x;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConstructorsAndInitializers extends Super {
|
||||
static int iX;
|
||||
static int sX;
|
||||
|
||||
Object x;
|
||||
|
||||
static {
|
||||
sX = 11;
|
||||
}
|
||||
|
||||
{
|
||||
iX = 55 + 33;
|
||||
sX = 6;
|
||||
}
|
||||
|
||||
ConstructorsAndInitializers() {
|
||||
this("hello");
|
||||
}
|
||||
|
||||
{
|
||||
int y = 5;
|
||||
iX = y + 9;
|
||||
|
||||
x = new Super("yo wassup") {
|
||||
|
||||
{
|
||||
s += " i say wassup!";
|
||||
iX = 55 + 12;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return s + " -- from an anon class in " + iX + "," + sX + ": " + ConstructorsAndInitializers.this.s;
|
||||
}
|
||||
|
||||
{
|
||||
s += " i say i say";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected ConstructorsAndInitializers(String x) {
|
||||
super("yo");
|
||||
iX = 99;
|
||||
}
|
||||
|
||||
static {
|
||||
sX = 22;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println(new ConstructorsAndInitializers().x.toString()); // yo wassup i say wassup! i say i say -- from an anon class in 99,6: yo
|
||||
|
||||
class T{
|
||||
|
||||
}
|
||||
T t = new T();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class CopyOfLoopsAndLabels {
|
||||
static int X=5;
|
||||
public static void main(String args[]) {
|
||||
int k=X;
|
||||
for (; ; k++)
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class DefaultCtorInitializerTest {
|
||||
String x;
|
||||
|
||||
public static void main(String args[]) {
|
||||
// MAKE SURE initializer added to default ctor!!!
|
||||
System.out.println(new DefaultCtorInitializerTest().x + z); // hellohellogoodbye
|
||||
}
|
||||
|
||||
static String z;
|
||||
static {
|
||||
z = "goodbye";
|
||||
}
|
||||
|
||||
{
|
||||
String y = "hello";
|
||||
x = y + y;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
class Temp {
|
||||
|
||||
}
|
||||
public class InnerClasses extends Temp {
|
||||
|
||||
Object supportLocalBusiness() {
|
||||
final int x = 54;
|
||||
class FooBar {
|
||||
public int hashCode() { return x; }
|
||||
}
|
||||
return new FooBar();
|
||||
}
|
||||
|
||||
static Object anonymousCoward() {
|
||||
final int x = 5;
|
||||
return new Object() {
|
||||
public int hashCode() { return x; }
|
||||
};
|
||||
}
|
||||
|
||||
static String xxxx = "odd";
|
||||
|
||||
public static void main(String args[]) {
|
||||
new Outie("eenie").new Innie().meenie();
|
||||
System.out.println(anonymousCoward().hashCode());
|
||||
final String xx = "crazy";
|
||||
Outie outie = new Outie("weird") {
|
||||
public String toString() {
|
||||
return "bogus" + x + xx + xxxx;
|
||||
}
|
||||
};
|
||||
System.out.println(outie);
|
||||
|
||||
ABC a = new ABC("hello") { };
|
||||
System.out.println(new InnerClasses().supportLocalBusiness().hashCode());
|
||||
System.out.println(a);
|
||||
|
||||
System.out.println(new SuperEnclosing().new SubEnclosed().hello());
|
||||
System.out.println(new SuperEnclosing().new SubEnclosed().seVar);
|
||||
System.out.println(new SuperEnclosing().new SubEnclosed().hello2());
|
||||
System.out.println(new SuperEnclosing().new SubEnclosed().seVar2);
|
||||
|
||||
SuperEnclosing2 se2 = new SuperEnclosing2();
|
||||
SuperEnclosing2.SubEnclosed2 sub2 = se2.new SubEnclosed2();
|
||||
System.out.println(sub2.hello()); //13
|
||||
sub2.setSEVar();
|
||||
System.out.println(sub2.hello()); //still 13
|
||||
se2.setSEVar();
|
||||
System.out.println(sub2.hello()); //1001
|
||||
|
||||
int foo = 12;
|
||||
foo++;
|
||||
--foo;
|
||||
}
|
||||
}
|
||||
|
||||
class ABC { ABC(Object x) {} }
|
||||
|
||||
class Outie {
|
||||
String x;
|
||||
|
||||
Outie(String s) {
|
||||
x = s;
|
||||
}
|
||||
|
||||
class Innie {
|
||||
public void meenie() {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SuperEnclosing {
|
||||
int seVar = 6;
|
||||
int seVar2 = 10;
|
||||
class SubEnclosed extends SuperEnclosing {
|
||||
int seVar2 = 11;
|
||||
SubEnclosed() {
|
||||
this.seVar = 5;
|
||||
SuperEnclosing.this.seVar = 7;
|
||||
this.seVar2 = 12;
|
||||
SuperEnclosing.this.seVar2 = 13;
|
||||
}
|
||||
int hello() {
|
||||
return seVar; // this is ours from SuperEnclosing, not the enlosing SuperEnclosing's
|
||||
// so even though the variable is defined in SuperEnclosing, this is NOT the same as
|
||||
// SuperEnclosing.this.x
|
||||
}
|
||||
int helloAgain() {
|
||||
return SubEnclosed.this.seVar; // this is ours from SuprEnclosing, not the enclosing SuperEnclosing's
|
||||
}
|
||||
int hello2() {
|
||||
return seVar2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SuperEnclosing2 {
|
||||
private int seVar = 6;
|
||||
public void setSEVar() {
|
||||
seVar= 1001;
|
||||
}
|
||||
class SubEnclosed2 extends SuperEnclosing2 {
|
||||
SubEnclosed2() {
|
||||
// this.seVar = 5; // illegal
|
||||
SuperEnclosing2.this.seVar += -(-(+7)); // makes 13
|
||||
}
|
||||
int hello() {
|
||||
return seVar; // since seVar is private, this now refers to the enclosing one
|
||||
// PROOF: callind setSEVar() on the SubEnclosed2 above does nothing.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class LoopsAndLabels {
|
||||
public static void main(String args[]) {
|
||||
|
||||
aaa: do {
|
||||
while (null instanceof String) {
|
||||
String x = (String) null;
|
||||
Object a = (Object) x;
|
||||
Object b = (Object) "hello";
|
||||
x = (String) a;
|
||||
x = "hello";
|
||||
x = (String) b.toString();
|
||||
x = ((String)((Object) b.toString()));
|
||||
x = (String)(Object) b.toString();
|
||||
b = (Object) b.toString();
|
||||
b = (String) b.toString();
|
||||
if (true)
|
||||
break aaa;
|
||||
}
|
||||
if ("war".equals("peace"))
|
||||
continue;
|
||||
else if (1 == 0)
|
||||
break;
|
||||
|
||||
int x = 6;
|
||||
x ++;
|
||||
} while (false);
|
||||
|
||||
if (false)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; i < 4; i++) {
|
||||
System.out.println(i + "*" + j + "=" + (i * j));
|
||||
}
|
||||
}
|
||||
a: for (int i = 0; i < 3; i++) {
|
||||
b: for (int j = 0; j < 10; j++) {
|
||||
c: for (int k = 0; k < 10; k++) {
|
||||
if (true)
|
||||
break c;
|
||||
}
|
||||
|
||||
if ('c' == 'd')
|
||||
continue b;
|
||||
}
|
||||
|
||||
if (null instanceof Object)
|
||||
break a;
|
||||
}
|
||||
a: for (int i = 0; i < 3; i++) {
|
||||
b: for (int j = 0; j < i; i++) {
|
||||
c: for (int k = 0; k < j; k++) {
|
||||
if (true)
|
||||
;
|
||||
else
|
||||
continue c;
|
||||
}
|
||||
if ("freedom".equals("slavery"))
|
||||
break b;
|
||||
}
|
||||
if ("ignorance" == "strength")
|
||||
continue a;
|
||||
}
|
||||
|
||||
foo:
|
||||
;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class MethodMadness {
|
||||
public static int s = 12345;
|
||||
public int x = 100000;
|
||||
|
||||
public MethodMadness() {
|
||||
System.out.println("constructor");
|
||||
}
|
||||
public MethodMadness(String ss) {
|
||||
System.out.println("hello world"+ ss);
|
||||
}
|
||||
|
||||
public static void staticTest() {
|
||||
System.out.println("staticTest");
|
||||
}
|
||||
protected int protectedInteger() {
|
||||
this.s = 5;
|
||||
new MethodMadness("thrownaway").staticTest(); // MethodMadness object evaluated but thrown away
|
||||
new MethodMadness("thrownaway").s++; // MethodMadness object evaluated but thrown away
|
||||
staticTest();
|
||||
|
||||
MethodMadness nullmm = null;
|
||||
System.out.println("s from nullmm: "+nullmm.s); // static refs cannot cause NPEs
|
||||
|
||||
return 6 + x;
|
||||
}
|
||||
protected int protectedInteger2() {
|
||||
return 66 + x;
|
||||
}
|
||||
|
||||
void defaultVoid() {
|
||||
if ( true )
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
private void privateVoid() {
|
||||
System.out.println("privateVoid "+x);
|
||||
}
|
||||
protected void protectedVoid() {
|
||||
System.out.println("protectedVoid "+x);
|
||||
}
|
||||
|
||||
private int privateInteger() {
|
||||
return 7 + x;
|
||||
}
|
||||
private int privateInteger2() {
|
||||
return 77 + x;
|
||||
}
|
||||
|
||||
class Inner extends MethodMadness {
|
||||
public Inner() {
|
||||
x = 200000;
|
||||
}
|
||||
|
||||
private int privateInteger() {
|
||||
return 13 + x;
|
||||
}
|
||||
|
||||
protected int protectedInteger() {
|
||||
return 233 + x;
|
||||
}
|
||||
|
||||
public void hello() {
|
||||
System.out.println(privateInteger()); // inner function, inner this, 200013
|
||||
System.out.println(MethodMadness.this.privateInteger()); // outer function, outer this, 100007
|
||||
System.out.println(privateInteger2()); // outer function, outer this, 200077 // WRONG IN POLYGLOT (private)
|
||||
System.out.println(protectedInteger()); // inner function, inner this, 200233
|
||||
System.out.println(MethodMadness.this.protectedInteger()); // outer function, outer this
|
||||
System.out.println(protectedInteger2()); // outer function, inner this, 200066 // the interesting one
|
||||
privateVoid(); // outer function, outer this, 100000 // WRONG IN POLYGLOT (private)
|
||||
protectedVoid(); // outer function, inner this, 200000
|
||||
|
||||
defaultVoid();
|
||||
|
||||
staticTest();
|
||||
this.staticTest();
|
||||
MethodMadness.this.staticTest();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
new MethodMadness().new Inner().hello();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class MiniaturList {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int a;
|
||||
for ( ;; ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class Misc {
|
||||
|
||||
public static void main(String args[]) {
|
||||
if ( "hello" instanceof Object ) {
|
||||
System.out.println("strings are objects in java");
|
||||
Object x = (Object) "hello";
|
||||
String y = (String) x;
|
||||
String z = (String) null;
|
||||
x = (String) null;
|
||||
char a = 'a';
|
||||
switch (a) {
|
||||
case 'c':
|
||||
case 'b':
|
||||
case 'a':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package foo.bar.hello.world;
|
||||
|
||||
public class SwitchCase {
|
||||
|
||||
public static final int X = 10;
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
|
||||
int x = 5+X;
|
||||
// int y =6 +7;
|
||||
switch (x) {
|
||||
case 0:
|
||||
case 32:
|
||||
System.out.println("escucha");
|
||||
case 2:
|
||||
System.out.println("ve");
|
||||
break;
|
||||
case X:
|
||||
if ( false ) {
|
||||
System.out.println("Hello world");
|
||||
}
|
||||
break;
|
||||
case 4: {
|
||||
int z = 3;
|
||||
System.out.println("es un charm la vez " + z + "a");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
System.out.println("default");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class AnonGeneNullarySimple {
|
||||
|
||||
static interface Ops<E> {
|
||||
public E nullary();
|
||||
}
|
||||
|
||||
static class StrTripler implements Ops<String> {
|
||||
public String nullary() {
|
||||
String x = "talk about it ";
|
||||
return x+x+x;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new AnonGeneNullarySimple()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
Ops<String> ops = new StrTripler();
|
||||
String globalEconomy = ops.nullary();
|
||||
String localEconomy = new StrTripler().nullary();
|
||||
System.out.println(globalEconomy+localEconomy);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class AnonymousGenerics {
|
||||
|
||||
static interface Ops<E> {
|
||||
public E nullary();
|
||||
public E unary(E x);
|
||||
}
|
||||
|
||||
static class StrTripler implements Ops<String> {
|
||||
// if has type parameters, find overriding method and
|
||||
// get erasures for all of those types and make a new method
|
||||
// that calls this one (with casts). no worries about return values.
|
||||
public String unary(String x) {
|
||||
return x + x + x;
|
||||
}
|
||||
public String nullary() {
|
||||
String x = "talk about it ";
|
||||
return x+x+x;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new AnonymousGenerics()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
Ops<String> strQuadrupler = new Ops<String>() {
|
||||
public String unary(String x) {
|
||||
return x+x+x+x;
|
||||
}
|
||||
public String nullary() {
|
||||
String x = "time to make a move to the global economy ";
|
||||
return x+x+x+x;
|
||||
}
|
||||
};
|
||||
System.out.println(strQuadrupler.unary("hi"));
|
||||
System.out.println(new StrTripler().unary("hi"));
|
||||
|
||||
String globalEconomy = strQuadrupler.nullary();
|
||||
System.out.println(globalEconomy);
|
||||
|
||||
Ops<String> ops = new StrTripler();
|
||||
globalEconomy = ops.nullary();
|
||||
System.out.println(globalEconomy);
|
||||
|
||||
Ops hack = ops;
|
||||
hack.unary("whatever");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class BasicsGenerics {
|
||||
|
||||
static ArrayList<String> strs = new ArrayList<String>();
|
||||
static ArrayList ints = new ArrayList();
|
||||
|
||||
public BasicsGenerics() {
|
||||
strs.add("Coucou, monde!");
|
||||
}
|
||||
|
||||
public BasicsGenerics(String s) {
|
||||
strs.add(s);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
BasicsGenerics a = new BasicsGenerics();
|
||||
String frenchy = a.part1();
|
||||
//
|
||||
//
|
||||
String s = "mondo";
|
||||
String sicilian = new BasicsGenerics("ciao "+s).part2();
|
||||
//
|
||||
System.out.println(frenchy);
|
||||
System.out.println(sicilian);
|
||||
strs.add("hello");
|
||||
ints.add(new Integer(3));
|
||||
|
||||
String qqq;
|
||||
|
||||
for (Iterator iter = ((Iterable)ints).iterator(); iter.hasNext(); iter.next());
|
||||
|
||||
for (Iterator<String> iter = strs.iterator(); iter.hasNext();) {
|
||||
qqq = iter.next();
|
||||
System.out.println(qqq);
|
||||
}
|
||||
|
||||
Iterable s1 = strs;
|
||||
for (Iterator itertmp = s1.iterator(); itertmp.hasNext();) {
|
||||
String rrr = (String) itertmp.next();
|
||||
{
|
||||
System.out.println("la vida pasaba y sentia " + rrr);
|
||||
}
|
||||
}
|
||||
|
||||
for (String rrr: strs) {
|
||||
System.out.println("la vida pasaba y sentia " + rrr);
|
||||
}
|
||||
|
||||
for (String rrr: strs) {
|
||||
System.out.println("la vida pasaba y sentia " + rrr);
|
||||
}
|
||||
|
||||
for ( String x: makeArray() )
|
||||
System.out.println(x);
|
||||
//
|
||||
// System.out.println("---break time---");
|
||||
// for ( int i = 0; i < makeArray().length; i++ )
|
||||
// System.out.println(makeArray()[i]);
|
||||
}
|
||||
|
||||
public static String[] makeArray() {
|
||||
String[] hey = {"hey","whats","up"};
|
||||
System.out.println("give a hoot");
|
||||
return hey;
|
||||
}
|
||||
|
||||
public String part1() {
|
||||
return strs.get(0);
|
||||
}
|
||||
|
||||
public String part2() {
|
||||
return strs.get(0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class Cocovariant {
|
||||
static class A {
|
||||
A foo(String x) { return null; }
|
||||
}
|
||||
static class B extends A {
|
||||
B foo(String x) { return null; }
|
||||
}
|
||||
static class C extends B {
|
||||
C foo(String x) { return null; }
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
(new Cocovariant()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
A a = new A();
|
||||
a.foo("");
|
||||
a = new B();
|
||||
a.foo("");
|
||||
a = new C();
|
||||
a.foo("");
|
||||
B b = new B();
|
||||
b.foo("");
|
||||
b = new C();
|
||||
b.foo("");
|
||||
C c = new C();
|
||||
c.foo("");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
// what IS illegal and we don't have to worry about:
|
||||
// "x instanceof E"
|
||||
// y = new Q();
|
||||
|
||||
interface IGeneric<E> {
|
||||
E foo();
|
||||
|
||||
E bar(E x, E y);
|
||||
}
|
||||
|
||||
// Y: "implements IGeneric" (no <E>)
|
||||
// TOTRY: two arguments
|
||||
class ConcreteGeneric<Q> implements IGeneric<Q> {
|
||||
Q x;
|
||||
|
||||
public Q bar(Q a, Q b) {
|
||||
x = a;
|
||||
if (b.hashCode() == a.hashCode() || b.toString().equals(a.toString()))
|
||||
return a;
|
||||
return b;
|
||||
}
|
||||
|
||||
public Q foo() {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
class ConcreteGeneric2<Q> extends ConcreteGeneric<Q> {
|
||||
Q y;
|
||||
public void setFoo(Q a) {
|
||||
y = a;
|
||||
}
|
||||
public Q foo() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
class MyGeneric<A extends Object, B extends IGeneric<A>> {
|
||||
A a;
|
||||
B b; // TODO: check field type
|
||||
public MyGeneric(A a, B b) { // TODO: check parameter type
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
public A doFoo() { // TODO: check return value type
|
||||
return b.foo();
|
||||
}
|
||||
public B getB() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomGenericsAndFields {
|
||||
static ConcreteGeneric2<String> cg2 = new ConcreteGeneric2<String>();
|
||||
|
||||
static public ConcreteGeneric2<String> cg2WithSideEffects() {
|
||||
System.out.println("look at me! I'm a side effect!");
|
||||
return cg2;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new CustomGenericsAndFields()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
// Simple: concrete generic
|
||||
|
||||
ConcreteGeneric<String> absinthe = new ConcreteGeneric<String>();
|
||||
IGeneric<String> rye = absinthe;
|
||||
String foo = rye.bar("hello", "world");
|
||||
System.out.println(absinthe.foo() + foo);
|
||||
|
||||
/////////////////////////////
|
||||
|
||||
String thrownaway = cg2.bar("a","b");
|
||||
cg2.setFoo("real one");
|
||||
MyGeneric<String,ConcreteGeneric2<String>> mygeneric = new MyGeneric<String,ConcreteGeneric2<String>>("useless",cg2);
|
||||
String x = mygeneric.doFoo();
|
||||
System.out.println(x);
|
||||
String y = cg2.x;
|
||||
System.out.println(mygeneric.getB().y);
|
||||
System.out.println(mygeneric.b.y); // TODO: fields are going to be a pain... watch out for Lvalues in context?
|
||||
cg2.x = null;
|
||||
cg2.x = "hello";
|
||||
|
||||
// mygeneric.getB().y+="hey"; // TODO: this is going to be a MAJOR pain...
|
||||
String real_oneheyya = (((cg2WithSideEffects().y))+="hey")+"ya"; // TODO: this is going to be a MAJOR pain...
|
||||
System.out.println(real_oneheyya);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class EnumSwitch {
|
||||
public enum Palo {
|
||||
OROS,
|
||||
COPAS,
|
||||
ESPADAS,
|
||||
BASTOS;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
for(Palo p : Palo.values()) {
|
||||
(new EnumSwitch()).doit(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void doit(Palo caballo) {
|
||||
int x = 5;
|
||||
int y = 3, z = 2;
|
||||
int total = 0;
|
||||
switch ( caballo ) {
|
||||
case OROS:
|
||||
total = x - y;
|
||||
System.out.println("gold"); break;
|
||||
case COPAS:
|
||||
total = x * x;
|
||||
y = y + y;
|
||||
System.out.println("cups"); break;
|
||||
case ESPADAS:
|
||||
total = z + z;
|
||||
y = 2 + 4;
|
||||
System.out.println("swords"); break;
|
||||
case BASTOS:
|
||||
total = x / y + z;
|
||||
z = x + y;
|
||||
System.out.println("clubs"); break;
|
||||
default:
|
||||
total = x + x + x + x;
|
||||
System.out.println("baraja inglesa");
|
||||
}
|
||||
System.out.println(x);
|
||||
System.out.println(y);
|
||||
System.out.println(z);
|
||||
System.out.println(total);
|
||||
System.out.println(Palo.valueOf(caballo.toString()));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class ExplicitBoxingTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
(new ExplicitBoxingTest()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
int a = 6;
|
||||
a = a + a;
|
||||
System.out.println(a);
|
||||
Integer useless1 = new Integer(5+6);
|
||||
Integer aa = new Integer(a+a);
|
||||
int aaa = aa.intValue();
|
||||
System.out.println(aaa);
|
||||
|
||||
int b = 6;
|
||||
b = b + b;
|
||||
System.out.println(b);
|
||||
Integer useless2 = 5+6;
|
||||
Integer bb = b+b;
|
||||
int bbb = bb;
|
||||
System.out.println(bbb);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GenericArrays {
|
||||
public static void main(String args[]) {
|
||||
(new GenericArrays()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
List<?>[] lsa = new List<?>[10]; // ok, array of unbounded wildcard type
|
||||
Object o = lsa;
|
||||
Object[] oa = (Object[]) o;
|
||||
List<Integer> li = new ArrayList<Integer>();
|
||||
li.add(new Integer(3));
|
||||
oa[1] = li; // correct
|
||||
String s = (String) lsa[1].get(0); // run time error, but cast is explicit
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GenericMemberClasses<T>
|
||||
{
|
||||
protected class A implements Iterator<T>
|
||||
{
|
||||
T x = null;
|
||||
private int localChangeID;
|
||||
public boolean hasNext() {
|
||||
return ( localChangeID == 5 );
|
||||
}
|
||||
|
||||
public T next() {
|
||||
localChangeID = 5;
|
||||
return x;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
}
|
||||
}
|
||||
public static void main(String args[]) {
|
||||
(new GenericMemberClasses<Object>()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
A a = new A();
|
||||
while (a.hasNext()) {
|
||||
Object x = a.next();
|
||||
a.remove();
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class GenericSuperSink {
|
||||
public static void main(String args[]) {
|
||||
(new GenericSuperSink()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
Collection<? super String> sink;
|
||||
Collection<String> cs = new ArrayList<String>();
|
||||
cs.add("hello");
|
||||
|
||||
sink = new ArrayList<Object>();
|
||||
sink.add(cs.iterator().next());
|
||||
System.out.println(sink);
|
||||
|
||||
sink = new ArrayList<String>();
|
||||
sink.add(cs.iterator().next());
|
||||
System.out.println(sink);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MethodGenerics {
|
||||
static <T> void fromArrayToCollection(T[] a, Collection<T> c) {
|
||||
c.add(a[0]);
|
||||
}
|
||||
|
||||
static <T extends String> void foo(String x, T y) {
|
||||
x = y;
|
||||
System.out.println(x);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new MethodGenerics()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
String array[] = new String[] { "coucou monde", "ciao mondo", "guten tag welt", "hola mundo", "shalom olam" };
|
||||
fromArrayToCollection(array, list);
|
||||
System.out.println(list);
|
||||
foo("whatever", "whatever");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class MoreOverriddenGenerics {
|
||||
class Super<T> {
|
||||
T x;
|
||||
|
||||
public T get() {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
class Sub extends Super<Number> {
|
||||
public Number get() {
|
||||
return super.get();
|
||||
}
|
||||
}
|
||||
|
||||
class SubSub extends Sub {
|
||||
public Long get() {
|
||||
return new Long(6);
|
||||
}
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
String x = new Super<String>().get();
|
||||
System.err.println(x);
|
||||
Super<Number> s = new Sub();
|
||||
Number n = s.get();
|
||||
SubSub sss = new SubSub();
|
||||
n = sss.get();
|
||||
Sub ss = sss;
|
||||
n = ss.get();
|
||||
s = sss;
|
||||
n = s.get();
|
||||
System.err.println(n);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new MoreOverriddenGenerics()).doit();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class NotSoSimpleEnums {
|
||||
public enum Direction {
|
||||
NORTH("nord") { public Direction getOpposite() { return SOUTH; }},
|
||||
EAST("est") { public Direction getOpposite() { return WEST; }},
|
||||
SOUTH("sud") { public Direction getOpposite() { return NORTH; }},
|
||||
WEST("ouest") { public Direction getOpposite() { return EAST; }};
|
||||
|
||||
public abstract Direction getOpposite();
|
||||
|
||||
String translation;
|
||||
Direction(String translation) {
|
||||
this.translation = translation;
|
||||
}
|
||||
public String getTranslation() {
|
||||
return translation;
|
||||
}
|
||||
}
|
||||
|
||||
private void doit(Direction d) {
|
||||
System.out.println(d.getTranslation() + " " + Direction.valueOf(d.getOpposite().toString()));
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("never eat shredded wheat");
|
||||
for(Direction d : Direction.values()) {
|
||||
(new NotSoSimpleEnums()).doit(d);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class OverridesOnePointFour {
|
||||
static interface Super {
|
||||
public Number get();
|
||||
}
|
||||
|
||||
static class Sub implements Super {
|
||||
public Long get() {
|
||||
return new Long(6);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new OverridesOnePointFour()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
Super sup = new Sub();
|
||||
Number x = sup.get();
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
import javaonepointfive.NotSoSimpleEnums.Direction;
|
||||
|
||||
public class SimpleEnums {
|
||||
public enum Direction {
|
||||
NORTH,
|
||||
EAST,
|
||||
SOUTH,
|
||||
WEST;
|
||||
|
||||
}
|
||||
|
||||
private void doit(Direction d) {
|
||||
System.out.println(d + " " + Direction.valueOf(d.toString()));
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("never eat shredded wheat");
|
||||
for(Direction d : Direction.values()) {
|
||||
(new SimpleEnums()).doit(d);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class SimpleEnums2 {
|
||||
public enum Direction {
|
||||
NORTH,
|
||||
EAST,
|
||||
SOUTH,
|
||||
WEST;
|
||||
public static void hello() {
|
||||
System.out.println(NORTH);
|
||||
}
|
||||
|
||||
public static Direction[] myValues() {
|
||||
return new Direction[] { NORTH, EAST, SOUTH, WEST };
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new SimpleEnums2()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
System.out.println("never eat shredded wheat");
|
||||
System.out.println(Direction.NORTH);
|
||||
System.out.println(Direction.EAST);
|
||||
System.out.println(Direction.SOUTH);
|
||||
System.out.println(Direction.WEST);
|
||||
|
||||
Direction abc = Enum.valueOf(Direction.class, "NORTH");
|
||||
Direction efg = Direction.valueOf("NORTH");
|
||||
System.out.println(abc);
|
||||
System.out.println(efg);
|
||||
|
||||
Direction x = Direction.values()[0];
|
||||
System.out.println(x);
|
||||
Direction y = Direction.myValues()[0];
|
||||
System.out.println(y);
|
||||
}
|
||||
|
||||
// public static class Foo {
|
||||
// public static final Foo foo = new Foo("NORTH",1);
|
||||
// public Foo(String string, int i) {
|
||||
// }
|
||||
// }
|
||||
// public static void main(String args[]) {
|
||||
// System.out.println(Foo.foo);
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class Varargs {
|
||||
public Varargs(int... x) {
|
||||
System.out.println(x[0]==x[1]);
|
||||
}
|
||||
public Varargs() {
|
||||
this(1,1);
|
||||
}
|
||||
|
||||
public static void varargs(int x, int y, Object... foo) {
|
||||
System.out.println(x);
|
||||
System.out.println(y);
|
||||
for (int i = 0; i < foo.length; i++)
|
||||
System.out.println(foo[i]);
|
||||
|
||||
new Varargs();
|
||||
}
|
||||
|
||||
// try overriding a function and causing havoc (i assume it knows at compile time whether to expand varargs)
|
||||
public static void varargs(int x, int y, String foo, String xa, String ya, String z) {
|
||||
System.out.println("gotcha!");
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
varargs(2, 3, new String[] { "hello", "world" });
|
||||
varargs(2, 3, (Object) new String[] { "hello", "world" });
|
||||
varargs(2, 3, (Object[]) new String[] { "hello", "world" });
|
||||
varargs(2, 3);
|
||||
varargs(2, 3, "hi");
|
||||
varargs(2, 3, "hello", "there");
|
||||
varargs(4, 5, "coucou", "monde", "shalom", "'olam");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
public class VarargsCovariant {
|
||||
static class A {
|
||||
A hello(int... x) {
|
||||
System.out.println("a hello");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
static class B extends A {
|
||||
B hello(int... x) {
|
||||
System.out.println("b hello");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new VarargsCovariant()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
A a = new A();
|
||||
a.hello(3114, 35, 74, 51617054);
|
||||
a = new B();
|
||||
a.hello(3114, 35, 74, 51617054);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
class Alef {
|
||||
void foo(String... args) {
|
||||
System.out.println("var args not overridden");
|
||||
}
|
||||
}
|
||||
|
||||
class Bet extends Alef {
|
||||
void foo(String a, String b) {
|
||||
System.out.println("non-varargs overrides varargs");
|
||||
}
|
||||
}
|
||||
|
||||
class Alpha {
|
||||
void foo(String a, String b) {
|
||||
System.out.println("non-varargs not overridden");
|
||||
}
|
||||
}
|
||||
|
||||
class Beta extends Alpha {
|
||||
void foo(String... args) {
|
||||
System.out.println("varargs overrides non-varargs");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////
|
||||
|
||||
class VarityTestSuper {
|
||||
void bar(String... args) {}
|
||||
}
|
||||
|
||||
class VarityTestSub extends VarityTestSuper {
|
||||
void bar(String... args) {}
|
||||
}
|
||||
|
||||
public class VarargsOverriding {
|
||||
public static void main(String args[]) {
|
||||
(new VarargsOverriding()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
Bet b = new Bet();
|
||||
Alef a = b;
|
||||
a.foo("hello", "world");
|
||||
b.foo("hello", "world");
|
||||
|
||||
Beta bb = new Beta();
|
||||
Alpha aa = bb;
|
||||
aa.foo("hello", "world");
|
||||
bb.foo("hello", "world");
|
||||
bb.foo("hello", "world", "and", "more");
|
||||
|
||||
VarityTestSuper x = new VarityTestSuper();
|
||||
x.bar("Hello", "world", "howareya");
|
||||
x = new VarityTestSub();
|
||||
x.bar("Hello", "world", "howareya");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is a derivative of code released by the University of
|
||||
* California under the terms listed below.
|
||||
*
|
||||
* WALA JDT Frontend is Copyright (c) 2008 The Regents of the
|
||||
* University of California (Regents). Provided that this notice and
|
||||
* the following two paragraphs are included in any distribution of
|
||||
* Refinement Analysis Tools or its derivative work, Regents agrees
|
||||
* not to assert any of Regents' copyright rights in Refinement
|
||||
* Analysis Tools against recipient for recipient's reproduction,
|
||||
* preparation of derivative works, public display, public
|
||||
* performance, distribution or sublicensing of Refinement Analysis
|
||||
* Tools and derivative works, in source code and object code form.
|
||||
* This agreement not to assert does not confer, by implication,
|
||||
* estoppel, or otherwise any license or rights in any intellectual
|
||||
* property of Regents, including, but not limited to, any patents
|
||||
* of Regents or Regents' employees.
|
||||
*
|
||||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
|
||||
* AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
|
||||
* WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
|
||||
* DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
|
||||
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package javaonepointfive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Wildcards {
|
||||
public void printCollection(ArrayList<?> c) {
|
||||
// for (Object e : c) {
|
||||
|
||||
// for (Iterator tmp = c.iterator(); tmp.hasNext(); ) {
|
||||
// Object e = tmp.next();
|
||||
|
||||
Object e = c.get(0);
|
||||
System.out.println(e);
|
||||
// }
|
||||
}
|
||||
public void printCollection1(ArrayList<? extends Object> c) {
|
||||
Object e = c.get(0);
|
||||
System.out.println(e);
|
||||
}
|
||||
public void printCollection2(ArrayList<? extends String> c) {
|
||||
String e = c.get(0);
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
(new Wildcards()).doit();
|
||||
}
|
||||
|
||||
private void doit() {
|
||||
ArrayList<String> e = new ArrayList<String>();
|
||||
e.add("hello");
|
||||
e.add("goodbye");
|
||||
printCollection(e);
|
||||
printCollection1(e);
|
||||
printCollection2(e);
|
||||
|
||||
ArrayList<Integer> e3 = new ArrayList<Integer>();
|
||||
e3.add(new Integer(123));
|
||||
e3.add(new Integer(42));
|
||||
printCollection(e3);
|
||||
printCollection1(e3);
|
||||
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ public class NonPrimaryTopLevel {
|
|||
Foo f = new Foo();
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
|
||||
}
|
Loading…
Reference in New Issue