示例#1
0
 protected boolean validate(final Resource resource) {
   URI _uRI = resource.getURI();
   IResourceServiceProvider _resourceServiceProvider =
       this.context.getResourceServiceProvider(_uRI);
   final IResourceValidator resourceValidator = _resourceServiceProvider.getResourceValidator();
   boolean _equals = Objects.equal(resourceValidator, null);
   if (_equals) {
     return true;
   }
   URI _uRI_1 = resource.getURI();
   String _lastSegment = _uRI_1.lastSegment();
   String _plus = ("Starting validation for input: \'" + _lastSegment);
   String _plus_1 = (_plus + "\'");
   IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.info(_plus_1);
   final List<Issue> validationResult =
       resourceValidator.validate(resource, CheckMode.ALL, null);
   BuildRequest.IPostValidationCallback _afterValidate = this.request.getAfterValidate();
   URI _uRI_2 = resource.getURI();
   return _afterValidate.afterValidate(_uRI_2, validationResult);
 }
示例#2
0
  private void compileResource(String fileName) {
    // get instances
    Injector injector = new DeltaJStandaloneSetup().createInjectorAndDoEMFRegistration();
    ResourceSet set = injector.getInstance(ResourceSet.class);
    validator = injector.getInstance(IResourceValidator.class);
    fileAccess = injector.getInstance(JavaIoFileSystemAccess.class);
    generator = injector.getInstance(IGenerator.class);

    Resource resource = set.getResource(URI.createURI(getUriPrefix() + fileName), true);

    // validate the resource for syntax errors
    issueList = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);

    // generate
    fileAccess.setOutputPath(this.outputPath);
    generator.doGenerate(resource, fileAccess);
  }
示例#3
0
文件: Main.java 项目: ceefour/glproto
  protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
      for (Issue issue : list) {
        System.err.println(issue);
      }
      return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
  }
示例#4
0
  public boolean runGenerator(String inputPath, Metadata metadata, String outputPath) {

    // load the resource
    resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    Resource resource = resourceSet.getResource(URI.createFileURI(inputPath), true);

    if (metadata != null) {
      Map<String, Object> entitiesMap = new HashMap<String, Object>();
      for (State key :
          Iterables.<State>filter(
              IteratorExtensions.<EObject>toIterable(resource.getAllContents()), State.class)) {
        String entity = key.getEntity().getName();
        if (StringUtils.isNotEmpty(entity)) {
          try {
            EntityMetadata em = metadata.getEntityMetadata(entity);
            if (null != em) {
              Map<String, Object> entityPropMap = new HashMap<String, Object>();
              for (String propertySimple : em.getTopLevelProperties()) {
                if (!em.isPropertyList(propertySimple)) {

                  ArrayList<String> obj = new ArrayList<String>();

                  String propertyName = em.getSimplePropertyName(propertySimple);

                  if (em.isPropertyNumber(propertySimple)) {
                    obj.add(0, "double");
                  } else if (em.isPropertyDate(propertySimple)) {
                    obj.add(0, "date");
                  } else if (em.isPropertyTime(propertySimple)) {
                    obj.add(0, "dateTime");
                  } else if (em.isPropertyBoolean(propertySimple)) {
                    obj.add(0, "boolean");
                  } else {
                    obj.add(0, "string");
                  }

                  String description = em.getTermValue(propertySimple, "TERM_DESCRIPTION");
                  description = (null != description) ? description : "";
                  obj.add(1, description);

                  entityPropMap.put(propertyName, obj);

                } else {
                  String propertyName = em.getSimplePropertyName(propertySimple);
                  entityPropMap.put(propertyName, complexTypeHandler(propertySimple, em));
                }
              }
              entitiesMap.put(entity, entityPropMap);
            }
          } catch (Exception e) {
            System.out.println("Entity Not found: " + entity);
          }
        }
      }
      resource.getResourceSet().getLoadOptions().put("Metadata", entitiesMap);
    }

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
      for (Issue issue : list) {
        listener.notify(issue.toString());
      }

      return false;
    }

    // configure and start the generator
    fileAccess.setOutputPath(outputPath);
    generator.doGenerate(resource, fileAccess);

    return true;
  }
示例#5
0
 public List<Issue> getValidationIssues(EObject model) {
   IResourceValidator validator =
       ((XtextResource) model.eResource()).getResourceServiceProvider().getResourceValidator();
   return validator.validate(model.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
 }