move CAst Java test data to separate project to ease use in plugin tests

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3139 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
dolby-oss 2008-12-16 15:14:00 +00:00
parent ba7e4f1fab
commit c181f33310
46 changed files with 1306 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="testSrc"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.ibm.wala.cast.java.test.data</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,7 @@
#Thu Dec 11 09:45:37 EST 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5

View File

@ -0,0 +1,6 @@
java\/awt\/.*
javax\/swing\/.*
sun\/awt\/.*
sun\/swing\/.*
com\/sun\/.*
sun\/.*

View File

@ -0,0 +1,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Data Plug-in
Bundle-SymbolicName: com.ibm.wala.cast.java.test.data
Bundle-Version: 1.0.0
Bundle-Activator: com.ibm.wala.cast.java.test.data.Activator
Bundle-Vendor: IBM
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy

View File

@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View File

@ -0,0 +1,46 @@
public class AnonymousClass {
private interface Foo {
public int getValue();
public int getValueBase();
}
public static void main(String[] args) {
final Integer base = new Integer(6);
Foo f= new Foo() {
int value = 3;
public int getValue() { return value; }
public int getValueBase() { return value - base.intValue(); }
};
System.out.println(f.getValue());
System.out.println(f.getValueBase());
(new AnonymousClass()).method();
}
public void method() {
final Integer base = new Integer(7);
abstract class FooImpl implements Foo {
int y;
public abstract int getValue();
FooImpl(int _y) {
y = _y;
}
public int getValueBase() {
return y + getValue() - base.intValue();
}
}
Foo f= new FooImpl(-4) {
public int getValue() { return 7; }
};
System.out.println(f.getValue());
System.out.println(f.getValueBase());
}
}

View File

@ -0,0 +1,19 @@
public class Array1 {
public static void main(String[] args) {
Array1 f= new Array1();
f.foo();
}
public void foo() {
int[] ary = new int[5];
for(int i= 0; i < ary.length; i++) {
ary[i]= i;
}
int sum = 0;
for(int j= 0; j < ary.length; j++) {
sum += ary[j];
}
}
}

View File

@ -0,0 +1,8 @@
public class ArrayLiteral1 {
public static void main(String[] args) {
ArrayLiteral1 al1= new ArrayLiteral1();
int[] a= new int[] { 0, 1, 2, 3, 5 };
Object[] b= new Object[] { null, "hi", new Integer(55), new int[] { 3, 1, 4 } };
}
}

View File

@ -0,0 +1,7 @@
public class ArrayLiteral2 {
public static void main(String[] args) {
ArrayLiteral2 al2= new ArrayLiteral2();
int[] x= {};
int[] y= { 1, 2, 3, 4 };
}
}

View File

@ -0,0 +1,35 @@
public class Breaks {
private static class Ref {
String[] classes;
String[] getClasses() {
return classes;
}
private Ref(String[] classes) {
this.classes = classes;
}
}
private void testBreakFromIf(String objectClass, Ref reference) {
objectClassCheck:
if (objectClass != null) {
String[] classes = reference.getClasses();
int size = classes.length;
for (int i = 0; i < size; i++) {
if (classes[i] == objectClass)
break objectClassCheck;
}
return;
}
if (objectClass == null) {
reference.classes = null;
}
}
public static void main(String[] args) {
(new Breaks()).testBreakFromIf("whatever", new Ref(args));
}
}

View File

@ -0,0 +1,7 @@
public class CastFromNull {
public static void main(String args[]) {
new CastFromNull();
Object x = (Object) null;
String y = (String) null;
}
}

View File

@ -0,0 +1,27 @@
public class Casts {
public static void main(String[] args) {
(new Casts()).test(args);
}
private void test(String[] args) {
long l1 = Long.parseLong(args[0]);
int i1 = Integer.parseInt(args[1]);
short s1 = Short.parseShort(args[2]);
float f1 = Float.parseFloat(args[3]);
double d1 = Double.parseDouble(args[4]);
double d2 = d1 + f1;
double d3 = d1 + l1;
double d4 = d1 + i1;
float f2 = f1 + i1;
float f3 = f1 + s1;
long l2 = l1 + i1;
long l3 = l1 + s1;
int i2 = i1 + s1;
}
}

