2013-05-22 22:39:19 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* 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
|
|
|
|
*******************************************************************************/
|
2012-11-28 17:09:55 +00:00
|
|
|
package com.ibm.wala.ide.jsdt.tests;
|
2012-09-24 19:43:51 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.eclipse.core.runtime.CoreException;
|
2013-12-02 14:35:47 +00:00
|
|
|
import org.eclipse.core.runtime.Plugin;
|
2012-09-24 19:43:51 +00:00
|
|
|
import org.eclipse.wst.jsdt.core.IJavaScriptProject;
|
|
|
|
import org.junit.Assert;
|
2013-12-02 14:35:47 +00:00
|
|
|
import org.junit.Ignore;
|
2012-09-24 19:43:51 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import com.ibm.wala.cast.ipa.callgraph.CAstAnalysisScope;
|
2013-07-24 15:18:54 +00:00
|
|
|
import com.ibm.wala.cast.js.client.EclipseJavaScriptAnalysisEngine;
|
2013-10-16 21:37:53 +00:00
|
|
|
import com.ibm.wala.cast.js.client.EclipseJavaScriptAnalysisEngine.BuilderType;
|
2012-09-24 19:43:51 +00:00
|
|
|
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
|
|
|
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
|
|
|
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
|
|
|
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
|
|
|
import com.ibm.wala.classLoader.ModuleEntry;
|
|
|
|
import com.ibm.wala.ide.tests.util.EclipseTestUtil.ZippedProjectData;
|
|
|
|
import com.ibm.wala.ide.util.JavaScriptEclipseProjectPath;
|
|
|
|
import com.ibm.wala.ide.util.JavaScriptHeadlessUtil;
|
|
|
|
import com.ibm.wala.ide.util.JsdtUtil;
|
|
|
|
import com.ibm.wala.ide.util.JsdtUtil.CGInfo;
|
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
2013-07-24 15:18:54 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2013-12-02 14:35:47 +00:00
|
|
|
import com.ibm.wala.util.collections.Pair;
|
2012-09-24 19:43:51 +00:00
|
|
|
|
2013-07-30 18:04:08 +00:00
|
|
|
public abstract class AbstractJSProjectScopeTest {
|
2014-10-15 07:01:38 +00:00
|
|
|
|
2012-09-24 19:43:51 +00:00
|
|
|
protected final ZippedProjectData project;
|
|
|
|
|
|
|
|
public AbstractJSProjectScopeTest(ZippedProjectData project) {
|
|
|
|
this.project = project;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testOpenProject() {
|
|
|
|
IJavaScriptProject p = JavaScriptHeadlessUtil.getJavaScriptProjectFromWorkspace(project.projectName);
|
|
|
|
System.err.println(p);
|
|
|
|
Assert.assertTrue("cannot find project", p != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testProjectScope() throws IOException, CoreException {
|
|
|
|
IJavaScriptProject p = JavaScriptHeadlessUtil.getJavaScriptProjectFromWorkspace(project.projectName);
|
|
|
|
JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory());
|
2013-07-30 18:04:08 +00:00
|
|
|
AnalysisScope s = makeProjectPath(p).toAnalysisScope(new CAstAnalysisScope(JSCallGraphUtil.makeLoaders(), Collections.singleton(JavaScriptLoader.JS)));
|
2012-09-24 19:43:51 +00:00
|
|
|
System.err.println(s);
|
|
|
|
Assert.assertTrue("cannot make scope", s != null);
|
|
|
|
Assert.assertFalse("cannot find files", s.getModules(JavaScriptTypes.jsLoader).isEmpty());
|
|
|
|
}
|
|
|
|
|
2013-07-30 18:04:08 +00:00
|
|
|
protected JavaScriptEclipseProjectPath makeProjectPath(IJavaScriptProject p) throws IOException, CoreException {
|
2013-12-02 14:35:47 +00:00
|
|
|
return JavaScriptEclipseProjectPath.make(p, Collections.<Pair<String,Plugin>>emptySet());
|
2013-07-30 18:04:08 +00:00
|
|
|
}
|
|
|
|
|
2015-05-26 13:09:50 +00:00
|
|
|
@Ignore("works for me on Eclipse Luna, but I cannot make it work with maven")
|
2012-09-24 19:43:51 +00:00
|
|
|
@Test
|
|
|
|
public void testParsing() throws IOException, CoreException {
|
|
|
|
Set<ModuleEntry> mes = JsdtUtil.getJavaScriptCodeFromProject(project.projectName);
|
|
|
|
CGInfo info = JsdtUtil.buildJSDTCallGraph(mes);
|
|
|
|
|
|
|
|
System.err.println(info.calls.size());
|
|
|
|
System.err.println("call graph:\n" + info.cg);
|
|
|
|
Assert.assertTrue("cannot find any function calls", info.calls.size()>0);
|
2014-10-15 07:01:38 +00:00
|
|
|
Assert.assertTrue("cannot find any cg nodes", info.cg.getNumberOfNodes()>0);
|
2012-09-24 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
2012-10-01 17:11:10 +00:00
|
|
|
@Test
|
2017-07-27 21:53:07 +00:00
|
|
|
public void testEngine() throws IOException, IllegalArgumentException {
|
2012-10-01 17:11:10 +00:00
|
|
|
IJavaScriptProject p = JavaScriptHeadlessUtil.getJavaScriptProjectFromWorkspace(project.projectName);
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
EclipseJavaScriptAnalysisEngine<InstanceKey> e = makeAnalysisEngine(p);
|
2012-10-01 17:11:10 +00:00
|
|
|
JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory());
|
2013-07-24 15:18:54 +00:00
|
|
|
e.buildAnalysisScope();
|
|
|
|
IClassHierarchy cha = e.getClassHierarchy();
|
2013-12-03 18:08:29 +00:00
|
|
|
//System.err.println(cha);
|
2013-07-24 15:18:54 +00:00
|
|
|
Assert.assertTrue(cha != null);
|
|
|
|
}
|
|
|
|
|
2017-07-27 21:53:07 +00:00
|
|
|
protected EclipseJavaScriptAnalysisEngine<InstanceKey> makeAnalysisEngine(IJavaScriptProject p) {
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
return new EclipseJavaScriptAnalysisEngine<>(p, BuilderType.REFLECTIVE);
|
2012-10-01 17:11:10 +00:00
|
|
|
}
|
2013-07-24 15:18:54 +00:00
|
|
|
|
2017-02-03 01:33:27 +00:00
|
|
|
}
|