Java 类org.eclipse.xtext.resource.IFragmentProvider 实例源码

项目:xtext-extras    文件:AbstractClassMirror.java   
@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);
}
项目:xtext-extras    文件:PrimitiveMirror.java   
@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);
}
项目:xtext-core    文件:XtextFragmentProvider.java   
@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);
    }
}
项目:xtext-core    文件:XtextFragmentProvider.java   
@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);
}
项目:dsl-devkit    文件:ExportFragment.java   
/** {@inheritDoc} */
@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
  final BindFactory bindFactory = new BindFactory();
  final String namingPrefix = GrammarUtil.getNamespace(grammar) + ".naming." + GrammarUtil.getName(grammar); //$NON-NLS-1$
  final String resourcePrefix = GrammarUtil.getNamespace(grammar) + ".resource." + GrammarUtil.getName(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");
    }
  }
  bindFactory.addTypeToType(IResourceDescription.Manager.class.getName(), resourcePrefix + "ResourceDescriptionManager"); //$NON-NLS-1$
  return bindFactory.getBindings();
}
项目:dsl-devkit    文件:AbstractSelectorFragmentProviderTest.java   
@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);
    }
  }));
}
项目:xtext-extras    文件:TypeResourceTest.java   
@Override
public EObject getEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
    assertEquals(expectedURI, resource.getURI());
    assertEquals(expectedFragment, fragment);
    return expectedObject;
}
项目:xtext-extras    文件:TypeResourceTest.java   
@Override
public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) {
    assertEquals(expectedObject, obj);
    return expectedFragment;
}
项目:xtext-extras    文件:AbstractClassMirror.java   
@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);   
}
项目:xtext-extras    文件:AbstractClassMirror.java   
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();
}
项目:xtext-core    文件:XtextFragmentProvider.java   
public String caseAbstractRule(AbstractRule obj, IFragmentProvider.Fallback fallback) {
    return getFragment(obj.eContainer(), fallback) + "/" + obj.getName();
}
项目:xtext-core    文件:DefaultRuntimeModule.java   
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
    return DefaultFragmentProvider.class;
}
项目:xtext-core    文件:XtextRuntimeModule.java   
@Override
public Class<? extends IFragmentProvider> bindIFragmentProvider() {
    return XtextFragmentProvider.class;
}