View File

@ -0,0 +1,61 @@
public class DefaultConstructors {
public static void main(String args[]) {
E e = new E();
// System.out.println(e.x);
// System.out.println(e.y);
e = new E(7,8);
// System.out.println(e.x);
// System.out.println(e.y);
Object x[] = new Object[4];
x.clone();
x.equals(new Object());
x.toString();
}
}
class dcA {
int x;
dcA() {
x = 5;
}
dcA(int a) {
x = a;
}
}
class dcB extends dcA {
dcB() {
super();
}
}
class C extends dcA {
C() {
// implicit call to super(). we want to see if it's the same as above
}
}
class D extends dcA {
// implicit constructor, should be same as above
}
class E extends dcA {
int y;
E() {
// no implicit call
this(6);
}
E(int z) {
// implicit call to A()
this.y = z;
}
E(int a, int b) {
// no implicit call
super(a);
y = b;
}
}

View File

@ -0,0 +1,37 @@
public class Exception1 {
public static void main(String[] args) {
Exception1 e1= new Exception1();
try {
FooEx1 f = new FooEx1();
f.bar();
} catch(BadLanguageExceptionEx1 e) {
e.printStackTrace();
}
try {
FooEx2 f = new FooEx2();
f.bar();
} catch(Throwable e) {
e.printStackTrace();
}
}
}
class FooEx1 {
public void bar() throws BadLanguageExceptionEx1 {
throw new BadLanguageExceptionEx1();
}
}
class FooEx2 {
public void bar() {
throw new NullPointerException();
}
}
class BadLanguageExceptionEx1 extends Exception {
public BadLanguageExceptionEx1() {
super("Try using a real language, like Perl");
}
}

View File

@ -0,0 +1,41 @@
import java.io.*;
public final class Exception2 {
public static void main(String[] args) {
Exception2 e2= new Exception2();
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream( args[0] );
fos = new FileOutputStream( args[1] );
int data;
while ( (data = fis.read()) != -1 ) {
fos.write(data);
}
} catch (FileNotFoundException e) {
System.err.println( "File not found" );
// whatever
} catch (IOException e) {
System.err.print( "I/O problem " );
System.err.println( e.getMessage() );
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
System.exit(-1);
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
System.exit(-1);
}
}
}
}
}

View File

@ -0,0 +1,25 @@
public class Finally1 {
public static void main(String[] args) throws BadLanguageExceptionF1 {
Finally1 f1= new Finally1();
try {
FooF1 f = new FooF1();
f.bar();
} finally {
System.out.println("blah");
}
System.out.println("feep");
}
}
class FooF1 {
public void bar() throws BadLanguageExceptionF1 {
if (true)
throw new BadLanguageExceptionF1();
System.out.println("feh");
}
}
class BadLanguageExceptionF1 extends Exception {
public BadLanguageExceptionF1() {
super("Try using a real language, like Perl");
}
}

View File

@ -0,0 +1,29 @@
import java.io.IOException;
public class Finally2 {
public static void main(String[] args) throws IOException {
try {
FooF2 f = new FooF2();
f.bar();
f.bletch();
} catch (BadLanguageExceptionF2 e) {
e.printStackTrace();
} finally {
System.out.println("blah");
}
}
}
class FooF2 {
public void bar() throws BadLanguageExceptionF2 {
throw new BadLanguageExceptionF2();
}
public void bletch() throws IOException {
throw new IOException("Burp!");
}
}
class BadLanguageExceptionF2 extends Exception {
public BadLanguageExceptionF2() {
super("Try using a real language, like Perl");
}
}

View File

