org.eclipse.xtext.resource.IFragmentProvider Java Examples

The following examples show how to use org.eclipse.xtext.resource.IFragmentProvider. 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: AbstractClassMirror.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) {
	if (obj instanceof JvmTypeParameter)
		return getFragment(obj.eContainer(), fallback) + "/" + ((JvmTypeParameter) obj).getName();
	if (obj instanceof JvmTypeReference || obj instanceof JvmFormalParameter)
		return fallback.getFragment(obj);
	if (obj instanceof JvmIdentifiableElement) {
		if (obj instanceof JvmArrayType) {
			if (obj.eContainer() instanceof JvmGenericArrayTypeReference)
				return fallback.getFragment(obj);
			if (obj.eContainer() instanceof JvmIdentifiableElement) {
				return getFragment(obj.eContainer(), fallback) + "[]";
			}
		}
		return ((JvmIdentifiableElement) obj).getIdentifier();
	}
	return fallback.getFragment(obj);
}
 
Example #2
Source File: PrimitiveMirror.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EObject getEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
	if (fragment.endsWith("[]")) {
		return getArrayEObject(resource, fragment, fallback);
	}
	for (EObject obj: resource.getContents()) {
		String otherFragment = getFragment(obj, fallback);
		if (fragment.equals(otherFragment))
			return obj;
	}
	return fallback.getEObject(fragment);
}
 
Example #3
Source File: XtextFragmentProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EObject getEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
	if (!fragment.startsWith(PREFIX))
		return fallback.getEObject(fragment);
	String fragmentWithoutPrefix = fragment.substring(PREFIX.length());
	List<String> splitted = Strings.split(fragmentWithoutPrefix, '/');
	if (splitted.isEmpty()) {
		return fallback.getEObject(fragment);
	}
	String firstPart = splitted.get(0);
	Grammar grammar = null;
	for(EObject content: resource.getContents()) {
		if (content instanceof Grammar) {
			Grammar g = (Grammar) content;
			if (firstPart.equals(g.getName())) {
				grammar = g;
				if (splitted.size() == 1)
					return grammar;
				break;
			}
		}
	}
	if (splitted.size() == 2) {
		return GrammarUtil.findRuleForName(grammar, splitted.get(1));
	} else {
		return fallback.getEObject(fragment);
	}
}
 
Example #4
Source File: XtextFragmentProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) {
	if (obj instanceof Grammar) {
		return caseGrammar((Grammar)obj);
	} else if (obj instanceof AbstractRule && obj.eContainer() != null) {
		return caseAbstractRule((AbstractRule)obj, fallback);
	}
	return fallback.getFragment(obj);
}
 
Example #5
Source File: ExportFragment.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
  final BindFactory bindFactory = new BindFactory();
  final String namingPrefix = GrammarUtil.getNamespace(grammar) + ".naming." + GrammarUtil.getSimpleName(grammar); //$NON-NLS-1$
  final String resourcePrefix = GrammarUtil.getNamespace(grammar) + ".resource." + GrammarUtil.getSimpleName(grammar); //$NON-NLS-1$

  ExportModel m = getModel(grammar);
  if (m != null) {
    bindFactory.addTypeToType(IQualifiedNameProvider.class.getName(), namingPrefix + "ExportedNamesProvider"); //$NON-NLS-1$
    if (!m.getInterfaces().isEmpty()) {
      bindFactory.addTypeToType(IFingerprintComputer.class.getName(), resourcePrefix + "FingerprintComputer"); //$NON-NLS-1$
    }
    if (!m.getExports().isEmpty()) {
      bindFactory.addTypeToType(IDefaultResourceDescriptionStrategy.class.getName(), resourcePrefix + "ResourceDescriptionStrategy"); //$NON-NLS-1$
    }
    if (Iterables.any(m.getExports(), new Predicate<Export>() {
      @Override
      public boolean apply(final Export input) {
        return input.isFingerprint() && input.getFragmentAttribute() != null;
      }
    })) {
      bindFactory.addTypeToType(IFragmentProvider.class.getName(), resourcePrefix + "FragmentProvider"); //$NON-NLS-1$
    }
  }
  bindFactory.addTypeToType(IResourceDescription.Manager.class.getName(), resourcePrefix + "ResourceDescriptionManager"); //$NON-NLS-1$
  return bindFactory.getBindings();
}
 
Example #6
Source File: AbstractSelectorFragmentProviderTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  with(Modules2.mixin(new XtextRuntimeModule(), new AbstractModule() {
    @Override
    protected void configure() {
      bind(IFragmentProvider.class).to(TestSelectorFragmentProvider.class);
    }
  }));
}
 
Example #7
Source File: TypeResourceTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public EObject getEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
	assertEquals(expectedURI, resource.getURI());
	assertEquals(expectedFragment, fragment);
	return expectedObject;
}
 
Example #8
Source File: TypeResourceTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) {
	assertEquals(expectedObject, obj);
	return expectedFragment;
}
 
Example #9
Source File: AbstractClassMirror.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public EObject getEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
	if (fragment.endsWith("[]")) {
		return getArrayEObject(resource, fragment, fallback);
	}
	int slash = fragment.indexOf('/'); 
	if (slash != -1) {
		if (slash == 0)
			return fallback.getEObject(fragment);
		String containerFragment = fragment.substring(0, slash);
		EObject container = getEObject(resource, containerFragment, fallback);
		if (container != null) {
			String parameterName = fragment.substring(slash + 1);
			if (container instanceof JvmTypeParameterDeclarator) {
				JvmTypeParameterDeclarator executable = (JvmTypeParameterDeclarator) container;
				for(JvmTypeParameter parameter: executable.getTypeParameters()) {
					if (parameter.getName().equals(parameterName))
						return parameter;
				}
			} 
		}
	} else {
		if (resource.getContents().isEmpty()) {
			if (typeResourceServices!= null) 
				typeResourceServices.outdatedStateManager.checkCanceled(resource.getResourceSet());
			if (!isEmptynessLogged) {
				isEmptynessLogged = true;
				logger.error("resource is empty: " + resource.getURI(), new IllegalStateException());
				if (logger.isDebugEnabled()) {
					logger.debug(getClass().getName(), new Exception());
				}
			}
			return null;
		}
		final EObject type = resource.getContents().get(0);
		if (type instanceof JvmType) {
			String typeName = getTypeName((JvmType) type);
			if (typeName.equals(fragment)) {
				return type;
			}
			if(fragment.startsWith(typeName)) {
				EObject member = findMember(type, fragment);
				if(member != null)
					return member;
			}
		}
	}
	return fallback.getEObject(fragment);	
}
 
Example #10
Source File: AbstractClassMirror.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected EObject getArrayEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
	JvmComponentType component = (JvmComponentType) getEObject(resource, fragment.substring(0, fragment.length() - 2), fallback);
	if (component == null)
		return null;
	return component.getArrayType();
}
 
Example #11
Source File: RefactoringTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
	return RefactoringTestLanguageFragmentProvider.class;
}
 
Example #12
Source File: XtextFragmentProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public String caseAbstractRule(AbstractRule obj, IFragmentProvider.Fallback fallback) {
	return getFragment(obj.eContainer(), fallback) + "/" + obj.getName();
}
 
Example #13
Source File: DefaultRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
	return DefaultFragmentProvider.class;
}
 
Example #14
Source File: XtextRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
	return XtextFragmentProvider.class;
}