org.eclipse.xtext.resource.impl.AbstractResourceDescription Java Examples

The following examples show how to use org.eclipse.xtext.resource.impl.AbstractResourceDescription. 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: ValidationJobSchedulerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IResourceDescription getResourceDescription(final URI uri) {
	return new AbstractResourceDescription() {

		@Override
		public Iterable<QualifiedName> getImportedNames() {
			return Collections.emptyList();
		}

		@Override
		public Iterable<IReferenceDescription> getReferenceDescriptions() {
			return Collections.emptyList();
		}

		@Override
		public URI getURI() {
			return uri;
		}

		@Override
		protected List<IEObjectDescription> computeExportedObjects() {
			return Collections.singletonList(EObjectDescription.create(exportedName, EcoreFactory.eINSTANCE.createEObject()));
		}
		
	};
}
 
Example #2
Source File: ValidationJobSchedulerTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	referenceDescriptions = Lists.newArrayList();
	dirtyStateManager = new DirtyStateManager();
	testMe = new ValidationJobScheduler();
	testMe.setDirtyStateManager(dirtyStateManager);
	testMe.setDescriptionUtils(new DescriptionUtils());
	testMe.setResourceDescriptions(this);
	testMe.setResourceDescriptionManager(new DefaultResourceDescriptionManager());
	DocumentTokenSource nullSource = new DocumentTokenSource() {
		@Override
		protected IRegion computeDamageRegion(DocumentEvent e) {
			return new Region(0, 0);
		}
	};
	document = new XtextDocument(nullSource, null, outdatedStateManager, operationCanceledManager) {

		@Override
		public URI getResourceURI() {
			return documentURI;
		}
		
		@Override
		public void checkAndUpdateAnnotations() {
			validationScheduled = true;
		}
	};
	documentResource = new TestableDocumentResource();
	targetResource = new AbstractResourceDescription() {
		
		@Override
		public URI getURI() {
			return targetURI;
		}
		
		@Override
		public Iterable<IReferenceDescription> getReferenceDescriptions() {
			throw new UnsupportedOperationException();
		}
		
		@Override
		public Iterable<QualifiedName> getImportedNames() {
			throw new UnsupportedOperationException();
		}
		
		@Override
		protected List<IEObjectDescription> computeExportedObjects() {
			if (documentResource.importedName == null)
				throw new UnsupportedOperationException();
			return Collections.emptyList();
		}
	};
}
 
Example #3
Source File: EObjectDescriptionBasedStubGeneratorTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test 
public void testNested() {
	final EObjectDescription _top = new EObjectDescription(QualifiedName.create("foo","Bar"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.<String,String>emptyMap());
	final EObjectDescription _nested0 = new EObjectDescription(QualifiedName.create("foo","Bar$Baz0"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
	final EObjectDescription _nested1 = new EObjectDescription(QualifiedName.create("foo","Bar$Baz1"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
	final EObjectDescription _nested10 = new EObjectDescription(QualifiedName.create("foo","Bar$Baz1$FooBar0"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
	final EObjectDescription _nested11 = new EObjectDescription(QualifiedName.create("foo","Bar$Baz1$FooBar0"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
	IResourceDescription resourceDescription = new AbstractResourceDescription( ) {
		
		@Override
		public URI getURI() {
			return null;
		}
		
		@Override
		public Iterable<IReferenceDescription> getReferenceDescriptions() {
			return Collections.emptyList();
		}
		
		@Override
		public Iterable<QualifiedName> getImportedNames() {
			return Collections.emptyList();
		}
		
		@Override
		protected List<IEObjectDescription> computeExportedObjects() {
			return Arrays.asList(new IEObjectDescription[] {_top, _nested0, _nested1, _nested10, _nested11});
		}
	};
	assertEquals("package foo;\n"
			+ "public class Bar{\n"
			+ "public static class Baz0{\n"
			+ "}\n"
			+ "public static class Baz1{\n"
			+ "public static class FooBar0{\n"
			+ "}\n"
			+ "public static class FooBar0{\n"
			+ "}\n"
			+ "}\n"
			+ "}"
			, gen.getJavaStubSource(_top, resourceDescription));
}
 
Example #4
Source File: ResourceDescriptionDeltaTest.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@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
            }
          };
        }
      });
    }
  };
}