@ -0,0 +1,28 @@
public class FunkySupers {
int y;
int funky(FunkySupers fs) {
return 5;
}
public static void main(String args[]) {
new SubFunkySupers().funky(new FunkySupers());
}
}
class SubFunkySupers extends FunkySupers {
int funky(FunkySupers fs) {
SubFunkySupers.super.funky(fs);
SubFunkySupers.this.funky(fs);
SubFunkySupers.this.y = 7;
SubFunkySupers.super.y = 7;
super.y = 7;
super.funky(fs);
return 6;
}
}
//class EE { class X {} }
//class Y extends EE.X { Y(EE e) { e.super(); } }
// DOESNT WORK IN POLYGLOT!!!

View File

@ -0,0 +1,28 @@
public class Inheritance1 {
public static void main(String[] args) {
Inheritance1 ih1= new Inheritance1();
Base b1 = new Base();
Base b2 = new Derived();
b1.foo();
b2.foo();
b1.bar(3);
b2.bar(5);
}
}
class Base {
public void foo() {
int i= 0;
}
public String bar(int x) {
return Integer.toOctalString(x);
}
}
class Derived extends Base {
public void foo() {
super.foo();
}
public String bar(int x) {
return Integer.toHexString(x);
}
}

View File

@ -0,0 +1,20 @@
public class InheritedField {
public static void main(String[] args) {
InheritedField if1= new InheritedField();
B b = new B();
b.foo();
b.bar();
}
}
class A {
protected int value;
}
class B extends A {
public void foo() {
value = 10;
}
public void bar() {
this.value *= 2;
}
}

View File

@ -0,0 +1,49 @@
public class InnerClass {
public static void main(String[] args) {
(new InnerClass()).method();
}
public int fromInner(int v) {
return v + 1;
}
public int fromInner2(int v) {
return v + 3;
}
public void method() {
WhatsIt w= new WhatsIt();
}
class WhatsThat {
private int otherValue;
WhatsThat() {
otherValue = 3;
fromInner2( otherValue );
}
}
class WhatsIt {
private int value;
public WhatsIt() {
value= 0;
fromInner(value);
anotherMethod();
}
private NotAgain anotherMethod() {
return new NotAgain();
}
class NotAgain {
Object x;
public NotAgain() {
x = new WhatsThat();
}
}
}
}

View File

@ -0,0 +1,125 @@
// 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();
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
}
}
}
}

View File

@ -0,0 +1,47 @@
interface IntConstant {
int getConstant();
}
public class InnerClassLexicalReads {
/*
* CAst Instructions:
* 2 v3 = new <Source,LInnerClassLexicalReads/makeIntConstant(I)LIntConstant;/<anonymous subtype of IntConstant>$9$9>@2[9:9] -> [13:3]
* 3 invokespecial < Source, LInnerClassLexicalReads/makeIntConstant(I)LIntConstant;/<anonymous subtype of IntConstant>$9$9, <init>()V > v3 @3 exception:v5[9:9] -> [13:3]
* 4 return v3 [9:2] -> [13:4]
*/
public static IntConstant makeIntConstant(int x) {
final int y = x * x;
return new IntConstant() {
// CAst CONSTRUCTOR Instructions:
// 1 invokespecial < Source, Ljava/lang/Object, <init>()V > v1 @1 exception:v3[20:9] -> [32:3]
/*
* CAst Instructions:
* 0 v2:com.ibm.wala.ssa.SymbolTable$1@16b18b6 = lexical:y@LInnerClassLexicalReads/makeIntConstant(I)LIntConstant;
* 1 return v2:com.ibm.wala.ssa.SymbolTable$1@16b18b6[11:4] -> [11:13]
*/
public int getConstant() {
return y;
}
};
}
/*
* CAst Instructions:
* 1 v2:com.ibm.wala.ssa.SymbolTable$1@4272b2 = invokestatic < Source, LInnerClassLexicalReads, makeIntConstant(I)LIntConstant; > v3:#123 @1 exception:v4[17:19] -> [17:39]
* 2 v7 = getstatic < Source, Ljava/lang/System, out, <Source,Ljava/io/PrintStream> >[18:2] -> [18:12]
* 3 v8 = invokeinterface < Source, LIntConstant, getConstant()I > v2:com.ibm.wala.ssa.SymbolTable$1@4272b2 @3 exception:v9[18:21] -> [18:37]
* 4 invokevirtual < Source, Ljava/io/PrintStream, println(I)V > v7,v8 @4 exception:v10[18:2] -> [18:38]
*/
public static void main(String args[]) {
InnerClassLexicalReads ignored = new InnerClassLexicalReads(); // call this just to make <init> reachable (test checks for unreachable methods)
int foo = 5;
int haha = foo * foo;
IntConstant ic = makeIntConstant(haha);
System.out.println(ic.getConstant());
int x = ic.getConstant();
System.out.println(x);
}
}

