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-08-21 19:53:16 +00:00
|
|
|
package com.ibm.wala.ide.util;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2013-12-02 14:35:47 +00:00
|
|
|
import java.net.URL;
|
2012-08-21 19:53:16 +00:00
|
|
|
import java.util.Arrays;
|
2013-08-07 19:19:27 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Set;
|
2012-08-21 19:53:16 +00:00
|
|
|
|
|
|
|
import org.eclipse.core.resources.IProject;
|
|
|
|
import org.eclipse.core.runtime.CoreException;
|
2013-08-07 19:19:27 +00:00
|
|
|
import org.eclipse.core.runtime.Plugin;
|
2012-08-21 19:53:16 +00:00
|
|
|
import org.eclipse.wst.jsdt.core.IIncludePathEntry;
|
|
|
|
import org.eclipse.wst.jsdt.core.IJavaScriptProject;
|
|
|
|
import org.eclipse.wst.jsdt.core.JavaScriptCore;
|
|
|
|
import org.eclipse.wst.jsdt.core.JavaScriptModelException;
|
|
|
|
|
2017-02-03 01:33:27 +00:00
|
|
|
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
2012-08-21 20:06:01 +00:00
|
|
|
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
2013-07-30 18:04:08 +00:00
|
|
|
import com.ibm.wala.classLoader.Module;
|
2015-07-30 23:37:02 +00:00
|
|
|
import com.ibm.wala.ide.jsdt.Activator;
|
2012-08-21 20:06:01 +00:00
|
|
|
import com.ibm.wala.types.ClassLoaderReference;
|
2013-08-07 19:19:27 +00:00
|
|
|
import com.ibm.wala.util.collections.HashSetFactory;
|
|
|
|
import com.ibm.wala.util.collections.Pair;
|
2012-08-21 20:06:01 +00:00
|
|
|
|
2012-08-21 19:53:16 +00:00
|
|
|
public class JavaScriptEclipseProjectPath extends EclipseProjectPath<IIncludePathEntry, IJavaScriptProject> {
|
|
|
|
|
2012-08-21 20:06:01 +00:00
|
|
|
public enum JSLoader implements ILoader {
|
|
|
|
JAVASCRIPT(JavaScriptTypes.jsLoader);
|
|
|
|
|
|
|
|
private ClassLoaderReference ref;
|
2012-08-21 19:53:16 +00:00
|
|
|
|
2012-08-21 20:06:01 +00:00
|
|
|
JSLoader(ClassLoaderReference ref) {
|
|
|
|
this.ref = ref;
|
|
|
|
}
|
2012-08-22 16:15:46 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ClassLoaderReference ref() {
|
|
|
|
return ref;
|
|
|
|
}
|
2012-08-21 20:06:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 19:19:27 +00:00
|
|
|
private final Set<Pair<String, Plugin>> models = HashSetFactory.make();
|
|
|
|
|
2017-07-27 21:53:07 +00:00
|
|
|
protected JavaScriptEclipseProjectPath(Set<Pair<String, Plugin>> models) {
|
2013-08-07 19:19:27 +00:00
|
|
|
super(AnalysisScopeType.SOURCE_FOR_PROJ_AND_LINKED_PROJS);
|
|
|
|
this.models.addAll(models);
|
2015-07-30 23:37:02 +00:00
|
|
|
this.models.add(Pair.make("prologue.js", (Plugin)Activator.getDefault()));
|
2012-08-21 19:53:16 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 19:19:27 +00:00
|
|
|
public static JavaScriptEclipseProjectPath make(IJavaScriptProject p, Set<Pair<String, Plugin>> models) throws IOException, CoreException {
|
|
|
|
JavaScriptEclipseProjectPath path = new JavaScriptEclipseProjectPath(models);
|
|
|
|
path.create(p.getProject());
|
|
|
|
return path;
|
2012-08-21 19:53:16 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 19:19:27 +00:00
|
|
|
|
2012-08-21 19:53:16 +00:00
|
|
|
@Override
|
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
|
|
|
public EclipseProjectPath<?, ?> create(IProject project) throws CoreException, IOException {
|
|
|
|
EclipseProjectPath<?, ?> path = super.create(project);
|
2013-08-07 19:19:27 +00:00
|
|
|
|
|
|
|
Collection<Module> s = modules.get(JSLoader.JAVASCRIPT);
|
|
|
|
for(Pair<String,Plugin> model : models) {
|
2015-07-30 23:37:02 +00:00
|
|
|
URL modelFile = JsdtUtil.getPrologueFile(model.fst, model.snd);
|
2014-01-03 15:07:52 +00:00
|
|
|
assert modelFile != null : "cannot find file for " + model;
|
2017-02-03 01:33:27 +00:00
|
|
|
s.add(new JSCallGraphUtil.Bootstrap(model.fst, modelFile.openStream(), modelFile));
|
2013-08-07 19:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-08-21 19:53:16 +00:00
|
|
|
protected IJavaScriptProject makeProject(IProject p) {
|
|
|
|
try {
|
|
|
|
if (p.hasNature(JavaScriptCore.NATURE_ID)) {
|
|
|
|
return JavaScriptCore.create(p);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (CoreException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected IIncludePathEntry resolve(IIncludePathEntry entry) {
|
|
|
|
return JavaScriptCore.getResolvedIncludepathEntry(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void resolveClasspathEntry(IJavaScriptProject project,
|
|
|
|
IIncludePathEntry entry,
|
2012-08-21 20:06:01 +00:00
|
|
|
ILoader loader,
|
2012-08-21 19:53:16 +00:00
|
|
|
boolean includeSource, boolean cpeFromMainProject) {
|
|
|
|
IIncludePathEntry e = JavaScriptCore.getResolvedIncludepathEntry(entry);
|
2017-08-06 19:50:05 +00:00
|
|
|
final int entryKind = e.getEntryKind();
|
|
|
|
switch (entryKind) {
|
2012-08-21 19:53:16 +00:00
|
|
|
case IIncludePathEntry.CPE_SOURCE:
|
2013-08-07 19:19:27 +00:00
|
|
|
resolveSourcePathEntry(JSLoader.JAVASCRIPT, true, cpeFromMainProject, e.getPath(), null, e.getExclusionPatterns(), "js");
|
2017-08-06 19:50:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new UnsupportedOperationException(String.format("unexpected classpath entry kind %s", entryKind));
|
2012-08-21 19:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-07-24 15:18:54 +00:00
|
|
|
protected void resolveProjectClasspathEntries(IJavaScriptProject project, boolean includeSource) {
|
|
|
|
try {
|
2012-08-21 19:53:16 +00:00
|
|
|
resolveClasspathEntries(project, Arrays.asList(project.getRawIncludepath()), Loader.EXTENSION, includeSource, true);
|
|
|
|
} catch (JavaScriptModelException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|