a new example program, requested by Amer Diwan
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2846 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
3df05382f0
commit
8c83635562
14
com.ibm.wala.core.tests/launchers/CountParameters.launch
Normal file
14
com.ibm.wala.core.tests/launchers/CountParameters.launch
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/com.ibm.wala.core.tests/src/com/ibm/wala/examples/analysis/CountParameters.java"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.examples.analysis.CountParameters"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-classpath c:/temp/testdata/JLex.jar"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.core.tests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx500M"/>
|
||||
</launchConfiguration>
|
||||
@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* 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.examples.analysis;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
|
||||
/**
|
||||
* This is a simple example WALA application.
|
||||
*
|
||||
* This counts the number of parameters to each method in the primordial loader (the J2SE standard libraries), and
|
||||
* prints the result.
|
||||
*
|
||||
* @author sfink
|
||||
*/
|
||||
public class CountParameters {
|
||||
|
||||
private final static ClassLoader MY_CLASSLOADER = CountParameters.class.getClassLoader();
|
||||
|
||||
/**
|
||||
* Use the 'CountParameters' launcher to run this program with the appropriate classpath
|
||||
*/
|
||||
public static void main(String[] args) throws IOException, ClassHierarchyException {
|
||||
// build an analysis scope representing the standard libraries, excluding no classes
|
||||
AnalysisScope scope = AnalysisScopeReader.read("primordial.txt", null, MY_CLASSLOADER);
|
||||
|
||||
// build a class hierarchy
|
||||
System.err.print("Build class hierarchy...");
|
||||
IClassHierarchy cha = ClassHierarchy.make(scope);
|
||||
System.err.println("Done");
|
||||
|
||||
int nClasses = 0;
|
||||
int nMethods = 0;
|
||||
int nParameters = 0;
|
||||
|
||||
for (IClass c : cha) {
|
||||
nClasses++;
|
||||
for (IMethod m : c.getDeclaredMethods()) {
|
||||
nMethods++;
|
||||
nParameters += m.getNumberOfParameters();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(nClasses + " classes");
|
||||
System.out.println(nMethods + " methods");
|
||||
System.out.println((float)nParameters/(float)nMethods + " parameters per method");
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user