View File

@ -0,0 +1,19 @@
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();
}
}
}

View File

@ -0,0 +1,21 @@
public class InterfaceTest1 {
public static void main(String[] args) {
InterfaceTest1 it= new InterfaceTest1();
IFoo foo = new FooIT1('a');
char ch2 = foo.getValue();
}
}
interface IFoo {
char getValue();
}
class FooIT1 implements IFoo {
private char fValue;
public FooIT1(char ch) {
fValue= ch;
}
public char getValue() {
return fValue;
}
}

View File

@ -0,0 +1,33 @@
public class LocalClass {
public static void main(String[] args) {
final Integer base = new Integer(6);
class Foo {
int value;
public Foo(int v) { value= v; }
public int getValue() { return value; }
public int getValueBase() { return value - base.intValue(); }
}
Foo f= new Foo(3);
System.out.println(f.getValue());
System.out.println(f.getValueBase());
(new LocalClass()).method();
}
public void method() {
final Integer base = new Integer(6);
class Foo {
int value;
public Foo(int v) { value= v; }
public int getValue() { return value; }
public int getValueBase() { return value - base.intValue(); }
}
Foo f= new Foo(3);
System.out.println(f.getValue());
System.out.println(f.getValueBase());
}
}

View File

@ -0,0 +1,53 @@
public class MiniaturList {
MiniaturList next;
int data;
public MiniaturList remove(int elt) {
MiniaturList xp = null;
MiniaturList head = this;
MiniaturList x = head;
while (x != null) {
if (x.data == elt) {
if (xp == null)
head = x.next;
else
xp.next = x.next;
break;
}
xp = x;
x = x.next;
}
return head;
}
public static MiniaturList cons(int elt, MiniaturList l) {
MiniaturList ret = new MiniaturList();
ret.data = elt;
ret.next = l;
return ret;
}
public boolean contains(int elt) {
MiniaturList head = this;
while (head != null) {
if (head.data == elt)
return true;
head = head.next;
}
return false;
}
public static void main(String[] args) {
MiniaturList l1 = cons(1, cons(2, cons(3, cons(2, null))));
MiniaturList l2 = cons(5, null);
l1 = l1.remove(2);
//assert 2 !in l1.*next.data
System.out.println(l1.contains(3));
System.out.println(l2.contains(6));
}
}

View File

@ -0,0 +1,73 @@
abstract class PrimitiveWrapper {
/**
* Sets the integer representation of the underlying primitive
* to the given value.
* @effects this.intVal' = i
*/
public abstract void setIntValue(int i);
/**
* Returns the integer representation of the underlying primitive.
* @return this.intVal
*/
public abstract int intValue();
/**
* Returns true if this and the given object are
* pri
* {@inheritDoc}
* @see java.lang.Object#equals(java.lang.Object)
*/
abstract public boolean equals(Object o);
}
final class IntWrapper extends PrimitiveWrapper {
private int val;
/**
* Constructs a wrapper for the given int.
* @effects this.intVal' = val
*/
public IntWrapper(int val) {
this.val = val;
}
/**
* {@inheritDoc}
* @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#intValue()
*/
public int intValue() {
return val;
}
/**
* {@inheritDoc}
* @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#setIntValue(int)
*/
public void setIntValue(int i) {
this.val = i;
}
/**
* {@inheritDoc}
* @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#equals(java.lang.Object)
*/
public boolean equals(Object o) {
return o instanceof IntWrapper && ((IntWrapper)o).val==val;
}
}
public class MiniaturSliceBug {
public void validNonDispatchedCall(IntWrapper wrapper) {
wrapper.setIntValue(3);
assert wrapper.intValue() == 3;
wrapper.equals(wrapper);
}
public static void main(String[] args) {
(new MiniaturSliceBug()).validNonDispatchedCall(new IntWrapper(-1));
}
}

