org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider Java Examples

The following examples show how to use org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrySLParser.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * This constructor use the CogniCyrpt Core plugin lib folder as classpath
 */
public CrySLParser() {
	CrySLStandaloneSetup crySLStandaloneSetup = new CrySLStandaloneSetup();
	final Injector injector = crySLStandaloneSetup.createInjectorAndDoEMFRegistration();
	this.resourceSet = injector.getInstance(XtextResourceSet.class);
	List<File> jars = new ArrayList<>();
	String[] l = System.getProperty("java.class.path").split(";");

	URL[] classpath = new URL[l.length];
	for (int i = 0; i < classpath.length; i++) {
		try {
			classpath[i] = new File(l[i]).toURI().toURL();
		}
		catch (MalformedURLException e) {
			Activator.getDefault().logError("File path: " + jars.get(i) + " could not converted to java.net.URI object");
		}
	}

	URLClassLoader ucl = new URLClassLoader(classpath);
	this.resourceSet.setClasspathURIContext(new URLClassLoader(classpath));
	new ClasspathTypeProvider(ucl, this.resourceSet, null, null);
	this.resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
}
 
Example #2
Source File: JvmTypeReferencesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	ResourceSet resourceSet = new ResourceSetImpl();
	Resource syntheticResource = new XMLResourceImpl(URI.createURI("http://synthetic.resource"));
	resourceSet.getResources().add(syntheticResource);
	typeProvider = new ClasspathTypeProvider(getClass().getClassLoader(), resourceSet, null, null);
}
 
Example #3
Source File: CachingClasspathTypeProviderFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ClasspathTypeProvider createClasspathTypeProvider(ResourceSet resourceSet) {
	ClassLoader classLoader = getClassLoader(resourceSet);
	CachingDeclaredTypeFactory actualFactoryToUse = reusedFactory;
	if (!isDefaultClassLoader(classLoader)) {
		actualFactoryToUse = newClassReaderTypeFactory(classLoader);
	}
	return new CachingClasspathTypeProvider(
			classLoader, 
			resourceSet, 
			getIndexedJvmTypeAccess(),
			actualFactoryToUse, services);
}
 
Example #4
Source File: ClasspathTypeProviderFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ClasspathTypeProvider createTypeProvider(ResourceSet resourceSet) {
	if (resourceSet == null)
		throw new IllegalArgumentException("resourceSet may not be null.");
	ClasspathTypeProvider result = createClasspathTypeProvider(resourceSet);
	return result;
}
 
Example #5
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Performs the actual installation of the JvmTypeProvider.
 */
private void internalInstallJvmTypeProvider(ResourceSet resourceSet, File tmpClassDirectory, boolean skipIndexLookup) {
	Iterable<String> classPathEntries = concat(asList(tmpClassDirectory.toString()), getClassPathEntries(), getSourcePathDirectories());
	classPathEntries = filter(classPathEntries, new Predicate<String>() {
		@Override
		public boolean apply(String input) {
			return !Strings.isEmpty(input.trim());
		}
	});
	
	Iterable<File> classpath = transform(classPathEntries, TO_FILE);
	if (log.isDebugEnabled()) {
		log.debug("classpath used for Xtend compilation : " + classpath);
	}
	ClassLoader parentClassLoader;
	if (useCurrentClassLoaderAsParent) {
		parentClassLoader = currentClassLoader;
	} else {
		if (isEmpty(bootClassPath)) {
			parentClassLoader = ClassLoader.getSystemClassLoader().getParent();
		} else {
			Iterable<File> bootClassPathEntries = transform(getBootClassPathEntries(), TO_FILE);
			parentClassLoader = new AlternateJdkLoader(bootClassPathEntries);
		}
	}
	jvmTypesClassLoader = createClassLoader(classpath, parentClassLoader);
	new ClasspathTypeProvider(jvmTypesClassLoader, resourceSet, skipIndexLookup ? null : indexedJvmTypeAccess, null);
	((XtextResourceSet) resourceSet).setClasspathURIContext(jvmTypesClassLoader);

	// for annotation processing we need to have the compiler's classpath as a parent.
	annotationProcessingClassLoader = createClassLoader(classpath, currentClassLoader);
	resourceSet.eAdapters().add(new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(annotationProcessingClassLoader));
}
 
Example #6
Source File: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void installTypeProvider(Iterable<String> classPathRoots, XtextResourceSet resSet,
		IndexedJvmTypeAccess typeAccess) {
	URLClassLoader classLoader = createURLClassLoader(classPathRoots);
	new ClasspathTypeProvider(classLoader, resSet, typeAccess, null);
	resSet.setClasspathURIContext(classLoader);
}
 
Example #7
Source File: ClasspathTypeProviderFactoryTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateTypeProvider_01() {
	ClasspathTypeProvider typeProvider = factory.createTypeProvider();
	assertNotNull(typeProvider);
	assertNotNull(typeProvider.getResourceSet());
}
 
Example #8
Source File: ClasspathTypeProviderFactoryTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateTypeProvider_02() {
	ResourceSet resourceSet = new ResourceSetImpl();
	ClasspathTypeProvider typeProvider = factory.createTypeProvider(resourceSet);
	assertNotNull(typeProvider);
	assertEquals(resourceSet, typeProvider.getResourceSet());
}
 
Example #9
Source File: ClasspathTypeProviderFactoryTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateTypeProvider_03() {
	ClasspathTypeProvider typeProvider = factory.createTypeProvider();
	ResourceSet resourceSet = typeProvider.getResourceSet();
	Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap();
	assertEquals(typeProvider, map.get(URIHelperConstants.PROTOCOL));
}
 
Example #10
Source File: ClasspathTypeProviderFactoryTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testFindTypeProvider_02() {
	ResourceSet resourceSet = new ResourceSetImpl();
	ClasspathTypeProvider typeProvider = factory.createTypeProvider(resourceSet);
	assertSame(typeProvider, factory.findTypeProvider(resourceSet));
}
 
Example #11
Source File: JavaReflectAccessTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
	resourceSet = new ResourceSetImpl();
	typeProvider = new ClasspathTypeProvider(getClass().getClassLoader(), resourceSet, null, null);
}
 
Example #12
Source File: JvmTypeReferencesTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected ClasspathTypeProvider getTypeProvider() {
	return typeProvider;
}
 
Example #13
Source File: ClasspathBasedTypeScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ClasspathBasedTypeScope createTypeScope(IJvmTypeProvider typeProvider, Predicate<IEObjectDescription> filter) {
	return new ClasspathBasedTypeScope((ClasspathTypeProvider) typeProvider, qualifiedNameConverter, filter);
}
 
Example #14
Source File: ClasspathBasedTypeScope.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public ClasspathBasedTypeScope(ClasspathTypeProvider typeProvider, IQualifiedNameConverter qualifiedNameConverter, Predicate<IEObjectDescription> filter) {
	super(typeProvider, qualifiedNameConverter, filter);
}
 
Example #15
Source File: ClasspathTypeProviderFactory.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected ClasspathTypeProvider createClasspathTypeProvider(ResourceSet resourceSet) {
	return new ClasspathTypeProvider(getClassLoader(resourceSet), resourceSet, getIndexedJvmTypeAccess(), services);
}
 
Example #16
Source File: ClasspathTypeProviderFactory.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ClasspathTypeProvider createTypeProvider() {
	return (ClasspathTypeProvider) super.createTypeProvider();
}