Java 类org.eclipse.xtext.resource.impl.AbstractResourceDescription 实例源码

项目:dsl-devkit    文件:ResourceDescriptionDeltaTest.java   
@SuppressWarnings("PMD.CyclomaticComplexity")
private IResourceDescription createDescriptionWithFingerprints(final String... fragmentsAndFingerprints) {
  final URI resourceURI = URI.createURI("foo:/foo.foo");
  return new AbstractResourceDescription() {

    public Iterable<QualifiedName> getImportedNames() {
      return ImmutableSet.of();
    }

    public Iterable<IReferenceDescription> getReferenceDescriptions() {
      return ImmutableSet.of();
    }

    public URI getURI() {
      return resourceURI;
    }

    @Override
    protected List<IEObjectDescription> computeExportedObjects() {
      return Lists.transform(Lists.newArrayList(fragmentsAndFingerprints), new Function<String, IEObjectDescription>() {
        public IEObjectDescription apply(final String from) {
          final String fragment = from.split(":")[0];
          final String fingerprint = from.indexOf(':') != -1 ? from.split(":")[1] : from;
          return new AbstractEObjectDescription() {

            public QualifiedName getQualifiedName() {
              return QualifiedName.create(fragment);
            }

            public QualifiedName getName() {
              return getQualifiedName();
            }

            public URI getEObjectURI() {
              return resourceURI.appendFragment(fragment);
            }

            public EObject getEObjectOrProxy() {
              return null;
            }

            public EClass getEClass() {
              return null;
            }

            @Override
            public String[] getUserDataKeys() {
              return new String[] {IFingerprintComputer.OBJECT_FINGERPRINT};
            }

            @Override
            public String getUserData(final String name) {
              return name.equals(IFingerprintComputer.OBJECT_FINGERPRINT) ? Integer.toString(fingerprint.hashCode()) : null; // NOPMD
            }
          };
        }
      });
    }
  };
}