View File

@ -0,0 +1,11 @@
public class Monitor {
int i = 0;
public Monitor() { }
public void incr() { synchronized(this) { i++; } }
public static void main(String[] a) {
new Monitor().incr();
}
}

View File

@ -0,0 +1,15 @@
public class Monitor2 {
int i = 0;
public Monitor2() { }
public void incr() { synchronized(this) { i++; } }
private static boolean test(Object o) {
return true;
}
public static void main(String[] a) {
new Monitor2().incr();
}
}

View File

@ -0,0 +1,15 @@
public class NullArrayInit {
String[] x = {null};
public static void main(String[] args) {
new NullArrayInit();
Object a[] = new Object[] {null,null};
Object b[] = {null};
String c[] = {null};
String d[] = {null,null};
String e[] = {null,"hello",null};
String f[] = new String[] {null};
String g[] = new String[] {null,null,null};
String j[][] = { {null,null}, {null} };
}
}

View File

@ -0,0 +1,10 @@
public class QualifiedStatic {
public static void main(String[] args) {
QualifiedStatic qs= new QualifiedStatic();
FooQ fq= new FooQ();
int x = FooQ.value;
}
}
class FooQ {
static int value= 0;
}

View File

@ -0,0 +1,13 @@
public class Scoping1 {
public static void main(String[] args) {
Scoping1 s1= new Scoping1();
{
int x= 5;
System.out.println(x);
}
{
double x= 3.14;
System.out.println(x);
}
}
}

View File

@ -0,0 +1,18 @@
public class Scoping2 {
public static void main(String[] args) {
Scoping2 s2= new Scoping2();
{
final int x= 5;
System.out.println(x);
(new Object() {
public void foo() {
System.out.println("x = " + x);
}
}).foo();
}
{
double x= 3.14;
System.out.println(x);
}
}
}

View File

@ -0,0 +1,31 @@
public class Simple1 {
private int value;
private final float fval = 3.14F;
private float fval1 = 3.2F;
public Simple1(int x) {
value = x;
}
public Simple1() {
this(0);
}
public static void doStuff(int N) {
int prod = 1;
for(int j=0; j < N; j++)
prod *= j;
}
public static void main(String[] args) {
int sum= 0;
for(int i=0; i < 10; i++) {
sum += i;
}
Simple1.doStuff(sum);
Simple1 s = new Simple1();
s.instanceMethod1();
}
public void instanceMethod1() {
instanceMethod2();
}
public float instanceMethod2() {
return fval * fval1;
}
}

View File

@ -0,0 +1,22 @@
interface ISimpleCalls {
public void helloWorld();
}
public class SimpleCalls implements ISimpleCalls {
public void helloWorld() {
System.out.println("hello world!");
}
public int anotherCall() {
this.helloWorld();
((this)).helloWorld();
System.out.println("another call");
return 5;
}
public static void main (String args[]) {
SimpleCalls sc = new SimpleCalls();
ISimpleCalls isc = sc;
isc.helloWorld();
int y = sc.anotherCall();
y = y + y;
}
}

View File

@ -0,0 +1,31 @@
public class StaticInit {
static class X {
int x;
int y;
int sum() {
return x+y;
}
int diff() {
return x+-y;
}
}
private static X x = new X();
private static X y;
static {
y = new X();
}
private static int sum() {
return x.sum() * y.diff();
}
public static void main(String[] args) {
StaticInit SI = new StaticInit();
SI.sum();
}
}

View File

