fixes to make incubator Eclipse support use JDT-based Java front end
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3183 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
c28e2386f4
commit
c88772b8ec
|
@ -11,7 +11,8 @@ Require-Bundle: com.ibm.wala.cast.java;bundle-version="1.0.0",
|
|||
org.eclipse.core.runtime
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: com.ibm.wala.cast.java.polyglot;uses:="org.osgi.framework,org.eclipse.core.runtime",
|
||||
Export-Package: com.ibm.wala.cast.java.client.polyglot,
|
||||
com.ibm.wala.cast.java.polyglot;uses:="org.osgi.framework,org.eclipse.core.runtime",
|
||||
com.ibm.wala.cast.java.translator.polyglot;
|
||||
uses:="com.ibm.wala.types,
|
||||
polyglot.types,
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* 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.client.polyglot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.JavaModelException;
|
||||
|
||||
import com.ibm.wala.cast.java.client.impl.ZeroCFABuilderFactory;
|
||||
import com.ibm.wala.client.AbstractAnalysisEngine;
|
||||
import com.ibm.wala.eclipse.util.EclipseProjectPath;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
|
||||
/**
|
||||
* @author Julian Dolby (dolby@us.ibm.com)
|
||||
* @author sfink ... refactored
|
||||
*/
|
||||
public class EclipseProjectAnalysisEngine extends AbstractAnalysisEngine {
|
||||
|
||||
protected final IPath workspaceRootPath;
|
||||
|
||||
protected final IJavaProject project;
|
||||
|
||||
protected final EclipseProjectPath ePath;
|
||||
|
||||
public EclipseProjectAnalysisEngine(IJavaProject project)
|
||||
throws IOException, CoreException
|
||||
{
|
||||
super();
|
||||
this.project = project;
|
||||
this.workspaceRootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
|
||||
assert project != null;
|
||||
assert workspaceRootPath != null;
|
||||
this.ePath = createProjectPath(project);
|
||||
//setCallGraphBuilderFactory(new ZeroCFABuilderFactory());
|
||||
}
|
||||
|
||||
protected EclipseProjectPath createProjectPath(IJavaProject project) throws IOException, CoreException {
|
||||
return EclipseProjectPath.make(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildAnalysisScope() {
|
||||
super.scope = ePath.toAnalysisScope(new File(getExclusionsFile()));
|
||||
}
|
||||
|
||||
public EclipseProjectPath getEclipseProjectPath() {
|
||||
return ePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CallGraphBuilder getCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) {
|
||||
return new ZeroCFABuilderFactory().make(options, cache, cha, scope, false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
/******************************************************************************
|
||||
* 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.client.polyglot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.JavaModelException;
|
||||
|
||||
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
|
||||
import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
|
||||
import com.ibm.wala.cast.java.translator.polyglot.IRTranslatorExtension;
|
||||
import com.ibm.wala.cast.java.translator.polyglot.JavaIRTranslatorExtension;
|
||||
import com.ibm.wala.cast.java.translator.polyglot.PolyglotClassLoaderFactory;
|
||||
import com.ibm.wala.classLoader.BinaryDirectoryTreeModule;
|
||||
import com.ibm.wala.classLoader.ClassLoaderFactory;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.core.plugin.CorePlugin;
|
||||
import com.ibm.wala.eclipse.util.EclipseProjectPath;
|
||||
import com.ibm.wala.eclipse.util.EclipseProjectPath.Loader;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
||||
import com.ibm.wala.ipa.callgraph.impl.SetOfClasses;
|
||||
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.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.ssa.SSAOptions;
|
||||
import com.ibm.wala.ssa.SymbolTable;
|
||||
import com.ibm.wala.ssa.Value;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.config.FileOfClasses;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.io.FileProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author julian dolby?
|
||||
* @author sfink .. cleaned up and refactored some
|
||||
* @author smarkstr (added file extension support)
|
||||
*
|
||||
*/
|
||||
public class EclipseProjectSourceAnalysisEngine extends EclipseProjectAnalysisEngine {
|
||||
|
||||
public static final String defaultFileExt = "java";
|
||||
|
||||
/**
|
||||
* file extension for source files in this Eclipse project
|
||||
*/
|
||||
final String fileExt;
|
||||
|
||||
public EclipseProjectSourceAnalysisEngine(IJavaProject project)
|
||||
throws IOException, CoreException
|
||||
{
|
||||
this(project, defaultFileExt);
|
||||
}
|
||||
|
||||
public EclipseProjectSourceAnalysisEngine(IJavaProject project, String fileExt)
|
||||
throws IOException, CoreException
|
||||
{
|
||||
super(project);
|
||||
this.fileExt = fileExt;
|
||||
try {
|
||||
setExclusionsFile(FileProvider.getFileFromPlugin(CorePlugin.getDefault(), "J2SEClassHierarchyExclusions.txt").getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
Assertions.UNREACHABLE("Cannot find exclusions file");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnalysisCache makeDefaultCache() {
|
||||
return new AnalysisCache(AstIRFactory.makeDefaultFactory());
|
||||
}
|
||||
|
||||
protected AnalysisScope makeSourceAnalysisScope() {
|
||||
return new JavaSourceAnalysisScope();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildAnalysisScope() {
|
||||
try {
|
||||
scope = makeSourceAnalysisScope();
|
||||
if (getExclusionsFile() != null) {
|
||||
scope.setExclusions(new FileOfClasses(new File(getExclusionsFile())));
|
||||
}
|
||||
EclipseProjectPath epath = getEclipseProjectPath();
|
||||
|
||||
for (Module m : epath.getModules(Loader.PRIMORDIAL, true)) {
|
||||
scope.addToScope(scope.getPrimordialLoader(), m);
|
||||
}
|
||||
ClassLoaderReference app = scope.getApplicationLoader();
|
||||
for (Module m : epath.getModules(Loader.APPLICATION, true)) {
|
||||
scope.addToScope(app, m);
|
||||
}
|
||||
for (Module m : epath.getModules(Loader.EXTENSION, true)) {
|
||||
if (!(m instanceof BinaryDirectoryTreeModule))
|
||||
scope.addToScope(app, m);
|
||||
}
|
||||
ClassLoaderReference src = ((JavaSourceAnalysisScope)scope).getSourceLoader();
|
||||
for (Module m : epath.getModules(Loader.SOURCE, false)) {
|
||||
scope.addToScope(src, m);
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
Assertions.UNREACHABLE(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public IRTranslatorExtension getTranslatorExtension() {
|
||||
return new JavaIRTranslatorExtension();
|
||||
}
|
||||
|
||||
protected ClassLoaderFactory getClassLoaderFactory(SetOfClasses exclusions,IRTranslatorExtension extInfo) {
|
||||
return new PolyglotClassLoaderFactory(exclusions, extInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClassHierarchy buildClassHierarchy() {
|
||||
IClassHierarchy cha = null;
|
||||
ClassLoaderFactory factory = getClassLoaderFactory(scope.getExclusions(), getTranslatorExtension());
|
||||
|
||||
try {
|
||||
cha = ClassHierarchy.make(getScope(), factory);
|
||||
} catch (ClassHierarchyException e) {
|
||||
System.err.println("Class Hierarchy construction failed");
|
||||
System.err.println(e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cha;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<Entrypoint> makeDefaultEntrypoints(AnalysisScope scope, IClassHierarchy cha) {
|
||||
return Util.makeMainEntrypoints(EclipseProjectPath.SOURCE_REF, cha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnalysisOptions getDefaultOptions(Iterable<Entrypoint> entrypoints) {
|
||||
AnalysisOptions options = new AnalysisOptions(getScope(), entrypoints);
|
||||
|
||||
SSAOptions ssaOptions = new SSAOptions();
|
||||
ssaOptions.setDefaultValues(new SSAOptions.DefaultValues() {
|
||||
public int getDefaultValue(SymbolTable symtab, int valueNumber) {
|
||||
Value v = symtab.getValue(valueNumber);
|
||||
if (v == null) {
|
||||
Assertions._assert(v != null, "no default for " + valueNumber);
|
||||
}
|
||||
return v.getDefaultValue(symtab);
|
||||
}
|
||||
});
|
||||
|
||||
options.setSSAOptions(ssaOptions);
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue