Java源码示例:org.eclipse.xtext.resource.IFragmentProvider
示例1
@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);
}
示例2
@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);
}
示例3
@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);
}
}
示例4
@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);
}
示例5
/** {@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();
}
示例6
@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);
}
}));
}
示例7
@Override
public EObject getEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
assertEquals(expectedURI, resource.getURI());
assertEquals(expectedFragment, fragment);
return expectedObject;
}
示例8
@Override
public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) {
assertEquals(expectedObject, obj);
return expectedFragment;
}
示例9
@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);
}
示例10
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();
}
示例11
@Override
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
return RefactoringTestLanguageFragmentProvider.class;
}
示例12
public String caseAbstractRule(AbstractRule obj, IFragmentProvider.Fallback fallback) {
return getFragment(obj.eContainer(), fallback) + "/" + obj.getName();
}
示例13
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
return DefaultFragmentProvider.class;
}
示例14
@Override
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
return XtextFragmentProvider.class;
}