repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
WALA
WALA-master/cast/java/test/data/src/test/java/AnonymousClass.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ public class AnonymousClass { private interface Foo { int getValue(); int getValueBase(); } public static void main(String[] args) { final Integer base = Integer.valueOf(6); Foo f= new Foo() { int value = 3; @Override public int getValue() { return value; } @Override public int getValueBase() { return value - base; } }; System.out.println(f.getValue()); System.out.println(f.getValueBase()); new AnonymousClass().method(); } public void method() { final Integer base = Integer.valueOf(7); abstract class FooImpl implements Foo { int y; @Override public abstract int getValue(); FooImpl(int _y) { y = _y; } @Override public int getValueBase() { return y + getValue() - base; } } Foo f= new FooImpl(-4) { @Override public int getValue() { return 7; } }; System.out.println(f.getValue()); System.out.println(f.getValueBase()); } }
1,389
19.746269
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Array1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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 i : ary) { sum += i; } } }
650
20.7
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/ArrayLiteral1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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", 55, new int[] { 3, 1, 4 } }; } }
621
33.555556
73
java
WALA
WALA-master/cast/java/test/data/src/test/java/ArrayLiteral2.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ public class ArrayLiteral2 { public static void main(String[] args) { ArrayLiteral2 al2= new ArrayLiteral2(); int[] x= {}; int[] y= { 1, 2, 3, 4 }; } }
538
28.944444
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Breaks.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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 (String aClass : classes) { if (aClass == objectClass) break objectClassCheck; } return; } if (objectClass == null) { reference.classes = null; } } public static void main(String[] args) { (new Breaks()).testBreakFromIf("whatever", new Ref(args)); } }
1,102
22.978261
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/CastFromNull.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ public class CastFromNull { public static void main(String args[]) { new CastFromNull(); Object x = (Object) null; String y = (String) null; } }
536
28.833333
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Casts.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; } }
930
23.5
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/DefaultConstructors.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; } }
1,197
15.638889
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/DominanceFrontierCase.java
public class DominanceFrontierCase { public static void main(String[] args) { (new DominanceFrontierCase()).convert(3); } public int convert(Integer i) { switch (i.intValue()) { default: return 1; } } }
257
17.428571
45
java
WALA
WALA-master/cast/java/test/data/src/test/java/Exception1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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"); } }
1,059
20.632653
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Exception2.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; 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); } } } } }
1,336
23.309091
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Exclusions.java
public class Exclusions { public static class Included { private final int f; private Included(int f) { this.f = f; } public int doit() { return f + 1; } } public static class Excluded { private final int f; private Excluded(int f) { this.f = f; } public int doit() { return f + 1; } } public void run(String[] args) { int i = new Included(5).doit(); } public static void main(String[] args) { new Exclusions().run(args); } }
540
13.621622
42
java
WALA
WALA-master/cast/java/test/data/src/test/java/Finally1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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"); } }
939
25.111111
74
java
WALA
WALA-master/cast/java/test/data/src/test/java/Finally2.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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"); } }
1,021
24.55
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/FunkySupers.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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 { @Override 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!!!
925
22.15
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Inheritance1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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 { @Override public void foo() { super.foo(); } @Override public String bar(int x) { return Integer.toHexString(x); } }
900
19.953488
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/InheritedField.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; } }
688
21.225806
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/InnerClass.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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(); } } } }
1,087
17.133333
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/InnerClassA.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ // 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 } } } }
3,386
23.904412
134
java
WALA
WALA-master/cast/java/test/data/src/test/java/InnerClassLexicalReads.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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] */ @Override 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); } }
2,364
38.416667
174
java
WALA
WALA-master/cast/java/test/data/src/test/java/InnerClassSuper.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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(); } } }
737
23.6
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/InterfaceTest1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; } @Override public char getValue() { return fValue; } }
771
21.705882
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/LexicalAccessOfMethodVariablesFromAnonymousClass.java
public class LexicalAccessOfMethodVariablesFromAnonymousClass { public static void main(String[] args) { new LexicalAccessOfMethodVariablesFromAnonymousClass().run(""); } public void run(final String var) { Object o = new Object() { @Override public int hashCode() { try { return var.hashCode(); } catch (Exception e) { String s = var; } return 0; } }; o.hashCode(); var.hashCode(); } }
477
18.12
67
java
WALA
WALA-master/cast/java/test/data/src/test/java/LocalClass.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ public class LocalClass { public static void main(String[] args) { final Integer base = 6; class Foo { int value; public Foo(int v) { value= v; } public int getValue() { return value; } public int getValueBase() { return value - base; } } Foo f= new Foo(3); System.out.println(f.getValue()); System.out.println(f.getValueBase()); (new LocalClass()).method(); } public void method() { final Integer base = 6; class Foo { int value; public Foo(int v) { value= v; } public int getValue() { return value; } public int getValueBase() { return value - base; } } Foo f= new Foo(3); System.out.println(f.getValue()); System.out.println(f.getValueBase()); } }
1,101
24.045455
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/MiniaturList.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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)); } }
1,346
20.046875
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/MiniaturSliceBug.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ abstract class PrimitiveWrapper { /** * Sets the integer representation of the underlying primitive * to the given value. */ 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} */ @Override abstract public boolean equals(Object o); } final class IntWrapper extends PrimitiveWrapper { private int val; /** * Constructs a wrapper for the given int. */ public IntWrapper(int val) { this.val = val; } @Override public int intValue() { return val; } @Override public void setIntValue(int i) { this.val = i; } @Override 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)); } }
1,608
20.743243
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Monitor.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ public class Monitor { int i = 0; public Monitor() { } public void incr() { synchronized(this) { i++; } } public static void main(String[] a) { new Monitor().incr(); } }
562
24.590909
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Monitor2.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ public class Monitor2 { private static boolean randomIsolate() { return Math.random() > .5; } int i = 0; public Monitor2() { } public void incr() { synchronized(this) { i++; } } public static void main(String[] a) { randomIsolate(); new Monitor2().incr(); } }
667
23.740741
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/NullArrayInit.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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} }; } }
793
29.538462
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/PeekErrorCase.java
public class PeekErrorCase { public static void main(String[] args) { (new PeekErrorCase()).start(); } public int start() { System.out.println(""); // Any method invocation here //noinspection ConditionalExpressionWithIdenticalBranches,ConstantConditionalExpression final int num = true ? 1 : 1; // has to be a ternary? Object o = new Object() { public int hashCode() { return num; // must use num in this function } }; return o.hashCode(); } }
504
24.25
91
java
WALA
WALA-master/cast/java/test/data/src/test/java/QualifiedStatic.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; }
586
26.952381
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Scoping1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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); } } }
586
23.458333
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Scoping2.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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); } } }
728
24.137931
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Simple1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; } }
999
22.809524
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/SimpleCalls.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ interface ISimpleCalls { void helloWorld(); } public class SimpleCalls implements ISimpleCalls { @Override 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; } }
857
23.514286
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/StaticInitializers.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ public class StaticInitializers { static class X { int x; int y; int sum() { return x+y; } int diff() { //noinspection UnnecessaryUnaryMinus return x+-y; } } private static X x = new X(); private static X y; static { y = new X(); } private int sum() { return x.sum() * y.diff(); } public static void main(String[] args) { StaticInitializers SI = new StaticInitializers(); SI.sum(); } }
846
18.697674
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/StaticNesting.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; } } }
615
25.782609
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Switch1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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); } }
1,828
33.509434
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/Thread1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ class R implements Runnable { public int i; R(int i) { this.i = i; } @Override 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(); } }
705
17.102564
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/TwoClasses.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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); } }
1,126
21.098039
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/WelcomeInitializers.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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(); } }
664
18
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/WhileTest1.java
/* * Copyright (c) 2002 - 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ 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; } } }
725
22.419355
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/alreadywalaunittests/InnerClassAA.java
/* * 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 InnerClassAA { int a_x; public static void main(String args[]) { // prints out 5 5 9 7 5 5 7 5 7 5 InnerClassAA a = new InnerClassAA(); a.doAllThis(); } public void doAllThis() { InnerClassAA 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(InnerClassAA.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 } } } }
5,053
28.555556
134
java
WALA
WALA-master/cast/java/test/data/src/test/java/alreadywalaunittests/InnerClassSuperA.java
/* * 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 InnerClassSuperA { 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 InnerClassSuperA { class SubInner { public SubInner() { InnerClassSuperA.SuperOuter so = new InnerClassSuperA.SuperOuter(); so.test(); } } }
2,314
38.237288
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/bugfixes/DoWhileInCase.java
package bugfixes; public class DoWhileInCase { static int x = 3; public static void main(String[] args) { new DoWhileInCase().run(args); } public void run(String[] args) { switch(x) { case 1: do { System.out.println("Problem"); x ++; } while (x < 3); break; default: System.out.println("Default"); } } }
376
16.952381
42
java
WALA
WALA-master/cast/java/test/data/src/test/java/bugfixes/VarDeclInSwitch.java
/* * 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 { private int y = 7; public static void main(String args[]) { new VarDeclInSwitch().run(args); } public void run(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; } } }
2,285
34.71875
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/QualifiedNames.java
/* * 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; 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() {} }
2,919
39.555556
86
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/SimpleNames.java
/* * 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() { @Override 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(); } }
2,788
32.60241
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/ArraysAndSuch.java
/* * 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<? extends Object[]> 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]; } }
2,927
36.063291
73
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/ConstructorsAndInitializers.java
/* * 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; } @Override 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(); } }
2,892
25.541284
142
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/CopyOfLoopsAndLabels.java
/* * 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; } }
2,084
42.4375
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/DefaultCtorInitializerTest.java
/* * 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; } }
2,277
37.610169
82
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/InnerClasses.java
/* * 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 { @Override public int hashCode() { return x; } } return new FooBar(); } static Object anonymousCoward() { final int x = 5; return new Object() { @Override 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") { @Override 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 //noinspection UnnecessaryUnaryMinus,UnaryPlus 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. } } }
4,710
29.006369
104
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/LoopsAndLabels.java
/* * 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: ; } }
3,207
28.431193
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/MethodMadness.java
/* * 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; } @Override 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(); } }
4,178
32.432
110
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/MiniaturList2.java
/* * 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 MiniaturList2 { public static void main(String[] args) { int a; for ( ;; ) { break; } } }
2,129
41.6
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/Misc.java
/* * 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; } } } }
2,307
38.118644
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/foo/bar/hello/world/SwitchCase.java
/* * 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"); } } }
2,441
33.394366
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/Annotations.java
/* * Copyright (c) 2013 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ package javaonepointfive; @interface TestAnnotation { String doSomething(); int count(); String date(); int[] stuff(); } @interface AnotherTestAnnotation { String value(); } @AnotherTestAnnotation("string") @TestAnnotation (doSomething="The class", count=-1, date="09-09-2001", stuff={0,1}) public class Annotations { @TestAnnotation (doSomething="What to do", count=1, date="09-09-2005", stuff={}) public int mymethod() { @AnotherTestAnnotation("i") int i = 0; return i; } @TestAnnotation (doSomething="What not to do", count=0, date="12-14-2010", stuff={1,2,3,4,5}) public static void main(String[] args) { (new Annotations()).mymethod(); } }
1,042
25.075
94
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/AnonGeneNullarySimple.java
/* * 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 { interface Ops<E> { E nullary(); } static class StrTripler implements Ops<String> { @Override 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); } }
2,475
35.955224
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/AnonymousGenerics.java
/* * 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 { interface Ops<E> { E nullary(); 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. @Override public String unary(String x) { return x + x + x; } @Override 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<>() { @Override public String unary(String x) { return x+x+x+x; } @Override 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<String> hack = ops; hack.unary("whatever"); hack.nullary(); hack = strQuadrupler; hack.unary("whatever"); hack.nullary(); } }
3,279
31.8
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/BasicsGenerics.java
/* * 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<>(); static ArrayList<Integer> 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(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<String> s1 = strs; for (String rrr : s1) { 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); } }
3,537
30.309735
87
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/Cocovariant.java
/* * 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 { @Override B foo(String x) { return null; } } static class C extends B { @Override 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(""); } }
2,734
36.465753
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/CustomGenericsAndFields.java
/* * 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; @Override public Q bar(Q a, Q b) { x = a; if (b.hashCode() == a.hashCode() || b.toString().equals(a.toString())) return a; return b; } @Override public Q foo() { return x; } } class ConcreteGeneric2<Q> extends ConcreteGeneric<Q> { Q y; public void setFoo(Q a) { y = a; } @Override 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<>(); 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<>(); 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<>("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); } }
4,119
29.518519
112
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/EnumSwitch.java
/* * 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())); } }
2,838
31.632184
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/ExplicitBoxingTest.java
/* * 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 = Integer.valueOf(5+6); Integer aa = Integer.valueOf(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); } }
2,417
36.78125
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/GenericArrays.java
/* * 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<>(); li.add(3); oa[1] = li; // correct String s = (String) lsa[1].get(0); // run time error, but cast is explicit } }
2,411
39.881356
76
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/GenericMemberClasses.java
/* * 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; @Override public boolean hasNext() { return ( localChangeID == 5 ); } @Override public T next() { localChangeID = 5; return x; } @Override public void remove() { } } public static void main(String args[]) { (new GenericMemberClasses<>()).doit(); } private void doit() { A a = new A(); while (a.hasNext()) { Object x = a.next(); a.remove(); System.out.println(x); } } }
2,598
31.898734
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/GenericSuperSink.java
/* * 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<>(); cs.add("hello"); sink = new ArrayList<Object>(); sink.add(cs.iterator().next()); System.out.println(sink); sink = new ArrayList<>(); sink.add(cs.iterator().next()); System.out.println(sink); } }
2,434
37.650794
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/MethodGenerics.java
/* * 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 array[] = new String[] { "coucou monde", "ciao mondo", "guten tag welt", "hola mundo", "shalom olam" }; fromArrayToCollection(array, list); System.out.println(list); foo("whatever", "whatever"); } }
2,572
38.584615
112
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/MoreOverriddenGenerics.java
/* * 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> { @Override public Number get() { return super.get(); } } class SubSub extends Sub { @Override public Long get() { return 6L; } } 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(); } }
2,613
30.493976
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/NotSoSimpleEnums.java
/* * 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") { @Override public Direction getOpposite() { return SOUTH; }}, EAST("est") { @Override public Direction getOpposite() { return WEST; }}, SOUTH("sud") { @Override public Direction getOpposite() { return NORTH; }}, WEST("ouest") { @Override 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); } } }
2,905
36.74026
95
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/OverridesOnePointFour.java
/* * 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 { interface Super { Number get(); } static class Sub implements Super { @Override public Long get() { return 6L; } } public static void main(String args[]) { (new OverridesOnePointFour()).doit(); } private void doit() { Super sup = new Sub(); Number x = sup.get(); System.out.println(x); } }
2,311
35.698413
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/SimpleEnums.java
/* * 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 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); } } }
2,327
37.163934
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/SimpleEnums2.java
/* * 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); // } }
3,060
34.183908
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/TypeInferencePrimAndStringOp.java
/* * Copyright (c) 2013 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ package javaonepointfive; public class TypeInferencePrimAndStringOp { public static void main(String[] args) { int a = 2; String result = "a" + a; } }
533
25.7
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/Varargs.java
/* * 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 (Object o : foo) System.out.println(o); 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"); } }
2,838
38.430556
109
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/VarargsCovariant.java
/* * 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 { @Override 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); } }
2,417
34.043478
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/VarargsOverriding.java
/* * 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 { @Override 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"); } }
3,059
29.6
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointfive/Wildcards.java
/* * 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<>(); e.add("hello"); e.add("goodbye"); printCollection(e); printCollection1(e); printCollection2(e); ArrayList<Integer> e3 = new ArrayList<>(); e3.add(123); e3.add(42); printCollection(e3); printCollection1(e3); } }
2,823
33.439024
72
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointseven/BinaryLiterals.java
package javaonepointseven; /** * @author Linghui Luo * @see <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/binary-literals.html">Java 7 docs</a> */ public class BinaryLiterals { public static final int[] phases = { 0b00110001, 0b01100010, 0b11000100, 0b10001001, 0b00010011, 0b00100110, 0b01001100, 0b10011000 }; // An 8-bit 'byte' value: private byte aByte = (byte) 0b00100001; // A 16-bit 'short' value: private short aShort = (short) 0b1010000101000101; // Some 32-bit 'int' values: private int anInt1 = 0b10100001010001011010000101000101; private int anInt2 = 0b101; private int anInt3 = 0B101; // The B can be upper or lower case. // A 64-bit 'long' value. Note the "L" suffix: private long aLong = 0b1010000101000101101000010100010110100001010001011010000101000101L; public static void main(String[] args) { BinaryLiterals x = new BinaryLiterals(); x.decodeInstruction(463527, x.new State(11)); } public State decodeInstruction(int instruction, State state) { if ((instruction & 0b11100000) == 0b00000000) { final int register = instruction & 0b00001111; switch (instruction & 0b11110000) { case 0b00000000: return state.nop(); case 0b00010000: return state.copyAccumTo(register); case 0b00100000: return state.addToAccum(register); case 0b00110000: return state.subFromAccum(register); case 0b01000000: return state.multiplyAccumBy(register); case 0b01010000: return state.divideAccumBy(register); case 0b01100000: return state.setAccumFrom(register); case 0b01110000: return state.returnFromCall(); default: throw new IllegalArgumentException(); } } else { final int address = instruction & 0b00011111; switch (instruction & 0b11100000) { case 0b00100000: return state.jumpTo(address); case 0b01000100: return state.jumpIfAccumZeroTo(address); case 0b01001000: return state.jumpIfAccumNonzeroTo(address); case 0b01100000: return state.setAccumFromMemory(address); case 0b10100000: return state.writeAccumToMemory(address); case 0b11000000: return state.callTo(address); default: throw new IllegalArgumentException(); } } } class State { int state = 0; public State(int s) { this.state = s; } public State nop() { return null; } public State copyAccumTo(int register) { return new State(1); } public State addToAccum(int register) { return new State(2); } public State subFromAccum(int register) { return new State(3); } public State multiplyAccumBy(int register) { return new State(4); } public State divideAccumBy(int register) { return new State(5); } public State setAccumFrom(int register) { return new State(6); } public State returnFromCall() { return new State(7); } public State jumpTo(int address) { return new State(8); } public State jumpIfAccumZeroTo(int address) { return new State(9); } public State jumpIfAccumNonzeroTo(int address) { return new State(10); } public State setAccumFromMemory(int address) { return new State(11); } public State writeAccumToMemory(int address) { return new State(12); } public State callTo(int address) { return new State(13); } } }
3,639
24.815603
118
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointseven/CatchMultipleExceptionTypes.java
package javaonepointseven; /** * @author Linghui Luo * @see <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html">Java 7 docs</a> */ public class CatchMultipleExceptionTypes { public static void main(String[] args) { new CatchMultipleExceptionTypes().test(-1, new int[] {0, 1}); } public void test(int i, int[] arr) { try { int num = 100; int a = 100 / i; int b = arr[i]; System.out.println(a + b); } catch (ArithmeticException | IndexOutOfBoundsException ex) { throw ex; } } }
572
22.875
117
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointseven/StringsInSwitch.java
package javaonepointseven; /** * @author Linghui Luo * @see <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html">Java 7 docs</a> */ public class StringsInSwitch { public static void main(String[] args) { new StringsInSwitch().getTypeOfDayWithSwitchStatement("Tuesday"); } public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay; switch (dayOfWeekArg) { case "Monday": typeOfDay = "Start of work week"; break; case "Tuesday": case "Wednesday": case "Thursday": typeOfDay = "Midweek"; break; case "Friday": typeOfDay = "End of work week"; break; case "Saturday": case "Sunday": typeOfDay = "Weekend"; break; default: throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg); } return typeOfDay; } }
942
25.194444
117
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointseven/TryWithResourcesStatement.java
package javaonepointseven; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @author Linghui Luo * @see <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html">Java 7 docs</a> */ public class TryWithResourcesStatement { public static void main(String[] args) throws IOException, SQLException { readFirstLineFromFile(args[0]); viewTable(null); TryWithResourcesStatement x = new TryWithResourcesStatement(); } public static String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.readLine(); } } public static void viewTable(Connection con) throws SQLException { String query = "select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from COFFEES"; try (Statement stmt = con.createStatement()) { ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String coffeeName = rs.getString("COF_NAME"); int supplierID = rs.getInt("SUP_ID"); float price = rs.getFloat("PRICE"); int sales = rs.getInt("SALES"); int total = rs.getInt("TOTAL"); System.out.println( coffeeName + ", " + supplierID + ", " + price + ", " + sales + ", " + total); } rs.close(); } catch (SQLException e) { e.printStackTrace(); } } }
1,525
29.52
121
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointseven/TypeInferenceforGenericInstanceCreation.java
package javaonepointseven; import java.util.ArrayList; import java.util.List; /** * @author Linghui Luo * @see * <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/type-inference-generic-instance-creation.html">Java 7 docs</a> */ public class TypeInferenceforGenericInstanceCreation { class MyClass<X> { X a; <T> MyClass(T t) { System.out.println("constructor"); } } public void test() { List<String> list = new ArrayList<>(); list.add("A"); list.addAll(new ArrayList<>()); List<? extends String> list2 = new ArrayList<>(); list.addAll(list2); MyClass<Integer> myObject = new MyClass<>(""); } public static void main(String[] args) { new TypeInferenceforGenericInstanceCreation().test(); } }
787
22.176471
142
java
WALA
WALA-master/cast/java/test/data/src/test/java/javaonepointseven/UnderscoresInNumericLiterals.java
package javaonepointseven; /** * @author Linghui Luo * @see <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html">Java 7 docs</a> */ public class UnderscoresInNumericLiterals { public void test() { long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumber = 999_99_9999L; float pi = 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BABE; long maxLong = 0x7fff_ffff_ffff_ffffL; byte nybbles = 0b0010_0101; long bytes = 0b11010010_01101001_10010100_10010010; } public static void main(String[] args) { new UnderscoresInNumericLiterals().test(); } }
674
26
123
java
WALA
WALA-master/cast/java/test/data/src/test/java/p/NonPrimaryTopLevel.java
/* * Copyright (c) 2013 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ package p; public class NonPrimaryTopLevel { public static void main(String[] args) { NonPrimaryTopLevel nptl= new NonPrimaryTopLevel(); Foo f = new Foo(); } } class Foo { }
559
23.347826
72
java
WALA
WALA-master/cast/js/html/nu_validator/src/main/java/com/ibm/wala/cast/js/html/nu_validator/NuValidatorHtmlParser.java
/* * Copyright (c) 2002 - 2011 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ package com.ibm.wala.cast.js.html.nu_validator; import com.ibm.wala.cast.js.html.IHtmlCallback; import com.ibm.wala.cast.js.html.IHtmlParser; import com.ibm.wala.cast.js.html.ITag; import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position; import com.ibm.wala.cast.tree.impl.LineNumberPosition; import com.ibm.wala.util.collections.Pair; import java.io.IOException; import java.io.InputStream; import java.io.LineNumberReader; import java.io.Reader; import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.util.AbstractMap; import java.util.ArrayDeque; import java.util.HashSet; import java.util.Map; import java.util.Set; import nu.validator.htmlparser.common.XmlViolationPolicy; import nu.validator.htmlparser.sax.HtmlParser; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; public class NuValidatorHtmlParser implements IHtmlParser { @Override public void parse( final URL url, final Reader reader, final IHtmlCallback handler, final String fileName) { URL xx = null; try { xx = new URL("file://" + fileName); } catch (MalformedURLException e1) { e1.printStackTrace(); } final URL localFileName = xx; HtmlParser parser = new HtmlParser(); parser.setXmlPolicy(XmlViolationPolicy.ALLOW); parser.setContentHandler( new ContentHandler() { private Locator locator; private final ArrayDeque<ITag> tags = new ArrayDeque<>(); private int countLines(char[] ch, int start, int length) { LineNumberReader r = new LineNumberReader(new StringReader(new String(ch, start, length))); try { while (r.read() > -1) ; } catch (IOException e) { throw new RuntimeException("cannot read from string", e); } return r.getLineNumber(); } @Override public void setDocumentLocator(Locator locator) { this.locator = locator; } @Override public void startElement( String uri, final String localName, String qName, final Attributes atts) throws SAXException { final Position line = new LineNumberPosition(url, localFileName, locator.getLineNumber()); tags.push( new ITag() { @Override public String getName() { return localName; } @Override public Pair<String, Position> getAttributeByName(String name) { if (atts.getValue(name) != null) { return Pair.make(atts.getValue(name), line); } else { return null; } } @Override public Map<String, Pair<String, Position>> getAllAttributes() { return new AbstractMap<>() { private Set<Map.Entry<String, Pair<String, Position>>> es = null; @Override public Set<java.util.Map.Entry<String, Pair<String, Position>>> entrySet() { if (es == null) { es = new HashSet<>(); for (int i = 0; i < atts.getLength(); i++) { final int index = i; es.add( new Map.Entry<>() { @Override public String getKey() { return atts.getLocalName(index).toLowerCase(); } @Override public Pair<String, Position> getValue() { if (atts.getValue(index) != null) { return Pair.make(atts.getValue(index), line); } else { return null; } } @Override public Pair<String, Position> setValue( Pair<String, Position> value) { throw new UnsupportedOperationException(); } }); } } return es; } }; } @Override public Position getElementPosition() { return line; } @Override public Position getContentPosition() { return line; } }); handler.handleStartTag(tags.peek()); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { handler.handleEndTag(tags.pop()); } @Override public void characters(char[] ch, int start, int length) throws SAXException { handler.handleText( new LineNumberPosition( url, localFileName, locator.getLineNumber() - countLines(ch, start, length)), new String(ch, start, length)); } @Override public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { handler.handleText( new LineNumberPosition(url, localFileName, locator.getLineNumber()), new String(ch, start, length)); } @Override public void startDocument() throws SAXException { // do nothing } @Override public void endDocument() throws SAXException { // do nothing } @Override public void startPrefixMapping(String prefix, String uri) throws SAXException { // do nothing } @Override public void endPrefixMapping(String prefix) throws SAXException { // do nothing } @Override public void processingInstruction(String target, String data) throws SAXException { // do nothing } @Override public void skippedEntity(String name) throws SAXException { // do nothing } }); try { parser.parse( new InputSource( new InputStream() { @Override public int read() throws IOException { int v; do { v = reader.read(); } while (v == '\r'); return v; } })); } catch (IOException | SAXException e) { assert false : e.toString(); } } }
7,600
33.238739
98
java
WALA
WALA-master/cast/js/html/nu_validator/src/test/java/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShapeRhinoNu.java
/* * Copyright (c) 2013 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ package com.ibm.wala.cast.js.test; import com.ibm.wala.cast.js.html.IHtmlParser; import com.ibm.wala.cast.js.html.nu_validator.NuValidatorHtmlParser; public class TestSimplePageCallGraphShapeRhinoNu extends TestSimplePageCallGraphShapeRhino { @Override protected IHtmlParser getParser() { return new NuValidatorHtmlParser(); } }
710
29.913043
92
java
WALA
WALA-master/cast/js/nodejs/src/main/java/com/ibm/wala/cast/js/nodejs/NodejsCallGraphBuilderUtil.java
/* * Copyright (c) 2002 - 2016 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Brian Pfretzschner - initial implementation */ package com.ibm.wala.cast.js.nodejs; import com.ibm.wala.cast.ipa.callgraph.CAstAnalysisScope; import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil; import com.ibm.wala.cast.ipa.callgraph.StandardFunctionTargetSelector; import com.ibm.wala.cast.ir.ssa.AstIRFactory; import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions; import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil; import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder; import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptEntryPoints; import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector; import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory; import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory; import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory; import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.Language; import com.ibm.wala.classLoader.Module; import com.ibm.wala.classLoader.SourceFileModule; import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl; import com.ibm.wala.ipa.callgraph.ContextSelector; import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.IAnalysisCacheView; import com.ibm.wala.ipa.callgraph.MethodTargetSelector; import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder; import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys; import com.ibm.wala.ipa.cha.ClassHierarchyFactory; import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ssa.IRFactory; import com.ibm.wala.util.WalaException; import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.Collections; /** @author Brian Pfretzschner &lt;[email protected]&gt; */ public class NodejsCallGraphBuilderUtil extends JSCallGraphUtil { public static PropagationCallGraphBuilder makeCGBuilder(File mainFile) throws IOException, IllegalArgumentException, WalaException { return makeCGBuilder(mainFile.getParentFile(), mainFile); } public static PropagationCallGraphBuilder makeCGBuilder(File workingDir, File mainFile) throws IOException, IllegalArgumentException, WalaException { JavaScriptTranslatorFactory translatorFactory = new CAstRhinoTranslatorFactory(); JSCallGraphUtil.setTranslatorFactory(translatorFactory); Language language = JavaScriptLoader.JS; Collection<Language> languages = Collections.singleton(language); IRFactory<IMethod> irFactory = new AstIRFactory.AstDefaultIRFactory<>(); IAnalysisCacheView cache = new AnalysisCacheImpl(irFactory); JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory, null); SourceFileModule mainSourceModule = CAstCallGraphUtil.makeSourceModule(mainFile.toURI().toURL(), mainFile.getName()); String mainFileClassName = NodejsRequiredSourceModule.convertFileToClassName(workingDir, mainFile); Module[] files = new Module[] { JSCallGraphUtil.getPrologueFile("prologue.js"), JSCallGraphUtil.getPrologueFile("extended-prologue.js"), new NodejsRequiredSourceModule(mainFileClassName, mainFile, mainSourceModule) }; CAstAnalysisScope scope = new CAstAnalysisScope(files, loaders, languages); IClassHierarchy cha = ClassHierarchyFactory.make(scope, loaders, language, null); com.ibm.wala.cast.util.Util.checkForFrontEndErrors(cha); // Make Script Roots Iterable<Entrypoint> roots = new JavaScriptEntryPoints(cha, loaders.getTheLoader()); // Make Options JSAnalysisOptions options = new JSAnalysisOptions(scope, roots); options.setUseConstantSpecificKeys(true); options.setUseStacksForLexicalScoping(true); options.setHandleCallApply(true); // Important to be able to identify what file are required options.setTraceStringConstants(true); com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha); MethodTargetSelector baseSelector = new StandardFunctionTargetSelector(cha, options.getMethodTargetSelector()); NodejsRequireTargetSelector requireTargetSelector = new NodejsRequireTargetSelector(workingDir, baseSelector); options.setSelector(requireTargetSelector); JSCFABuilder builder = new JSZeroOrOneXCFABuilder( cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS, true); // A little hacky, but the instance of RequireTargetSelector is required to build the // CallGraphBuilder // and the RequireTargetSelector also needs the CallGraphBuilder instance. requireTargetSelector.setCallGraphBuilder(builder); ContextSelector contextSelector = new PropertyNameContextSelector(cache, 2, builder.getContextSelector()); builder.setContextSelector(contextSelector); return builder; } }
5,278
42.991667
91
java
WALA
WALA-master/cast/js/nodejs/src/main/java/com/ibm/wala/cast/js/nodejs/NodejsRequireTargetSelector.java
/* * Copyright (c) 2002 - 2016 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Brian Pfretzschner - initial implementation */ package com.ibm.wala.cast.js.nodejs; import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil; import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.ssa.JavaScriptInvoke; import com.ibm.wala.cast.js.types.JavaScriptTypes; import com.ibm.wala.cast.types.AstMethodReference; import com.ibm.wala.classLoader.CallSiteReference; import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.SourceFileModule; import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.core.util.ssa.ClassLookupException; import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.MethodTargetSelector; import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey; import com.ibm.wala.ipa.callgraph.propagation.ConstantKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis; import com.ibm.wala.ipa.callgraph.propagation.PointerKey; import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder; import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; import com.ibm.wala.types.TypeReference; import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.intset.OrdinalSet; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.commons.io.FileUtils; import org.json.JSONObject; /** * This class is used by WALA internals to resolve to what functions a call could potentially * invoke. * * @author Brian Pfretzschner &lt;[email protected]&gt; */ public class NodejsRequireTargetSelector implements MethodTargetSelector { private final File rootDir; private final MethodTargetSelector base; private PropagationCallGraphBuilder builder; private final HashMap<String, IMethod> previouslyRequired = HashMapFactory.make(); public NodejsRequireTargetSelector(File rootDir, MethodTargetSelector base) { this.rootDir = rootDir; this.base = base; } public void setCallGraphBuilder(PropagationCallGraphBuilder builder) { this.builder = builder; } /** * Basic idea: If the called method is named "__WALA__require", it is most likely the * require-function mock from the module-wrapper. To figure out what file shall be required, * pointer analysis is used to identify strings that can flow into the require call. That file is * than loaded, wrapped into the module wrapper and returned as method that will be invoked. * Therefore, there will never be an call graph edge to the require function call, the require * function is replaced by the file that is included through the require call. * * <p>{@inheritDoc} */ @Override public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) { PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis(); JavaScriptLoader jsLoader = (JavaScriptLoader) builder.getClassHierarchy().getLoader(JavaScriptTypes.jsLoader); IMethod calledMethod = base.getCalleeTarget(caller, site, receiver); if (calledMethod != null && calledMethod.getDeclaringClass().toString().endsWith("/__WALA__require")) { JavaScriptInvoke callInstr = getInvokeInstruction(caller, site); Set<String> targets = getRequireTargets(pointerAnalysis, caller, callInstr); if (targets.size() == 0) { // There is no possible call target throw new RuntimeException("No require target found in method: " + caller.getMethod()); } for (String target : targets) { try { File workingDir = new File(receiver.getSourceFileName()).getParentFile(); SourceModule sourceModule = resolve(rootDir, workingDir, target); if (previouslyRequired.containsKey(sourceModule.getClassName())) { return previouslyRequired.get(sourceModule.getClassName()); } String className = 'L' + sourceModule.getClassName() + "/nodejsModule"; if (sourceModule instanceof NodejsRequiredSourceModule && ((NodejsRequiredSourceModule) sourceModule) .getFile() .toString() .endsWith(".json")) { className = 'L' + sourceModule.getClassName() + "/jsonModule"; } JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy(), jsLoader, sourceModule); IClass script = builder .getClassHierarchy() .lookupClass(TypeReference.findOrCreate(jsLoader.getReference(), className)); IMethod method = script.getMethod(AstMethodReference.fnSelector); previouslyRequired.put(sourceModule.getClassName(), method); return method; } catch (IOException e) { e.printStackTrace(); } } } return calledMethod; } private static JavaScriptInvoke getInvokeInstruction(CGNode caller, CallSiteReference site) { IR callerIR = caller.getIR(); SSAAbstractInvokeInstruction callInstrs[] = callerIR.getCalls(site); assert callInstrs.length == 1; return (JavaScriptInvoke) callInstrs[0]; } private Set<String> getRequireTargets( PointerAnalysis<InstanceKey> pointerAnalysis, CGNode caller, JavaScriptInvoke callInstr) { HashSet<String> set = HashSetFactory.make(); PointerKey pk = builder.getPointerKeyForLocal(caller, callInstr.getUse(2)); OrdinalSet<InstanceKey> instanceKeys = pointerAnalysis.getPointsToSet(pk); for (InstanceKey instanceKey : instanceKeys) { if (instanceKey instanceof ConstantKey<?>) { Object value = ((ConstantKey<?>) instanceKey).getValue(); if (value instanceof String) { set.add((String) value); } else { System.err.println("NodejsRequireTargetSelector: Unexpected value: " + value); return HashSetFactory.make(); } } else if (instanceKey instanceof ConcreteTypeKey) { // Cannot do anything with this information... } else { System.err.println( "NodejsRequireTargetSelector: Unexpected instanceKey: " + instanceKey.getClass() + " -- " + instanceKey); return HashSetFactory.make(); } } return set; } /** * Implements the Nodejs require.resolve algorithm, see <a * href="https://nodejs.org/api/modules.html#modules_all_together">Node.js documentation</a> * * <p>require(X) from module at path Y 1. If X is a core module, a. return the core module b. STOP * 2. If X begins with './' or '/' or '../' a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) 3. * LOAD_NODE_MODULES(X, dirname(Y)) 4. THROW "not found" * * @param dir Y in the pseudo algorithm * @param target X in the pseudo algorithm */ public static SourceFileModule resolve(File rootDir, File dir, String target) throws IOException { if (NodejsRequiredCoreModule.isCoreModule(target)) return NodejsRequiredCoreModule.make(target); if (target.startsWith("./") || target.startsWith("/") || target.startsWith("../")) { SourceFileModule module = loadAsFile(rootDir, new File(dir, target)); if (module != null) return module; module = loadAsDirectory(rootDir, new File(dir, target)); if (module != null) return module; } SourceFileModule module = loadNodeModules(rootDir, dir, target); if (module != null) return module; throw new ClassLookupException("Required module not found: " + target + " in " + dir); } /** * LOAD_AS_FILE(X) 1. If X is a file, load X as JavaScript text. STOP 2. If X.js is a file, load * X.js as JavaScript text. STOP 3. If X.json is a file, parse X.json to a JavaScript Object. STOP * 4. If X.node is a file, load X.node as binary addon. STOP */ private static SourceFileModule loadAsFile(File rootDir, File f) throws IOException { // 1. if (f.isFile()) return NodejsRequiredSourceModule.make(rootDir, f); // 2. File jsFile = new File(f + ".js"); if (jsFile.isFile()) return NodejsRequiredSourceModule.make(rootDir, jsFile); // 3. File jsonFile = new File(f + ".json"); if (jsonFile.isFile()) return NodejsRequiredSourceModule.make(rootDir, jsonFile); // Skip 4. step return null; } /** * LOAD_AS_DIRECTORY(X) 1. If X/package.json is a file, a. Parse X/package.json, and look for * "main" field. b. let M = X + (json main field) c. LOAD_AS_FILE(M) 2. If X/index.js is a file, * load X/index.js as JavaScript text. STOP 3. If X/index.json is a file, parse X/index.json to a * JavaScript object. STOP 4. If X/index.node is a file, load X/index.node as binary addon. STOP */ private static SourceFileModule loadAsDirectory(File rootDir, File d) throws IOException { // 1. File packageJsonFile = new File(d, "package.json"); if (packageJsonFile.isFile()) { // 1.a. String packageJsonContent = FileUtils.readFileToString(packageJsonFile, (Charset) null); JSONObject packageJson = new JSONObject(packageJsonContent); if (packageJson.has("main")) { String mainFileName = packageJson.getString("main"); // 1.b. File mainFile = new File(d, mainFileName); // 1.c. return loadAsFile(rootDir, mainFile); } } // 2. File jsFile = new File(d, "index.js"); if (jsFile.isFile()) return NodejsRequiredSourceModule.make(rootDir, jsFile); // 3. File jsonFile = new File(d, "index.json"); if (jsonFile.isFile()) return NodejsRequiredSourceModule.make(rootDir, jsonFile); // Skip 4. step return null; } /** * LOAD_NODE_MODULES(X, START) 1. let DIRS=NODE_MODULES_PATHS(START) 2. for each DIR in DIRS: a. * LOAD_AS_FILE(DIR/X) b. LOAD_AS_DIRECTORY(DIR/X) */ private static SourceFileModule loadNodeModules(File rootDir, File d, String target) throws IOException { List<File> dirs = nodeModulePaths(rootDir, d); for (File dir : dirs) { SourceFileModule module = loadAsFile(rootDir, new File(dir, target)); if (module != null) return module; module = loadAsDirectory(rootDir, new File(dir, target)); if (module != null) return module; } return null; } /** * NODE_MODULES_PATHS(START) 1. let PARTS = path split(START) 2. let I = count of PARTS - 1 3. let * DIRS = [] 4. while I &gt;= 0, a. if PARTS[I] = "node_modules" CONTINUE b. DIR = path * join(PARTS[0 .. I] + "node_modules") c. DIRS = DIRS + DIR d. let I = I - 1 5. return DIRS */ private static List<File> nodeModulePaths(File rootDir, File d) throws IOException { List<File> dirs = new ArrayList<>(); while (d.getCanonicalPath().startsWith(rootDir.getCanonicalPath()) && d.toPath().getNameCount() > 0) { // 4.a. if (!d.getName().equals("node_modules")) { // 4.b. and 4.c. dirs.add(new File(d, "node_modules")); } // 4.d. d = d.getParentFile(); } return dirs; } }
11,619
37.476821
100
java
WALA
WALA-master/cast/js/nodejs/src/main/java/com/ibm/wala/cast/js/nodejs/NodejsRequiredCoreModule.java
/* * Copyright (c) 2002 - 2016 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Brian Pfretzschner - initial implementation */ package com.ibm.wala.cast.js.nodejs; import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil; import com.ibm.wala.classLoader.SourceFileModule; import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.io.TemporaryFile; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.util.Arrays; import java.util.Map; import java.util.Set; import org.apache.commons.io.FilenameUtils; /** @author Brian Pfretzschner &lt;[email protected]&gt; */ public class NodejsRequiredCoreModule extends NodejsRequiredSourceModule { /** * Core modules list for Nodejs v6.2.2 * * @see <a href="https://github.com/nodejs/node/blob/v6.2.2/lib/internal/module.js">module.js</a> */ private static final Set<String> CORE_MODULES = HashSetFactory.make( Arrays.asList( "assert", "buffer", "child_process", "cluster", "crypto", "dgram", "dns", "domain", "events", "fs", "http", "https", "net", "os", "path", "punycode", "querystring", "readline", "repl", "stream", "string_decoder", "tls", "tty", "url", "util", "v8", "vm", "zlib", // Non-public files "timers", "constants", "freelist", "smalloc", "_debugger", "_http_agent", "_http_client", "_http_common", "_http_incoming", "_http_outgoing", "_http_server", "_linklist", "_stream_duplex", "_stream_passthrough", "_stream_readable", "_stream_transform", "_stream_writable", "_tls_common", "_tls_legacy", "_tls_wrap")); protected NodejsRequiredCoreModule(File f, SourceFileModule clonedFrom) throws IOException { super(FilenameUtils.getBaseName(f.getName()), f, clonedFrom); } private static InputStream getModule(String name) { return NodejsRequiredCoreModule.class .getClassLoader() .getResourceAsStream("core-modules/" + name + ".js"); } private static final Map<String, File> names = HashMapFactory.make(); public static NodejsRequiredCoreModule make(String name) throws IOException { if (!names.containsKey(name)) { java.nio.file.Path p = Files.createTempDirectory("nodejs"); File f = new File(p.toFile(), name + ".js"); f.deleteOnExit(); p.toFile().deleteOnExit(); names.put(name, f); } File file = names.get(name); try (InputStream module = getModule(name)) { TemporaryFile.streamToFile(file, module); } SourceFileModule sourceFileModule = CAstCallGraphUtil.makeSourceModule(file.toURI().toURL(), file.getName()); return new NodejsRequiredCoreModule(file, sourceFileModule); } public static boolean isCoreModule(String name) { return CORE_MODULES.contains(name); } }
3,755
29.786885
99
java
WALA
WALA-master/cast/js/nodejs/src/main/java/com/ibm/wala/cast/js/nodejs/NodejsRequiredSourceModule.java
/* * Copyright (c) 2002 - 2016 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Brian Pfretzschner - initial implementation */ package com.ibm.wala.cast.js.nodejs; import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil; import com.ibm.wala.classLoader.SourceFileModule; import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.io.Streams; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.nio.charset.Charset; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; /** * This class is intended to be used whenever a JavaScript module is dynamically required by * JavaScript (CommonJS). The required file will be loaded and wrapped in a function call to * simulate the real behavior of a CommonJS environment. The resulting function will be named * GLOBAL_PREFIX + relative file-name. To retrieve the final function name, use getFunctioName(). * * @author Brian Pfretzschner &lt;[email protected]&gt; */ public class NodejsRequiredSourceModule extends SourceFileModule { private static final String MODULE_WRAPPER_FILENAME = "module-wrapper.js"; private static final String JSON_WRAPPER_FILENAME = "json-wrapper.js"; private static final String FILENAME_PLACEHOLDER = "/*/ WALA-INSERT-FILENAME-HERE /*/"; private static final String DIRNAME_PLACEHOLDER = "/*/ WALA-INSERT-DIRNAME-HERE /*/"; private static final String CODE_PLACEHOLDER = "/*/ WALA-INSERT-CODE-HERE /*/"; private static String MODULE_WRAPPER_SOURCE = null; private static String JSON_WRAPPER_SOURCE = null; private final String className; /** @param f Must be a file located below folder workingDir. */ protected NodejsRequiredSourceModule(String className, File f, SourceFileModule clonedFrom) throws IOException { super(f, clonedFrom); // Generate className based on the given file name this.className = className; assert className.matches("[a-zA-Z_$][0-9a-zA-Z_$]*") : "Invalid className: " + className; if (MODULE_WRAPPER_SOURCE == null || JSON_WRAPPER_SOURCE == null) { // Populate the cache that hold the module wrapper source code loadWrapperSources(); } } @Override public InputStream getInputStream() { String moduleSource = null; try (final InputStream inputStream = super.getInputStream()) { moduleSource = IOUtils.toString(inputStream, (Charset) null); } catch (IOException e) { Assertions.UNREACHABLE(e.getMessage()); } String wrapperSource = null; String ext = FilenameUtils.getExtension(getFile().toString()).toLowerCase(); switch (ext) { case "js": // JS file -> use module wrapper wrapperSource = MODULE_WRAPPER_SOURCE; break; case "json": // JSON file -> use JSON wrapper wrapperSource = JSON_WRAPPER_SOURCE; break; default: // No clue -> try module wrapper System.err.println( "NodejsRequiredSourceModule: Unsupported file type (" + ext + "), continue anyway."); wrapperSource = MODULE_WRAPPER_SOURCE; break; } String wrappedModuleSource = wrapperSource .replace(FILENAME_PLACEHOLDER, getFile().getName()) .replace(DIRNAME_PLACEHOLDER, getFile().getParent()) .replace(CODE_PLACEHOLDER, moduleSource); return IOUtils.toInputStream(wrappedModuleSource, (Charset) null); } @Override public String getClassName() { return className; } @Override public String getName() { return className; } private static void loadWrapperSources() throws IOException { MODULE_WRAPPER_SOURCE = loadWrapperSource(MODULE_WRAPPER_FILENAME); JSON_WRAPPER_SOURCE = loadWrapperSource(JSON_WRAPPER_FILENAME); } private static String loadWrapperSource(String filename) throws IOException { try (final InputStream url = NodejsRequiredSourceModule.class.getClassLoader().getResourceAsStream(filename)) { return new String(Streams.inputStream2ByteArray(url)); } } /** * Generate a className based on the file name and path of the module file. The path should be * encoded in the className since the file name is not unique. */ public static String convertFileToClassName(File rootDir, File file) { URI normalizedWorkingDirURI = rootDir.getAbsoluteFile().toURI().normalize(); URI normalizedFileURI = file.getAbsoluteFile().toURI().normalize(); String relativePath = normalizedWorkingDirURI.relativize(normalizedFileURI).getPath(); return FilenameUtils.removeExtension(relativePath) .replace("/", "_") .replace("-", "__") .replace(".", "__"); } public static NodejsRequiredSourceModule make(File rootDir, File file) throws IOException { String className = convertFileToClassName(rootDir, file); SourceFileModule sourceFileModule = CAstCallGraphUtil.makeSourceModule(file.toURI().toURL(), file.getName()); return new NodejsRequiredSourceModule(className, file, sourceFileModule); } }
5,327
36.258741
97
java
WALA
WALA-master/cast/js/nodejs/src/test/java/com/ibm/wala/cast/js/nodejs/test/NodejsRequireJsonTest.java
/* * Copyright (c) 2002 - 2016 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Brian Pfretzschner - initial implementation */ package com.ibm.wala.cast.js.nodejs.test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.ibm.wala.cast.js.nodejs.NodejsCallGraphBuilderUtil; import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder; import java.io.File; import java.net.URL; import org.junit.Test; /** @author Brian Pfretzschner &lt;[email protected]&gt; */ public class NodejsRequireJsonTest { @Test public void test() throws Exception { URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireJsonTest/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Lempty/jsonModule>")); assertTrue(cgString.contains("Lnested/jsonModule>")); assertTrue(cgString.contains("Lpackage/jsonModule>")); assertFalse(cgString.contains("?")); } }
1,457
34.560976
92
java
WALA
WALA-master/cast/js/nodejs/src/test/java/com/ibm/wala/cast/js/nodejs/test/NodejsRequireTargetSelectorResolveTest.java
/* * Copyright (c) 2002 - 2016 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Brian Pfretzschner - initial implementation */ package com.ibm.wala.cast.js.nodejs.test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.ibm.wala.cast.js.nodejs.NodejsCallGraphBuilderUtil; import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder; import java.io.File; import java.net.URL; import org.junit.Test; /** @author Brian Pfretzschner &lt;[email protected]&gt; */ public class NodejsRequireTargetSelectorResolveTest { @Test public void testRequireSimple() throws Exception { URL fileUrl = getClass() .getClassLoader() .getResource("NodejsRequireTargetSelectorResolve/requireSimple/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Lmod/nodejsModule/moduleSource/exec>")); assertTrue(cgString.contains("Lmod/nodejsModule/moduleSource/SomeClass/hello>")); assertFalse(cgString.contains("?")); } @Test public void testRequireStaticCircular() throws Exception { URL fileUrl = getClass() .getClassLoader() .getResource("NodejsRequireTargetSelectorResolve/requireStaticCircular/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Llib1/nodejsModule/moduleSource/lib1>")); assertTrue(cgString.contains("Llib2/nodejsModule/moduleSource/lib2>")); assertFalse(cgString.contains("?")); } @Test public void testRequireDynamic() throws Exception { URL fileUrl = getClass() .getClassLoader() .getResource("NodejsRequireTargetSelectorResolve/requireDynamic/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Llib1/nodejsModule/moduleSource/lib1>")); assertTrue(cgString.contains("Llib2/nodejsModule/moduleSource/lib2>")); assertFalse(cgString.contains("?")); } @Test public void testRequireNodeModules() throws Exception { URL fileUrl = getClass() .getClassLoader() .getResource("NodejsRequireTargetSelectorResolve/requireNodeModules/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue( cgString.contains( "Lnode_modules_lib_node_modules_sublib_sublib/nodejsModule/moduleSource")); assertFalse(cgString.contains("?")); } @Test public void testRequireCoreModules() throws Exception { URL fileUrl = getClass() .getClassLoader() .getResource("NodejsRequireTargetSelectorResolve/requireCoreModules.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Lutil/nodejsModule/moduleSource/util")); assertTrue(cgString.contains("Lhttps/nodejsModule/moduleSource/https")); assertTrue(cgString.contains("Lhttp/nodejsModule/moduleSource/http")); } }
4,176
36.294643
94
java
WALA
WALA-master/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/drivers/RunBuilder.java
/* * Copyright (c) 2007 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation */ package com.ibm.wala.cast.js.examples.drivers; import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil; import com.ibm.wala.cast.ir.translator.RewritingTranslatorToCAst; import com.ibm.wala.cast.ir.translator.TranslatorToCAst; import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder; import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory; import com.ibm.wala.cast.js.translator.RhinoToAstTranslator; import com.ibm.wala.cast.js.util.JSCallGraphBuilderUtil; import com.ibm.wala.cast.js.util.JSCallGraphBuilderUtil.CGBuilderType; import com.ibm.wala.cast.tree.CAst; import com.ibm.wala.cast.tree.impl.CAstImpl; import com.ibm.wala.classLoader.ModuleEntry; import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.util.CancelException; import com.ibm.wala.util.WalaException; import java.io.IOException; public class RunBuilder { public static void main(String[] args) throws IOException, WalaException, IllegalArgumentException, CancelException { class CAstRhinoNewTranslator extends RewritingTranslatorToCAst { public CAstRhinoNewTranslator(ModuleEntry m, boolean replicateForDoLoops) { super( m, new RhinoToAstTranslator(new CAstImpl(), m, m.getName(), replicateForDoLoops, true)); } } com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil.setTranslatorFactory( new CAstRhinoTranslatorFactory() { @Override public TranslatorToCAst make(CAst ast, ModuleEntry M) { return new CAstRhinoNewTranslator(M, false); } }); JSCFABuilder builder = JSCallGraphBuilderUtil.makeScriptCGBuilder( args[0], args[1], CGBuilderType.ZERO_ONE_CFA_WITHOUT_CORRELATION_TRACKING, RunBuilder.class.getClassLoader()); // builder.setContextSelector(new CPAContextSelector(builder.getContextSelector())); CallGraph CG = builder.makeCallGraph(builder.getOptions()); System.err.println(CG.getClassHierarchy()); CAstCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG); } }
2,506
36.984848
100
java
WALA
WALA-master/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/hybrid/Driver.java
package com.ibm.wala.cast.js.examples.hybrid; import com.ibm.wala.cast.ipa.callgraph.CrossLanguageCallGraph; import com.ibm.wala.cast.ipa.callgraph.CrossLanguageMethodTargetSelector; import com.ibm.wala.cast.ipa.callgraph.StandardFunctionTargetSelector; import com.ibm.wala.cast.ipa.cha.CrossLanguageClassHierarchy; import com.ibm.wala.cast.ir.ssa.AstIRFactory; import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil; import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptConstructTargetSelector; import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptEntryPoints; import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory; import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.Language; import com.ibm.wala.classLoader.SourceURLModule; import com.ibm.wala.core.util.config.AnalysisScopeReader; import com.ibm.wala.core.util.io.FileProvider; import com.ibm.wala.core.util.strings.Atom; import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl; import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.IAnalysisCacheView; import com.ibm.wala.ipa.callgraph.MethodTargetSelector; import com.ibm.wala.ipa.callgraph.impl.ComposedEntrypoints; import com.ibm.wala.ipa.callgraph.impl.FakeRootClass; import com.ibm.wala.ipa.callgraph.impl.FakeRootMethod; import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ssa.IRFactory; import com.ibm.wala.util.CancelException; import com.ibm.wala.util.collections.HashMapFactory; import java.io.IOException; import java.net.URL; import java.util.Map; public class Driver { public static void addDefaultDispatchLogic(AnalysisOptions options, IClassHierarchy cha) { com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha); Map<Atom, MethodTargetSelector> methodTargetSelectors = HashMapFactory.make(); methodTargetSelectors.put( JavaScriptLoader.JS.getName(), new JavaScriptConstructTargetSelector( cha, new StandardFunctionTargetSelector(cha, options.getMethodTargetSelector()))); methodTargetSelectors.put(Language.JAVA.getName(), options.getMethodTargetSelector()); options.setSelector(new CrossLanguageMethodTargetSelector(methodTargetSelectors)); } public static void main(String[] args) throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory()); HybridClassLoaderFactory loaders = new HybridClassLoaderFactory(); HybridAnalysisScope scope = new HybridAnalysisScope(); FileProvider files = new FileProvider(); AnalysisScopeReader.instance.read( scope, args[0], files.getFile("Java60RegressionExclusions.txt"), Driver.class.getClassLoader()); scope.addToScope(scope.getJavaScriptLoader(), JSCallGraphUtil.getPrologueFile("prologue.js")); for (int i = 1; i < args.length; i++) { URL script = Driver.class.getClassLoader().getResource(args[i]); scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(script)); } System.err.println(scope); IClassHierarchy cha = CrossLanguageClassHierarchy.make(scope, loaders); Iterable<Entrypoint> jsRoots = new JavaScriptEntryPoints(cha, cha.getLoader(scope.getJavaScriptLoader())); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(cha); ComposedEntrypoints roots = new ComposedEntrypoints(jsRoots, entrypoints); AnalysisOptions options = new AnalysisOptions(scope, roots); IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory(); IAnalysisCacheView cache = new AnalysisCacheImpl(factory); addDefaultDispatchLogic(options, cha); JavaJavaScriptHybridCallGraphBuilder b = new JavaJavaScriptHybridCallGraphBuilder( new FakeRootMethod( new FakeRootClass(CrossLanguageCallGraph.crossCoreLoader, cha), options, cache), options, cache); System.err.println(b.makeCallGraph(options)); } }
4,212
40.712871
98
java
WALA
WALA-master/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/hybrid/HybridAnalysisScope.java
package com.ibm.wala.cast.js.examples.hybrid; import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.types.JavaScriptTypes; import com.ibm.wala.classLoader.Language; import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.util.collections.HashSetFactory; import java.util.Set; public class HybridAnalysisScope extends AnalysisScope { private static final Set<Language> languages; static { languages = HashSetFactory.make(); languages.add(Language.JAVA); languages.add(JavaScriptLoader.JS); } public HybridAnalysisScope() { super(languages); this.initForJava(); ClassLoaderReference jsLoader = JavaScriptTypes.jsLoader; loadersByName.put(JavaScriptTypes.jsLoaderName, jsLoader); } public ClassLoaderReference getJavaScriptLoader() { return getLoader(JavaScriptTypes.jsLoaderName); } }
925
26.235294
62
java
WALA
WALA-master/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/hybrid/HybridClassLoaderFactory.java
package com.ibm.wala.cast.js.examples.hybrid; import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory; import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory; import com.ibm.wala.cast.js.types.JavaScriptTypes; import com.ibm.wala.classLoader.ClassLoaderFactoryImpl; import com.ibm.wala.classLoader.IClassLoader; import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.util.config.SetOfClasses; import java.io.IOException; public class HybridClassLoaderFactory extends ClassLoaderFactoryImpl { private final JavaScriptTranslatorFactory jsTranslatorFactory; public HybridClassLoaderFactory( JavaScriptTranslatorFactory jsTranslatorFactory, SetOfClasses exclusions) { super(exclusions); this.jsTranslatorFactory = jsTranslatorFactory; } public HybridClassLoaderFactory() { this(new CAstRhinoTranslatorFactory(), null); } @Override protected IClassLoader makeNewClassLoader( ClassLoaderReference classLoaderReference, IClassHierarchy cha, IClassLoader parent, AnalysisScope scope) throws IOException { if (classLoaderReference.equals(JavaScriptTypes.jsLoader)) { JavaScriptLoader L = new JavaScriptLoader(cha, jsTranslatorFactory); L.init(scope.getModules(classLoaderReference)); return L; } else { return super.makeNewClassLoader(classLoaderReference, cha, parent, scope); } } }
1,564
33.021739
81
java
WALA
WALA-master/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/hybrid/JavaJavaScriptHybridCallGraphBuilder.java
package com.ibm.wala.cast.js.examples.hybrid; import com.ibm.wala.cast.ipa.callgraph.AstCFAPointerKeys; import com.ibm.wala.cast.ipa.callgraph.AstSSAPropagationCallGraphBuilder.AstPointerAnalysisImpl.AstImplicitPointsToSetVisitor; import com.ibm.wala.cast.ipa.callgraph.CrossLanguageCallGraph; import com.ibm.wala.cast.ipa.callgraph.CrossLanguageContextSelector; import com.ibm.wala.cast.ipa.callgraph.CrossLanguageInstanceKeys; import com.ibm.wala.cast.ipa.callgraph.CrossLanguageSSAPropagationCallGraphBuilder; import com.ibm.wala.cast.ipa.callgraph.GlobalObjectKey; import com.ibm.wala.cast.js.ipa.callgraph.JSSSAPropagationCallGraphBuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSSSAPropagationCallGraphBuilder.JSConstraintVisitor; import com.ibm.wala.cast.js.ipa.callgraph.JSSSAPropagationCallGraphBuilder.JSInterestingVisitor; import com.ibm.wala.cast.js.ipa.callgraph.JSSSAPropagationCallGraphBuilder.JSPointerAnalysisImpl.JSImplicitPointsToSetVisitor; import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptConstructorContextSelector; import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptConstructorInstanceKeys; import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptFunctionApplyContextSelector; import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptScopeMappingInstanceKeys; import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.types.JavaScriptTypes; import com.ibm.wala.cast.util.TargetLanguageSelector; import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.Language; import com.ibm.wala.core.util.strings.Atom; import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.ContextSelector; import com.ibm.wala.ipa.callgraph.IAnalysisCacheView; import com.ibm.wala.ipa.callgraph.impl.AbstractRootMethod; import com.ibm.wala.ipa.callgraph.impl.DefaultContextSelector; import com.ibm.wala.ipa.callgraph.propagation.AbstractFieldPointerKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory; import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey; import com.ibm.wala.ipa.callgraph.propagation.PointerKey; import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter; import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys; import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; import com.ibm.wala.util.collections.HashMapFactory; import java.util.Map; public class JavaJavaScriptHybridCallGraphBuilder extends CrossLanguageSSAPropagationCallGraphBuilder { public JavaJavaScriptHybridCallGraphBuilder( IMethod fakeRootClass, AnalysisOptions options, IAnalysisCacheView cache) { super(fakeRootClass, options, cache, new AstCFAPointerKeys()); globalObject = new GlobalObjectKey(cha.lookupClass(JavaScriptTypes.Root)); SSAContextInterpreter contextInterpreter = makeDefaultContextInterpreters(null, options, cha); setContextInterpreter(contextInterpreter); ContextSelector def = new DefaultContextSelector(options, cha); Map<Atom, ContextSelector> languageSelectors = HashMapFactory.make(); languageSelectors.put( JavaScriptTypes.jsName, new JavaScriptFunctionApplyContextSelector(new JavaScriptConstructorContextSelector(def))); languageSelectors.put(Language.JAVA.getName(), def); setContextSelector(new CrossLanguageContextSelector(languageSelectors)); Map<Atom, InstanceKeyFactory> instanceKeys = HashMapFactory.make(); instanceKeys.put( JavaScriptTypes.jsName, new JavaScriptScopeMappingInstanceKeys( cha, this, new JavaScriptConstructorInstanceKeys( new ZeroXInstanceKeys( options, cha, contextInterpreter, ZeroXInstanceKeys.ALLOCATIONS)))); instanceKeys.put( Language.JAVA.getName(), new ZeroXInstanceKeys(options, cha, contextInterpreter, ZeroXInstanceKeys.NONE)); setInstanceKeys(new CrossLanguageInstanceKeys(instanceKeys)); } private final GlobalObjectKey globalObject; @Override public GlobalObjectKey getGlobalObject(Atom language) { assert language.equals(JavaScriptTypes.jsName); return globalObject; } @Override protected TargetLanguageSelector<ConstraintVisitor, CGNode> makeMainVisitorSelector() { return (language, construct) -> { if (JavaScriptTypes.jsName.equals(language)) { return new JSConstraintVisitor(JavaJavaScriptHybridCallGraphBuilder.this, construct); } else { return new ConstraintVisitor(JavaJavaScriptHybridCallGraphBuilder.this, construct); } }; } @Override protected TargetLanguageSelector<InterestingVisitor, Integer> makeInterestingVisitorSelector() { return (language, construct) -> { if (JavaScriptTypes.jsName.equals(language)) { return new JSInterestingVisitor(construct); } else { return new InterestingVisitor(construct); } }; } @Override protected TargetLanguageSelector<AstImplicitPointsToSetVisitor, LocalPointerKey> makeImplicitVisitorSelector(CrossLanguagePointerAnalysisImpl analysis) { return (language, construct) -> { if (JavaScriptTypes.jsName.equals(language)) { return new JSImplicitPointsToSetVisitor( (AstPointerAnalysisImpl) getPointerAnalysis(), construct); } else { return new AstImplicitPointsToSetVisitor( (AstPointerAnalysisImpl) getPointerAnalysis(), construct); } }; } @Override protected TargetLanguageSelector<AbstractRootMethod, CrossLanguageCallGraph> makeRootNodeSelector() { return (language, construct) -> getOptions() .getAnalysisScope() .getLanguage(language) .getFakeRootMethod(getClassHierarchy(), getOptions(), getAnalysisCache()); } @Override protected boolean useObjectCatalog() { return true; } @Override protected AbstractFieldPointerKey fieldKeyForUnknownWrites(AbstractFieldPointerKey fieldKey) { // TODO Auto-generated method stub return null; } @Override protected boolean sameMethod(CGNode opNode, String definingMethod) { if (JavaScriptLoader.JS.equals( opNode.getMethod().getDeclaringClass().getClassLoader().getLanguage())) { return definingMethod.equals( opNode.getMethod().getReference().getDeclaringClass().getName().toString()); } else { return false; } } @Override protected void processCallingConstraints( CGNode caller, SSAAbstractInvokeInstruction instruction, CGNode target, InstanceKey[][] constParams, PointerKey uniqueCatchKey) { if (JavaScriptLoader.JS.equals( caller.getMethod().getDeclaringClass().getClassLoader().getLanguage())) { JSSSAPropagationCallGraphBuilder.processCallingConstraintsInternal( this, caller, instruction, target, constParams, uniqueCatchKey); } else { super.processCallingConstraints(caller, instruction, target, constParams, uniqueCatchKey); } } }
7,094
41.48503
126
java