use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class ReplAutoEdit method getConfiguredInterpreter.
protected XbaseInterpreter getConfiguredInterpreter(XtextResource resource) {
XbaseInterpreter interpreter2 = interpreterProvider.get();
ResourceSet set = resource.getResourceSet();
ClassLoader cl = getClass().getClassLoader();
if (set instanceof XtextResourceSet) {
Object context = ((XtextResourceSet) set).getClasspathURIContext();
if (context instanceof IJavaProject) {
try {
final IJavaProject jp = (IJavaProject) context;
// String[] runtimeClassPath =
// JavaRuntime.computeDefaultRuntimeClassPath(jp);
// URL[] urls = new URL[runtimeClassPath.length];
// for (int i = 0; i < urls.length; i++) {
// urls[i] = new URL(runtimeClassPath[i]);
// }
// cl = new URLClassLoader(urls);
IClasspathEntry[] classpath = jp.getResolvedClasspath(true);
final IWorkspaceRoot root = jp.getProject().getWorkspace().getRoot();
Set<URL> urls = newHashSet();
for (int i = 0; i < classpath.length; i++) {
final IClasspathEntry entry = classpath[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
IPath outputLocation = entry.getOutputLocation();
if (outputLocation == null) {
outputLocation = jp.getOutputLocation();
}
IFolder folder = root.getFolder(outputLocation);
if (folder.exists()) {
urls.add(new URL(folder.getRawLocationURI().toASCIIString() + "/"));
}
} else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
IPath outputLocation = entry.getOutputLocation();
if (outputLocation == null) {
IProject project = (IProject) jp.getProject().getWorkspace().getRoot().getContainerForLocation(entry.getPath());
IJavaProject javaProject = JavaCore.create(project);
outputLocation = javaProject.getOutputLocation();
}
IFolder folder = root.getFolder(outputLocation);
if (folder.exists()) {
urls.add(new URL(folder.getRawLocationURI().toASCIIString() + "/"));
}
} else {
urls.add(entry.getPath().toFile().toURI().toURL());
}
}
cl = new URLClassLoader(urls.toArray(new URL[urls.size()]));
} catch (Exception e) {
e.printStackTrace();
}
}
}
interpreter2.setClassLoader(cl);
return interpreter2;
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class ResourceAccess method registerResourceSet.
public void registerResourceSet(ResourceSet resourceSet) {
if (resourceSet instanceof XtextResourceSet) {
Object context = ((XtextResourceSet) resourceSet).getClasspathURIContext();
if (context instanceof IJavaProject) {
IProject project = ((IJavaProject) context).getProject();
resourceSets.put(project, resourceSet);
}
}
this.fallBackResourceSet = resourceSet;
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class SimpleResourceSetProvider method get.
@Override
public ResourceSet get(IProject project) {
XtextResourceSet xtextResourceSet = resourceSetProvider.get();
ProjectConfigAdapter.install(xtextResourceSet, projectConfigProvider.createProjectConfig(project));
return xtextResourceSet;
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class XtextResourceSetProvider method get.
@Override
public ResourceSet get(IProject project) {
XtextResourceSet set = resourceSetProvider.get();
ProjectConfigAdapter.install(set, projectConfigProvider.createProjectConfig(project));
for (int i = 0; i < initializers.size(); i++) {
initializers.get(i).initialize(set, project);
}
return set;
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class JavaProjectResourceSetInitializer method initialize.
@Override
public void initialize(ResourceSet resourceSet, IProject project) {
if (resourceSet instanceof XtextResourceSet) {
XtextResourceSet casted = (XtextResourceSet) resourceSet;
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null && javaProject.exists()) {
casted.getURIConverter().getURIMap().putAll(computePlatformURIMap(javaProject));
casted.setClasspathURIContext(javaProject);
casted.setClasspathUriResolver(new JdtClasspathUriResolver());
}
}
}
Aggregations