Examples of XtextResource


Examples of org.eclipse.xtext.resource.XtextResource

    try {
      Lexer lexer = new Lexer(input);
      tokens = lexer.tokenizeToStrings();
      InputStream in = getAsStream("" + input);
      URI uri = URI.createURI("mytestmodel." + getCurrentFileExtension());
      XtextResource resource = doGetResource(in, uri);
      parseResult = getModel(resource);
      errors = resource.getErrors();
      warnings = resource.getWarnings();
      if (errorCount == 0)
        assertEquals("Errors: " + errors, 0, errors.size());
      else if (errorCount > 0)
        assertTrue("No errors", errors.size() > 0);         
      if (warningCount >= 0) {       
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

    this.importUri = importUri;
    this.nodes = nodes;
    addOptionTypes();
    InputStreamReader reader = null;
    try {
      resource = new XtextResource(location);
      reader = new InputStreamReader(contents(location), UTF_8);
      IParseResult result = parser.parse(reader);
      root = (Protobuf) result.getRootASTElement();
      resource.getContents().add(root);
      resolveLazyCrossReferences(resource, NullImpl);
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

    FileStoreEditorInput input = supportedEditorInputType().cast(element);
    File file = new File(input.getURI());
    try {
      String contents = contentsOf(file);
      document.set(contents);
      XtextResource resource = resourceFactory.createResource(file.toURI().toString(), contents);
      document.setInput(resource);
    } catch (Throwable t) {
      throw new CoreException(error(t));
    }
  }
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

    UriEditorInput input = supportedEditorInputType().cast(element);
    URI uri = input.getFileUri();
    try {
      String contents = contentsOf(uri);
      document.set(contents);
      XtextResource resource = resourceFactory.createResource(uri, contents);
      document.setInput(resource);
    } catch (Throwable t) {
      throw new CoreException(error(t));
    }
  }
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

    this.injector = injector;
  }

  public IParseResult parseText(String text) {
    boolean ignoreSyntaxErrors = shouldIgnoreSyntaxErrorsIn(text);
    XtextResource resource = createResourceFrom(new StringInputStream(text));
    IParseResult parseResult = resource.getParseResult();
    if (ignoreSyntaxErrors || !parseResult.hasSyntaxErrors()) {
      return parseResult;
    }
    StringBuilder builder = new StringBuilder();
    builder.append("Syntax errors:");
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

  }

  private XtextResource createResourceFrom(InputStream input, URI uri) {
    XtextResourceSet resourceSet = getInstanceOf(XtextResourceSet.class);
    resourceSet.setClasspathURIContext(getClass());
    XtextResource resource = (XtextResource) getInstanceOf(IResourceFactory.class).createResource(uri);
    resourceSet.getResources().add(resource);
    try {
      resource.load(input, null);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    if (resource instanceof LazyLinkingResource) {
      ((LazyLinkingResource) resource).resolveLazyCrossReferences(NullImpl);
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

  // syntax = "proto2";
  // package com.google.proto;
  //
  // message Person {}
  @Test public void should_find_resource_if_URIs_are_exact_match() {
    XtextResource resource = xtext.resource();
    addToXtextIndex(resource);
    URI resourceUri = resource.getURI();
    IPath path = Path.fromOSString(resourceUri.path());
    IResourceDescription description = lookup.resourceIn(path);
    assertThat(description.getURI(), equalTo(resourceUri));
  }
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

  // syntax = "proto2";
  // package com.google.proto;
  //
  // message Person {}
  @Test public void should_find_resource_matching_segments_if_URIs_are_not_exact_match() {
    XtextResource resource = xtext.resource();
    addToXtextIndex(resource);
    URI resourceUri = resource.getURI();
    String[] segments = resourceUri.segments();
    int segmentCount = segments.length;
    String path = segments[segmentCount - 2] + "/" + segments[segmentCount - 1]; // last two segments.
    IResourceDescription description = lookup.resourceIn(Path.fromOSString(path));
    assertThat(description.getURI(), equalTo(resourceUri));
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

  // syntax = "proto2";
  // package com.google.proto;
  //
  // message Person {}
  @Test public void should_return_null_if_matching_URI_was_not_found() {
    XtextResource resource = xtext.resource();
    addToXtextIndex(resource);
    IResourceDescription description = lookup.resourceIn(Path.fromOSString("some/crazy/path"));
    assertNull(description);
  }
View Full Code Here

Examples of org.eclipse.xtext.resource.XtextResource

   * @throws IOException if something goes wrong.
   */
  public XtextResource createResource(URI uri, String contents) throws IOException {
    // TODO get project from URI.
    ResourceSet resourceSet = resourceSetProvider.get(projects.activeProject());
    XtextResource resource = (XtextResource) resourceSet.createResource(uri, UNSPECIFIED_CONTENT_TYPE);
    resource.load(new StringInputStream(contents), singletonMap(OPTION_ENCODING, UTF_8));
    resolveLazyCrossReferences(resource, NullImpl);
    return resource;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.