git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@620 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
8b41a566ae
commit
870f9cc88f
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1,2 @@
|
|||
bin
|
||||
domo-trace.txt*
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.ibm.wala.cast.java.test</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,16 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Java AST DOMO Test Plug-in
|
||||
Bundle-SymbolicName: com.ibm.domo.ast.java.test
|
||||
Bundle-Version: 1.0.0
|
||||
Bundle-Activator: com.ibm.wala.cast.java.test.TestPlugin
|
||||
Bundle-Vendor: IBM
|
||||
Bundle-Localization: plugin
|
||||
Require-Bundle: com.ibm.wala.core.tests,
|
||||
com.ibm.domo.ast.java,
|
||||
com.ibm.wala.cast,
|
||||
com.ibm.wala.core,
|
||||
org.eclipse.core.runtime,
|
||||
org.junit
|
||||
Eclipse-AutoStart: true
|
||||
Export-Package: com.ibm.wala.cast.java.test
|
|
@ -0,0 +1,4 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
|
@ -0,0 +1,383 @@
|
|||
/******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* Created on Oct 3, 2005
|
||||
*/
|
||||
package com.ibm.wala.cast.java.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import com.ibm.wala.util.debug.*;
|
||||
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
|
||||
import com.ibm.wala.cast.java.client.EclipseProjectSourceAnalysisEngine;
|
||||
import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
|
||||
import com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl;
|
||||
import com.ibm.wala.cast.java.translator.polyglot.IRTranslatorExtension;
|
||||
import com.ibm.wala.cast.java.translator.polyglot.PolyglotClassLoaderFactory;
|
||||
import com.ibm.wala.classLoader.ClassLoaderFactory;
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IClassLoader;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.classLoader.JarFileModule;
|
||||
import com.ibm.wala.classLoader.SourceFileModule;
|
||||
import com.ibm.wala.client.AnalysisEngine;
|
||||
import com.ibm.wala.client.impl.AbstractAnalysisEngine;
|
||||
import com.ibm.wala.core.tests.util.WalaTestCase;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
|
||||
import com.ibm.wala.ipa.callgraph.Entrypoints;
|
||||
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
|
||||
import com.ibm.wala.ipa.callgraph.impl.Util;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
import com.ibm.wala.ssa.*;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.types.MethodReference;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.Atom;
|
||||
import com.ibm.wala.util.collections.*;
|
||||
import com.ibm.wala.util.warnings.WarningSet;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
public abstract class IRTests extends WalaTestCase {
|
||||
public IRTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected static String javaHomePath= System.getProperty("java.home");
|
||||
|
||||
protected static String testSrcPath= "." + File.separator + "testSrc";
|
||||
|
||||
protected static List/*<String>*/ rtJar;
|
||||
|
||||
static {
|
||||
rtJar = new LinkedList();
|
||||
rtJar.add(javaHomePath + File.separator + "lib" + File.separator + "rt.jar");
|
||||
rtJar.add(javaHomePath + File.separator + "lib" + File.separator + "core.jar");
|
||||
rtJar.add(javaHomePath + File.separator + "lib" + File.separator + "vm.jar");
|
||||
}
|
||||
|
||||
protected static class EdgeAssertions {
|
||||
public final String srcDescriptor;
|
||||
public final List/*<String>*/ tgtDescriptors= new ArrayList();
|
||||
public EdgeAssertions(String srcDescriptor) {
|
||||
this.srcDescriptor= srcDescriptor;
|
||||
}
|
||||
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor) {
|
||||
EdgeAssertions ea= new EdgeAssertions(srcDescriptor);
|
||||
ea.tgtDescriptors.add(tgtDescriptor);
|
||||
return ea;
|
||||
}
|
||||
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor1, String tgtDescriptor2) {
|
||||
EdgeAssertions ea= new EdgeAssertions(srcDescriptor);
|
||||
ea.tgtDescriptors.add(tgtDescriptor1);
|
||||
ea.tgtDescriptors.add(tgtDescriptor2);
|
||||
return ea;
|
||||
}
|
||||
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor1, String tgtDescriptor2, String tgtDescriptor3) {
|
||||
EdgeAssertions ea= new EdgeAssertions(srcDescriptor);
|
||||
ea.tgtDescriptors.add(tgtDescriptor1);
|
||||
ea.tgtDescriptors.add(tgtDescriptor2);
|
||||
ea.tgtDescriptors.add(tgtDescriptor3);
|
||||
return ea;
|
||||
}
|
||||
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor1, String tgtDescriptor2, String tgtDescriptor3, String tgtDescriptor4) {
|
||||
EdgeAssertions ea= new EdgeAssertions(srcDescriptor);
|
||||
ea.tgtDescriptors.add(tgtDescriptor1);
|
||||
ea.tgtDescriptors.add(tgtDescriptor2);
|
||||
ea.tgtDescriptors.add(tgtDescriptor3);
|
||||
ea.tgtDescriptors.add(tgtDescriptor4);
|
||||
return ea;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class GraphAssertions {
|
||||
public final Set/*<EdgeAssertions>*/ nodeAssertions= new HashSet();
|
||||
public GraphAssertions() { }
|
||||
public GraphAssertions(EdgeAssertions ea1) {
|
||||
nodeAssertions.add(ea1);
|
||||
}
|
||||
public GraphAssertions(EdgeAssertions ea1, EdgeAssertions ea2) {
|
||||
nodeAssertions.add(ea1);
|
||||
nodeAssertions.add(ea2);
|
||||
}
|
||||
public GraphAssertions(EdgeAssertions ea1, EdgeAssertions ea2, EdgeAssertions ea3) {
|
||||
nodeAssertions.add(ea1);
|
||||
nodeAssertions.add(ea2);
|
||||
nodeAssertions.add(ea3);
|
||||
}
|
||||
public GraphAssertions(EdgeAssertions ea1, EdgeAssertions ea2, EdgeAssertions ea3, EdgeAssertions ea4) {
|
||||
nodeAssertions.add(ea1);
|
||||
nodeAssertions.add(ea2);
|
||||
nodeAssertions.add(ea3);
|
||||
nodeAssertions.add(ea4);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class SourceMapAssertion {
|
||||
private final String variableName;
|
||||
private final int definingLineNumber;
|
||||
|
||||
protected
|
||||
SourceMapAssertion(String variableName, int definingLineNumber)
|
||||
{
|
||||
this.variableName = variableName;
|
||||
this.definingLineNumber = definingLineNumber;
|
||||
}
|
||||
|
||||
boolean check(IMethod m, IR ir) {
|
||||
Trace.println(
|
||||
"check for " + variableName + " defined at " + definingLineNumber);
|
||||
SSAInstruction[] insts = ir.getInstructions();
|
||||
for(int i = 0; i < insts.length; i++) {
|
||||
if (insts[i] != null) {
|
||||
int ln = m.getLineNumber( i );
|
||||
if (ln == definingLineNumber) {
|
||||
Trace.println(" found " + insts[i] + " at " + ln);
|
||||
for(int j = 0; j < insts[i].getNumberOfDefs(); j++) {
|
||||
int def = insts[i].getDef(j);
|
||||
Trace.println(" looking at def " + j + ": " + def);
|
||||
String[] names = ir.getLocalNames(i, def);
|
||||
if (names != null) {
|
||||
for(int n = 0; n < names.length; n++) {
|
||||
Trace.println(" looking at name " + names[n]);
|
||||
if (names[n].equals(variableName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class SourceMapAssertions {
|
||||
|
||||
private final Map methodAssertions = new HashMap();
|
||||
|
||||
protected void addAssertion(String method, SourceMapAssertion a) {
|
||||
Set x = MapUtil.findOrCreateSet(methodAssertions, method);
|
||||
x.add(a);
|
||||
}
|
||||
|
||||
void check(CallGraph CG) {
|
||||
WarningSet ws = new WarningSet();
|
||||
for(Iterator ms = methodAssertions.entrySet().iterator();
|
||||
ms.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry)ms.next();
|
||||
|
||||
Set s = (Set) entry.getValue();
|
||||
|
||||
String method = (String) entry.getKey();
|
||||
MethodReference mref = descriptorToMethodRef(method, CG.getClassHierarchy());
|
||||
|
||||
for(Iterator ns = CG.getNodes(mref).iterator(); ns.hasNext(); ) {
|
||||
CGNode n = (CGNode) ns.next();
|
||||
for(Iterator as = s.iterator(); as.hasNext(); ) {
|
||||
SourceMapAssertion a = (SourceMapAssertion) as.next();
|
||||
Assert.assertTrue(
|
||||
"failed for " + a.variableName + " in " + n,
|
||||
a.check(n.getMethod(), CG.getInterpreter(n).getIR(n, ws)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String singleInputForTest();
|
||||
|
||||
protected abstract String singlePkgInputForTest(String pkgName);
|
||||
|
||||
protected Collection singleTestSrc() {
|
||||
return Collections.singletonList(testSrcPath + File.separator + singleInputForTest());
|
||||
}
|
||||
|
||||
protected Collection singlePkgTestSrc(String pkgName) {
|
||||
return Collections.singletonList(testSrcPath + File.separator + singlePkgInputForTest(pkgName));
|
||||
}
|
||||
|
||||
protected String[] simpleTestEntryPoint() {
|
||||
return new String[] { "L" + getName().substring(4) };
|
||||
}
|
||||
|
||||
protected String[] simplePkgTestEntryPoint(String pkgName) {
|
||||
return new String[] { "L" + pkgName + "/" + getName().substring(4) };
|
||||
}
|
||||
|
||||
protected abstract EclipseProjectSourceAnalysisEngine getAnalysisEngine();
|
||||
|
||||
public void runTest(Collection/*<String>*/ sources,
|
||||
List/*<String>*/ libs,
|
||||
String[] mainClassDescriptors,
|
||||
GraphAssertions ga,
|
||||
SourceMapAssertions sa)
|
||||
{
|
||||
try {
|
||||
EclipseProjectSourceAnalysisEngine engine= getAnalysisEngine();
|
||||
|
||||
populateScope(engine, sources, libs);
|
||||
|
||||
CallGraph callGraph = engine.buildDefaultCallGraph(mainClassDescriptors);
|
||||
|
||||
// If we've gotten this far, IR has been produced.
|
||||
dumpIR(callGraph);
|
||||
|
||||
// Now check any assertions as to source mapping
|
||||
if (sa != null) {
|
||||
sa.check(callGraph);
|
||||
}
|
||||
|
||||
// Now check any assertions as to call-graph shape.
|
||||
checkCallGraphShape(callGraph, ga);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void dumpIR(CallGraph cg) throws IOException {
|
||||
WarningSet warnings= new WarningSet();
|
||||
ClassHierarchy cha = cg.getClassHierarchy();
|
||||
IClassLoader sourceLoader = cha.getLoader(JavaSourceAnalysisScope.SOURCE_REF);
|
||||
for(Iterator iter= sourceLoader.iterateAllClasses(); iter.hasNext(); ) {
|
||||
IClass clazz= (IClass) iter.next();
|
||||
|
||||
System.out.println(clazz);
|
||||
if (clazz.isInterface())
|
||||
continue;
|
||||
|
||||
for(Iterator iterator= clazz.getDeclaredMethods().iterator();
|
||||
iterator.hasNext(); )
|
||||
{
|
||||
IMethod m= (IMethod) iterator.next();
|
||||
if (m.isAbstract())
|
||||
System.out.println(m);
|
||||
else {
|
||||
Iterator nodeIter= cg.getNodes(m.getReference()).iterator();
|
||||
if (!nodeIter.hasNext()) {
|
||||
System.err.println("Source method " + m.getReference() + " not reachable?");
|
||||
continue;
|
||||
}
|
||||
CGNode node= (CGNode) nodeIter.next();
|
||||
System.out.println(cg.getInterpreter(node).getIR(node, warnings));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkCallGraphShape(CallGraph callGraph, GraphAssertions ga) throws IOException {
|
||||
Trace.println(callGraph.toString());
|
||||
for(Iterator nodeIter= ga.nodeAssertions.iterator(); nodeIter.hasNext(); ) {
|
||||
EdgeAssertions ea= (EdgeAssertions) nodeIter.next();
|
||||
|
||||
MethodReference srcMethod= descriptorToMethodRef(ea.srcDescriptor, callGraph.getClassHierarchy());
|
||||
Set/*<CGNode>*/ srcNodes= callGraph.getNodes(srcMethod);
|
||||
|
||||
if (srcNodes.size() == 0) {
|
||||
System.err.println("Unreachable/non-existent method: " + srcMethod);
|
||||
continue;
|
||||
}
|
||||
if (srcNodes.size() > 1) {
|
||||
System.err.println("Context-sensitive call graph?");
|
||||
}
|
||||
|
||||
// Assume only one node for src method
|
||||
CGNode srcNode= (CGNode) srcNodes.iterator().next();
|
||||
|
||||
for(Iterator edgeIter= ea.tgtDescriptors.iterator(); edgeIter.hasNext(); ) {
|
||||
String target= (String) edgeIter.next();
|
||||
MethodReference tgtMethod= descriptorToMethodRef(target, callGraph.getClassHierarchy());
|
||||
// Assume only one node for target method
|
||||
Set tgtNodes= callGraph.getNodes(tgtMethod);
|
||||
if (tgtNodes.size() == 0) {
|
||||
System.err.println("Unreachable/non-existent method: " + tgtMethod);
|
||||
continue;
|
||||
}
|
||||
CGNode tgtNode= (CGNode) tgtNodes.iterator().next();
|
||||
|
||||
boolean found= false;
|
||||
for(Iterator succIter= callGraph.getSuccNodes(srcNode); succIter.hasNext(); ) {
|
||||
CGNode succ= (CGNode) succIter.next();
|
||||
|
||||
if (tgtNode == succ) {
|
||||
found= true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
System.err.println("Missing edge: " + srcMethod + " -> " + tgtMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static MethodReference descriptorToMethodRef(String descrip, ClassHierarchy cha) {
|
||||
String srcDescriptor= descrip; // ldr#type#methName#methSig
|
||||
String[] ldrTypeMeth= srcDescriptor.split("\\#");
|
||||
|
||||
String loaderName= ldrTypeMeth[0];
|
||||
String typeStr= ldrTypeMeth[1];
|
||||
String methName= ldrTypeMeth[2];
|
||||
String methSig= ldrTypeMeth[3];
|
||||
|
||||
ClassLoaderReference clr= findLoader(loaderName, cha);
|
||||
TypeName typeName= TypeName.string2TypeName("L" + typeStr);
|
||||
TypeReference typeRef= TypeReference.findOrCreate(clr, typeName);
|
||||
MethodReference methodRef= MethodReference.findOrCreate(typeRef, methName, methSig);
|
||||
|
||||
return methodRef;
|
||||
}
|
||||
|
||||
private static ClassLoaderReference findLoader(String loaderName, ClassHierarchy cha) {
|
||||
Atom loaderAtom = Atom.findOrCreateUnicodeAtom(loaderName);
|
||||
IClassLoader[] loaders = cha.getLoaders();
|
||||
for(int i = 0; i < loaders.length; i++) {
|
||||
if (loaders[i].getName() == loaderAtom)
|
||||
return loaders[i].getReference();
|
||||
}
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void populateScope(EclipseProjectSourceAnalysisEngine engine, Collection/*<String>*/ sources, List/*<String>*/ libs) throws IOException {
|
||||
JavaSourceAnalysisScope scope= new JavaSourceAnalysisScope();
|
||||
|
||||
boolean foundLib = false;
|
||||
for(Iterator iter= libs.iterator(); iter.hasNext(); ) {
|
||||
String lib= (String) iter.next();
|
||||
|
||||
File libFile= new File(lib);
|
||||
if (libFile.exists()) {
|
||||
foundLib = true;
|
||||
engine.addSystemModule(new JarFileModule(new JarFile(libFile)));
|
||||
}
|
||||
}
|
||||
Assertions._assert(foundLib);
|
||||
|
||||
for(Iterator iter= sources.iterator(); iter.hasNext(); ) {
|
||||
String srcFilePath= (String) iter.next();
|
||||
String srcFileName= srcFilePath.substring(srcFilePath.lastIndexOf(File.separator)+1);
|
||||
|
||||
engine.addSourceModule(new SourceFileModule(new File(srcFilePath), srcFileName));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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.java.test;
|
||||
|
||||
import com.ibm.wala.cast.java.client.EclipseProjectSourceAnalysisEngine;
|
||||
|
||||
public class JLexTest extends IRTests {
|
||||
|
||||
public JLexTest() {
|
||||
super("JLexTest");
|
||||
}
|
||||
|
||||
protected EclipseProjectSourceAnalysisEngine getAnalysisEngine() {
|
||||
return new EclipseProjectSourceAnalysisEngine();
|
||||
}
|
||||
|
||||
protected String singleInputForTest() {
|
||||
return "JLex/Main.java";
|
||||
}
|
||||
|
||||
public void testJLex() {
|
||||
runTest(singleTestSrc(), rtJar,
|
||||
new String[]{ "LJLex/Main" },
|
||||
new GraphAssertions(),
|
||||
new SourceMapAssertions());
|
||||
}
|
||||
|
||||
protected String singlePkgInputForTest(String pkgName) {
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
/******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* Created on Oct 21, 2005
|
||||
*/
|
||||
package com.ibm.wala.cast.java.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.ibm.wala.cast.java.client.EclipseProjectSourceAnalysisEngine;
|
||||
import com.ibm.wala.cast.java.ipa.callgraph.AstJavaZeroXCFABuilder;
|
||||
import com.ibm.wala.cast.java.translator.polyglot.IRTranslatorExtension;
|
||||
import com.ibm.wala.cast.java.translator.polyglot.JavaIRTranslatorExtension;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.util.warnings.WarningSet;
|
||||
|
||||
public class JavaIRTests extends IRTests {
|
||||
public JavaIRTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected EclipseProjectSourceAnalysisEngine getAnalysisEngine() {
|
||||
return new EclipseProjectSourceAnalysisEngine();
|
||||
}
|
||||
|
||||
protected String singleInputForTest() {
|
||||
return getName().substring(4) + ".java";
|
||||
}
|
||||
|
||||
protected String singlePkgInputForTest(String pkgName) {
|
||||
return pkgName + File.separator + getName().substring(4) + ".java";
|
||||
}
|
||||
|
||||
public void testSimple1() {
|
||||
SourceMapAssertions sa = new SourceMapAssertions();
|
||||
sa.addAssertion("Source#Simple1#doStuff#(I)V", new SourceMapAssertion("prod", 13));
|
||||
sa.addAssertion("Source#Simple1#doStuff#(I)V", new SourceMapAssertion("j", 12));
|
||||
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("s", 21));
|
||||
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("i", 17));
|
||||
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("sum", 18));
|
||||
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(
|
||||
EdgeAssertions.make("Source#Simple1#main#([Ljava/lang/String;)V", "Source#Simple1#doStuff#(I)V"),
|
||||
EdgeAssertions.make("Source#Simple1#instanceMethod1#()V", "Source#Simple1#instanceMethod2#()V")
|
||||
),
|
||||
// this needs soure positions to work too
|
||||
sa);
|
||||
}
|
||||
|
||||
public void testTwoClasses() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testInterfaceTest1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testInheritance1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testArray1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testArrayLiteral1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testArrayLiteral2() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testInheritedField() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(
|
||||
EdgeAssertions.make("Source#InheritedField#main#([Ljava/lang/String;)V", "Source#B#foo#()V"),
|
||||
EdgeAssertions.make("Source#InheritedField#main#([Ljava/lang/String;)V", "Source#B#bar#()V")
|
||||
), null);
|
||||
}
|
||||
|
||||
public void testQualifiedStatic() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testStaticNesting() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testInnerClass() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testLocalClass() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testAnonymousClass() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testWhileTest1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testSwitch1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testException1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testException2() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testFinally1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testScoping1() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testScoping2() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testNonPrimaryTopLevel() {
|
||||
runTest(singlePkgTestSrc("p"), rtJar, simplePkgTestEntryPoint("p"),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testMiniaturList() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
|
||||
public void testMonitor() {
|
||||
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
|
||||
new GraphAssertions(), null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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.java.test;
|
||||
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* The main plugin class to be used in the desktop.
|
||||
*/
|
||||
public class TestPlugin extends Plugin {
|
||||
|
||||
//The shared instance.
|
||||
private static TestPlugin plugin;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public TestPlugin() {
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called upon plug-in activation
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the plug-in is stopped
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
super.stop(context);
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance.
|
||||
*/
|
||||
public static TestPlugin getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
public class AnonymousClass {
|
||||
private interface Foo {
|
||||
public int getValue();
|
||||
public int getValueBase();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final Integer base = new Integer(6);
|
||||
|
||||
Foo f= new Foo() {
|
||||
int value = 3;
|
||||
public int getValue() { return value; }
|
||||
public int getValueBase() { return value - base.intValue(); }
|
||||
};
|
||||
|
||||
System.out.println(f.getValue());
|
||||
System.out.println(f.getValueBase());
|
||||
|
||||
(new AnonymousClass()).method();
|
||||
}
|
||||
|
||||
public void method() {
|
||||
final Integer base = new Integer(7);
|
||||
|
||||
abstract class FooImpl implements Foo {
|
||||
int y;
|
||||
|
||||
public abstract int getValue();
|
||||
|
||||
FooImpl(int _y) {
|
||||
y = _y;
|
||||
}
|
||||
|
||||
public int getValueBase() {
|
||||
return y + getValue() - base.intValue();
|
||||
}
|
||||
}
|
||||
|
||||
Foo f= new FooImpl(-4) {
|
||||
public int getValue() { return 7; }
|
||||
};
|
||||
|
||||
System.out.println(f.getValue());
|
||||
System.out.println(f.getValueBase());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
public class Array1 {
|
||||
public static void main(String[] args) {
|
||||
Array1 f= new Array1();
|
||||
f.foo();
|
||||
}
|
||||
public void foo() {
|
||||
int[] ary = new int[5];
|
||||
|
||||
for(int i= 0; i < ary.length; i++) {
|
||||
ary[i]= i;
|
||||
}
|
||||
|
||||
int sum = 0;
|
||||
|
||||
for(int j= 0; j < ary.length; j++) {
|
||||
sum += ary[j];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public class ArrayLiteral1 {
|
||||
public static void main(String[] args) {
|
||||
ArrayLiteral1 al1= new ArrayLiteral1();
|
||||
int[] a= new int[] { 0, 1, 2, 3, 5 };
|
||||
Object[] b= new Object[] { null, "hi", new Integer(55), new int[] { 3, 1, 4 } };
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
public class ArrayLiteral2 {
|
||||
public static void main(String[] args) {
|
||||
ArrayLiteral2 al2= new ArrayLiteral2();
|
||||
int[] x= {};
|
||||
int[] y= { 1, 2, 3, 4 };
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
class FooEx1 {
|
||||
public void bar() throws BadLanguageExceptionEx1 {
|
||||
throw new BadLanguageExceptionEx1();
|
||||
}
|
||||
}
|
||||
class BadLanguageExceptionEx1 extends Exception {
|
||||
public BadLanguageExceptionEx1() {
|
||||
super("Try using a real language, like Perl");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
import java.io.*;
|
||||
|
||||
public final class Exception2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Exception2 e2= new Exception2();
|
||||
FileInputStream fis = null;
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
fis = new FileInputStream( args[0] );
|
||||
fos = new FileOutputStream( args[1] );
|
||||
|
||||
int data;
|
||||
while ( (data = fis.read()) != -1 ) {
|
||||
fos.write(data);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println( "File not found" );
|
||||
// whatever
|
||||
} catch (IOException e) {
|
||||
System.err.print( "I/O problem " );
|
||||
System.err.println( e.getMessage() );
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
public class Finally1 {
|
||||
public static void main(String[] args) throws BadLanguageExceptionF1 {
|
||||
Finally1 f1= new Finally1();
|
||||
try {
|
||||
FooF1 f = new FooF1();
|
||||
|
||||
f.bar();
|
||||
} finally {
|
||||
System.out.println("blah");
|
||||
}
|
||||
System.out.println("feep");
|
||||
}
|
||||
}
|
||||
class FooF1 {
|
||||
public void bar() throws BadLanguageExceptionF1 {
|
||||
if (true)
|
||||
throw new BadLanguageExceptionF1();
|
||||
System.out.println("feh");
|
||||
}
|
||||
}
|
||||
class BadLanguageExceptionF1 extends Exception {
|
||||
public BadLanguageExceptionF1() {
|
||||
super("Try using a real language, like Perl");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import java.io.IOException;
|
||||
|
||||
public class Finally2 {
|
||||
public static void main(String[] args) throws IOException {
|
||||
try {
|
||||
FooF2 f = new FooF2();
|
||||
|
||||
f.bar();
|
||||
f.bletch();
|
||||
} catch (BadLanguageExceptionF2 e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("blah");
|
||||
}
|
||||
}
|
||||
}
|
||||
class FooF2 {
|
||||
public void bar() throws BadLanguageExceptionF2 {
|
||||
throw new BadLanguageExceptionF2();
|
||||
}
|
||||
public void bletch() throws IOException {
|
||||
throw new IOException("Burp!");
|
||||
}
|
||||
}
|
||||
class BadLanguageExceptionF2 extends Exception {
|
||||
public BadLanguageExceptionF2() {
|
||||
super("Try using a real language, like Perl");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
public class Inheritance1 {
|
||||
public static void main(String[] args) {
|
||||
Inheritance1 ih1= new Inheritance1();
|
||||
Base b1 = new Base();
|
||||
Base b2 = new Derived();
|
||||
|
||||
b1.foo();
|
||||
b2.foo();
|
||||
b1.bar(3);
|
||||
b2.bar(5);
|
||||
}
|
||||
}
|
||||
class Base {
|
||||
public void foo() {
|
||||
int i= 0;
|
||||
}
|
||||
public String bar(int x) {
|
||||
return Integer.toOctalString(x);
|
||||
}
|
||||
}
|
||||
class Derived extends Base {
|
||||
public void foo() {
|
||||
super.foo();
|
||||
}
|
||||
public String bar(int x) {
|
||||
return Integer.toHexString(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
public class InheritedField {
|
||||
public static void main(String[] args) {
|
||||
InheritedField if1= new InheritedField();
|
||||
B b = new B();
|
||||
|
||||
b.foo();
|
||||
b.bar();
|
||||
}
|
||||
}
|
||||
class A {
|
||||
protected int value;
|
||||
}
|
||||
class B extends A {
|
||||
public void foo() {
|
||||
value = 10;
|
||||
}
|
||||
public void bar() {
|
||||
this.value *= 2;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
public class InnerClass {
|
||||
public static void main(String[] args) {
|
||||
(new InnerClass()).method();
|
||||
}
|
||||
|
||||
public void method() {
|
||||
WhatsIt w= new WhatsIt();
|
||||
}
|
||||
|
||||
class WhatsIt {
|
||||
private int value;
|
||||
public WhatsIt() {
|
||||
value= 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
public class InterfaceTest1 {
|
||||
public static void main(String[] args) {
|
||||
InterfaceTest1 it= new InterfaceTest1();
|
||||
IFoo foo = new Foo('a');
|
||||
char ch2 = foo.getValue();
|
||||
}
|
||||
}
|
||||
interface IFoo {
|
||||
char getValue();
|
||||
}
|
||||
class Foo implements IFoo {
|
||||
private char fValue;
|
||||
public Foo(char ch) {
|
||||
fValue= ch;
|
||||
}
|
||||
public char getValue() {
|
||||
return fValue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
public class LocalClass {
|
||||
public static void main(String[] args) {
|
||||
final Integer base = new Integer(6);
|
||||
|
||||
class Foo {
|
||||
int value;
|
||||
public Foo(int v) { value= v; }
|
||||
public int getValue() { return value; }
|
||||
public int getValueBase() { return value - base.intValue(); }
|
||||
}
|
||||
Foo f= new Foo(3);
|
||||
|
||||
System.out.println(f.getValue());
|
||||
System.out.println(f.getValueBase());
|
||||
|
||||
(new LocalClass()).method();
|
||||
}
|
||||
|
||||
public void method() {
|
||||
final Integer base = new Integer(6);
|
||||
|
||||
class Foo {
|
||||
int value;
|
||||
public Foo(int v) { value= v; }
|
||||
public int getValue() { return value; }
|
||||
public int getValueBase() { return value - base.intValue(); }
|
||||
}
|
||||
Foo f= new Foo(3);
|
||||
|
||||
System.out.println(f.getValue());
|
||||
System.out.println(f.getValueBase());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
public class MiniaturList {
|
||||
MiniaturList next;
|
||||
|
||||
int data;
|
||||
|
||||
public MiniaturList remove(int elt) {
|
||||
MiniaturList xp = null;
|
||||
MiniaturList head = this;
|
||||
MiniaturList x = head;
|
||||
|
||||
while (x != null) {
|
||||
if (x.data == elt) {
|
||||
if (xp == null)
|
||||
head = x.next;
|
||||
else
|
||||
xp.next = x.next;
|
||||
break;
|
||||
}
|
||||
xp = x;
|
||||
x = x.next;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
public static MiniaturList cons(int elt, MiniaturList l) {
|
||||
MiniaturList ret = new MiniaturList();
|
||||
ret.data = elt;
|
||||
ret.next = l;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean contains(int elt) {
|
||||
MiniaturList head = this;
|
||||
while (head != null) {
|
||||
if (head.data == elt)
|
||||
return true;
|
||||
head = head.next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
MiniaturList l1 = cons(1, cons(2, cons(3, cons(2, null))));
|
||||
MiniaturList l2 = cons(5, null);
|
||||
|
||||
l1 = l1.remove(2);
|
||||
//assert 2 !in l1.*next.data
|
||||
|
||||
System.out.println(l1.contains(3));
|
||||
System.out.println(l2.contains(6));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
public class Monitor {
|
||||
int i = 0;
|
||||
|
||||
public Monitor() { }
|
||||
|
||||
public void incr() { synchronized(this) { i++; } }
|
||||
|
||||
public static void main(String[] a) {
|
||||
new Monitor().incr();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
public class QualifiedStatic {
|
||||
public static void main(String[] args) {
|
||||
QualifiedStatic qs= new QualifiedStatic();
|
||||
FooQ fq= new FooQ();
|
||||
int x = FooQ.value;
|
||||
}
|
||||
}
|
||||
class FooQ {
|
||||
static int value= 0;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
public class Scoping1 {
|
||||
public static void main(String[] args) {
|
||||
Scoping1 s1= new Scoping1();
|
||||
{
|
||||
int x= 5;
|
||||
System.out.println(x);
|
||||
}
|
||||
{
|
||||
double x= 3.14;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
public class Scoping2 {
|
||||
public static void main(String[] args) {
|
||||
Scoping2 s2= new Scoping2();
|
||||
{
|
||||
final int x= 5;
|
||||
System.out.println(x);
|
||||
(new Object() {
|
||||
public void foo() {
|
||||
System.out.println("x = " + x);
|
||||
}
|
||||
}).foo();
|
||||
}
|
||||
{
|
||||
double x= 3.14;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
public class Simple1 {
|
||||
private int value;
|
||||
private float fval= 3.14F;
|
||||
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 void instanceMethod2() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
public class StaticNesting {
|
||||
public static void main(String[] args) {
|
||||
StaticNesting sn= new StaticNesting();
|
||||
WhatsIt w= new WhatsIt();
|
||||
}
|
||||
static class WhatsIt {
|
||||
private int value;
|
||||
public WhatsIt() {
|
||||
value= 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
public class Switch1 {
|
||||
public static void main(String[] args) {
|
||||
Switch1 s1= new Switch1();
|
||||
int x= Integer.parseInt(args[0]);
|
||||
char ch;
|
||||
switch(x) {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
public class TwoClasses {
|
||||
private int value;
|
||||
private float fval= 3.14F;
|
||||
public TwoClasses(int x) {
|
||||
value = x;
|
||||
}
|
||||
public TwoClasses() {
|
||||
this(0);
|
||||
}
|
||||
public static void doStuff(int N) {
|
||||
int prod= 1;
|
||||
TwoClasses tc= new TwoClasses();
|
||||
tc.instanceMethod1();
|
||||
for(int j=0; j < N; j++)
|
||||
prod *= j;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
int sum= 0;
|
||||
for(int i=0; i < 10; i++) {
|
||||
sum += i;
|
||||
}
|
||||
TwoClasses.doStuff(sum);
|
||||
}
|
||||
public void instanceMethod1() {
|
||||
instanceMethod2();
|
||||
}
|
||||
public void instanceMethod2() {
|
||||
Bar b= Bar.create('a');
|
||||
}
|
||||
}
|
||||
class Bar {
|
||||
private final char fChar;
|
||||
|
||||
private Bar(char c) {
|
||||
fChar= c;
|
||||
}
|
||||
public static Bar create(char c) {
|
||||
return new Bar(c);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
public class WhileTest1 {
|
||||
public static void main(String[] args) {
|
||||
WhileTest1 wt1= new WhileTest1();
|
||||
int x= 235834;
|
||||
boolean stop= false;
|
||||
|
||||
while (!stop) {
|
||||
x += 3;
|
||||
x ^= 0xAAAA5555;
|
||||
stop= (x & 0x1248) != 0;
|
||||
}
|
||||
|
||||
while (!stop) {
|
||||
x += 3;
|
||||
if (x < 7) continue;
|
||||
x ^= 0xAAAA5555;
|
||||
stop= (x & 0x1248) != 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package p;
|
||||
|
||||
public class NonPrimaryTopLevel {
|
||||
public static void main(String[] args) {
|
||||
NonPrimaryTopLevel nptl= new NonPrimaryTopLevel();
|
||||
Foo f = new Foo();
|
||||
}
|
||||
}
|
||||
class Foo {
|
||||
|
||||
}
|
Loading…
Reference in New Issue