org.eclipse.xtext.resource.ResourceSetContext Java Examples

The following examples show how to use org.eclipse.xtext.resource.ResourceSetContext. 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: EditorAwareCanLoadFromDescriptionHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * This implementation is aware of open editors and in the context of dirty resource / multiple open editors, we
 * need to consider also resources across project boundaries.
 */
@Override
public boolean mustLoadFromSource(URI resourceURI, ResourceSet resourceSet) {
	if (super.mustLoadFromSource(resourceURI, resourceSet)) {
		return true;
	}
	ResourceSetContext context = ResourceSetContext.get(resourceSet);
	// check that we are not in the builder scope (which has strict boundaries
	// wrt project dependencies
	if (!context.isBuilder()) {
		ImmutableSet<URI> openEditors = ImmutableSet.copyOf(dirtyStateManager.getDirtyResourceURIs());
		/* ignore project boundaries */
		return dependsOnAny(resourceURI, openEditors, getIndex(resourceSet), false);
	}
	return false;
}
 
Example #2
Source File: XtendResourceValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<Issue> validate(final Resource resource, final CheckMode mode, final CancelIndicator mon) throws OperationCanceledError {
  List<Issue> _xtrycatchfinallyexpression = null;
  try {
    _xtrycatchfinallyexpression = super.validate(resource, mode, mon);
  } finally {
    boolean _isEditor = ResourceSetContext.get(resource).isEditor();
    if (_isEditor) {
      final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(resource.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
      resource.eAdapters().remove(adapter);
    }
  }
  return _xtrycatchfinallyexpression;
}
 
Example #3
Source File: JdtBasedProcessorProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ClassLoader getClassLoader(final EObject ctx) {
  ResourceSet _resourceSet = ctx.eResource().getResourceSet();
  final XtextResourceSet rs = ((XtextResourceSet) _resourceSet);
  final boolean isBuilder = ResourceSetContext.get(rs).isBuilder();
  final boolean isEditor = ResourceSetContext.get(rs).isEditor();
  if (isBuilder) {
    final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(rs.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
    if ((adapter != null)) {
      return adapter.getClassLoader();
    }
  }
  if (isEditor) {
    final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter_1 = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(this.getEditorResource(ctx).eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
    if ((adapter_1 != null)) {
      ClassLoader _classLoader = adapter_1.getClassLoader();
      boolean _tripleEquals = (_classLoader == null);
      if (_tripleEquals) {
        this.getEditorResource(ctx).eAdapters().remove(adapter_1);
      } else {
        return adapter_1.getClassLoader();
      }
    }
  }
  Object _classpathURIContext = rs.getClasspathURIContext();
  final IJavaProject project = ((IJavaProject) _classpathURIContext);
  final URLClassLoader classloader = this.createClassLoaderForJavaProject(project);
  if (isBuilder) {
    EList<Adapter> _eAdapters = rs.eAdapters();
    ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
    _eAdapters.add(_processorClassloaderAdapter);
  }
  if (isEditor) {
    EList<Adapter> _eAdapters_1 = this.getEditorResource(ctx).eAdapters();
    ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter_1 = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
    _eAdapters_1.add(_processorClassloaderAdapter_1);
  }
  return classloader;
}
 
Example #4
Source File: ProjectAwareUniqueClassNameValidator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private ICompilationUnit[] getWorkingCopies(JvmDeclaredType type) {
	return ResourceSetContext.get(type).isBuilder() //
			? new ICompilationUnit[] {} //
			: JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false);
}
 
Example #5
Source File: JdtTypeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private ICompilationUnit[] getWorkingCopies() {
	if (ResourceSetContext.get(getResourceSet()).isBuilder()) {
		return new ICompilationUnit[0];
	}
	return JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false/*don't add primary WCs a second time*/);
}
 
Example #6
Source File: Linker.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean isClearAllReferencesRequired(Resource resource) {
	return ResourceSetContext.get(resource).isEditor();
}