@ -0,0 +1,12 @@
public class StaticNesting {
public static void main(String[] args) {
StaticNesting sn= new StaticNesting();
WhatsIt w= new WhatsIt();
}
static class WhatsIt {
private int value;
public WhatsIt() {
value= 0;
}
}
}

View File

@ -0,0 +1,42 @@
public class Switch1 {
public static void main(String[] args) {
Switch1 s1= new Switch1();
s1.testOne(args);
s1.testTwo(args);
s1.testThree(args);
}
public void testOne(String[] args) {
char ch;
switch(Integer.parseInt(args[0])) {
case 0: ch=Character.forDigit(Integer.parseInt(args[1]), 10); break;
case 1: ch=Character.forDigit(Integer.parseInt(args[2]), 10); break;
case 2: ch=Character.forDigit(Integer.parseInt(args[3]), 10); break;
case 3: ch=Character.forDigit(Integer.parseInt(args[4]), 10); break;
default: ch= '?'; break;
}
System.out.println(ch);
}
public char testTwo(String[] args) {
switch(Integer.parseInt(args[0])) {
case 0: return Character.forDigit(Integer.parseInt(args[1]), 10);
case 1: return Character.forDigit(Integer.parseInt(args[2]), 10);
case 2: return Character.forDigit(Integer.parseInt(args[3]), 10);
case 3: return Character.forDigit(Integer.parseInt(args[4]), 10);
default: return '?';
}
}
public void testThree(String[] args) {
char ch = '?';
switch(Integer.parseInt(args[0])) {
case 0: ch=Character.forDigit(Integer.parseInt(args[1]), 10); break;
case 1: ch=Character.forDigit(Integer.parseInt(args[2]), 10); break;
case 2: ch=Character.forDigit(Integer.parseInt(args[3]), 10); break;
case 3: ch=Character.forDigit(Integer.parseInt(args[4]), 10); break;
}
System.out.println(ch);
}
}

View File

@ -0,0 +1,26 @@
class R implements Runnable {
public int i;
R(int i) { this.i = i; }
public void run() {
return;
}
}
public class Thread1 {
private void test() {
R r = new R(2);
Thread t = new Thread(r);
t.start();
}
public static void main(String[] a) {
(new Thread1()).test();
}
}

View File

@ -0,0 +1,40 @@
public class TwoClasses {
private int value;
private float fval= 3.14F;
public TwoClasses(int x) {
value = x;
}
public TwoClasses() {
this(0);
}
public static void doStuff(int N) {
int prod= 1;
TwoClasses tc= new TwoClasses();
tc.instanceMethod1();
for(int j=0; j < N; j++)
prod *= j;
}
public static void main(String[] args) {
int sum= 0;
for(int i=0; i < 10; i++) {
sum += i;
}
TwoClasses.doStuff(sum);
}
public void instanceMethod1() {
instanceMethod2();
}
public void instanceMethod2() {
Bar b= Bar.create('a');
}
}
class Bar {
private final char fChar;
private Bar(char c) {
fChar= c;
}
public static Bar create(char c) {
return new Bar(c);
}
}

View File

@ -0,0 +1,24 @@
public class WelcomeInitializers {
int x;
int y = 6;
static int sX;
static int sY = 6;
{
x = 7 / 7;
}
static {
sX = 9 / 3;
}
public WelcomeInitializers() {
}
public void hey() {}
public static void main(String args[]) {
new WelcomeInitializers().hey();
}
}

View File

@ -0,0 +1,20 @@
public class WhileTest1 {
public static void main(String[] args) {
WhileTest1 wt1= new WhileTest1();
int x= 235834;
boolean stop= false;
while (!stop) {
x += 3;
x ^= 0xAAAA5555;
stop= (x & 0x1248) != 0;
}
while (!stop) {
x += 3;
if (x < 7) continue;
x ^= 0xAAAA5555;
stop= (x & 0x1248) != 0;
}
}
}

View File

@ -0,0 +1,50 @@
package com.ibm.wala.cast.java.test.data;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends Plugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.ibm.wala.cast.java.test.data";
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}

View File

@ -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
cd $MY_DIR
rm -rf $TMP
fi