Search in sources :

Example 1 with ClasspathTypeProvider

use of org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider in project xtext-xtend by eclipse.

the class TypeBasedSimpleBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = new XtextResourceSet();
    ClassLoader loader = getClass().getClassLoader();
    resourceSet.setClasspathURIContext(loader);
    typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
    CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
    owner = new StandardTypeReferenceOwner(services, resourceSet);
}
Also used : XbaseStandaloneSetup(org.eclipse.xtext.xbase.XbaseStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 2 with ClasspathTypeProvider

use of org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider in project xtext-xtend by eclipse.

the class XtendBatchCompiler method internalInstallJvmTypeProvider.

/**
 * 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));
}
Also used : AlternateJdkLoader(org.eclipse.xtext.util.internal.AlternateJdkLoader) ProcessorInstanceForJvmTypeProvider(org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URLClassLoader(java.net.URLClassLoader) XtendFile(org.eclipse.xtend.core.xtend.XtendFile) File(java.io.File) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) Predicate(com.google.common.base.Predicate)

Example 3 with ClasspathTypeProvider

use of org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider in project xtext-xtend by eclipse.

the class ConvertToArrayBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = new XtextResourceSet();
    ClassLoader loader = getClass().getClassLoader();
    resourceSet.setClasspathURIContext(loader);
    ClasspathTypeProvider typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
    CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
    StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, resourceSet);
    typeReference = type.getReference(typeProvider, owner);
    EcoreUtil.resolveAll(resourceSet);
}
Also used : XbaseStandaloneSetup(org.eclipse.xtext.xbase.XbaseStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 4 with ClasspathTypeProvider

use of org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider in project xtext-xtend by eclipse.

the class ParameterizedTypeReferenceBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = new XtextResourceSet();
    ClassLoader loader = getClass().getClassLoader();
    resourceSet.setClasspathURIContext(loader);
    ClasspathTypeProvider typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
    CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
    StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, resourceSet);
    typeReference = type.getReference(typeProvider, owner);
    EcoreUtil.resolveAll(resourceSet);
}
Also used : XbaseStandaloneSetup(org.eclipse.xtext.xbase.XbaseStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 5 with ClasspathTypeProvider

use of org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider in project xtext-xtend by eclipse.

the class IndexingTest method doTestResourceDescriptionWithoutGetContents.

private void doTestResourceDescriptionWithoutGetContents(final String input) throws IOException {
    XtextResourceSet resourceSet = getResourceSet();
    new ClasspathTypeProvider(classLoader, resourceSet, null, null);
    final Wrapper<Boolean> wrapper = Wrapper.wrap(Boolean.FALSE);
    for (int i = 0; i < 10; i++) {
        DerivedStateAwareResource resource = (DerivedStateAwareResource) resourceSet.createResource(URI.createURI("Dummy" + i + ".xtend"));
        resource.setDerivedStateComputer(new IDerivedStateComputer() {

            @Override
            public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
                if (!preLinkingPhase) {
                    wrapper.set(Boolean.TRUE);
                }
                derivedStateComputer.installDerivedState(resource, preLinkingPhase);
            }

            @Override
            public void discardDerivedState(DerivedStateAwareResource resource) {
                derivedStateComputer.discardDerivedState(resource);
            }
        });
        String actualInput = input;
        if (i != 0) {
            actualInput = "import C" + (i + 1) + " " + actualInput;
            actualInput = "import C" + (i - 1) + " " + actualInput;
        }
        actualInput = String.format(actualInput, i, i + 1);
        resource.load(new StringInputStream(actualInput), null);
    }
    for (int i = 0; i < 10; i++) {
        Resource resource = resourceSet.getResources().get(i);
        for (IEObjectDescription description : resourceDescriptionManager.getResourceDescription(resource).getExportedObjects()) {
            description.getEObjectOrProxy();
        }
    }
    assertFalse(wrapper.get());
}
Also used : DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) XtextResource(org.eclipse.xtext.resource.XtextResource) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) IDerivedStateComputer(org.eclipse.xtext.resource.IDerivedStateComputer) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Aggregations

ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)5 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)5 Injector (com.google.inject.Injector)3 XbaseStandaloneSetup (org.eclipse.xtext.xbase.XbaseStandaloneSetup)3 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)3 CommonTypeComputationServices (org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices)3 Predicate (com.google.common.base.Predicate)1 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ProcessorInstanceForJvmTypeProvider (org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 DerivedStateAwareResource (org.eclipse.xtext.resource.DerivedStateAwareResource)1 IDerivedStateComputer (org.eclipse.xtext.resource.IDerivedStateComputer)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1 AlternateJdkLoader (org.eclipse.xtext.util.internal.AlternateJdkLoader)1