Ejemplo n.º 1
0
 protected void addJSFile(TernDoc doc, ITernFile file) throws IOException {
   TernQuery query = doc.getQuery();
   String fileName = file.getFullName(getProject());
   query.setFile(fileName);
   TernFile tf = file.toTernServerFile(getProject());
   doc.addFile(tf);
 }
  @Override
  public void process(
      TernDoc doc,
      IJSONObjectHelper jsonObjectHelper,
      Object jsonObject,
      ITernLintCollector collector) {
    if (!(jsonObject instanceof JsonObject)) {
      // TODO: support for Rhino server
      return;
    }
    JsonArray messages = (JsonArray) ((JsonObject) jsonObject).get(MESSAGES_FIELD); // $NON-NLS-1$
    if (messages != null) {
      TernLintQuery query = (TernLintQuery) doc.getQuery();
      if (query.isGroupByFiles()) {
        JsonObject filesObject = null;
        String file = null;
        for (JsonValue files : messages) {
          filesObject = (JsonObject) files;
          file = jsonObjectHelper.getText(filesObject.get(FILE_FIELD)); // $NON-NLS-1$

          try {
            collector.startLint(file);

            JsonArray messagesFile = (JsonArray) filesObject.get(MESSAGES_FIELD); // $NON-NLS-1$
            if (messagesFile != null) {
              addMessages(jsonObjectHelper, messagesFile, query, collector);
            }
          } finally {
            collector.endLint(file);
          }
        }
      } else {
        String file = doc.getQuery().getFile();
        try {
          collector.startLint(file);
          addMessages(jsonObjectHelper, messages, query, collector);
        } finally {
          collector.endLint(file);
        }
      }
    }
  }
  @Test
  public void todoTextAfterEnd() throws TernException {

    TernDoc doc = createDocForDefinitionTodoText();
    doc.getQuery().setEnd(9);

    MockTernDefinitionCollector collector = new MockTernDefinitionCollector();
    server.request(doc, collector);

    Assert.assertNull(collector.getFile());
  }
  @Test
  public void todoTextDefinedInScopeToo() throws TernException {

    TernDoc doc = createDocForDefinitionTodoText();
    ((TernAngularDefinitionQuery) doc.getQuery()).getScope().getProps().add("todoText", "todoText");
    MockTernDefinitionCollector collector = new MockTernDefinitionCollector();
    server.request(doc, collector);

    Assert.assertNotNull(collector.getFile());
    Assert.assertEquals("myfile.js", collector.getFile());
    Assert.assertNotNull(collector.getStart());
    Assert.assertEquals(216, collector.getStart().longValue());
    Assert.assertNotNull(collector.getEnd());
    Assert.assertEquals(224, collector.getEnd().longValue());
  }
  @Test
  public void todoTextBeforeEnd() throws TernException {

    TernDoc doc = createDocForDefinitionTodoText();
    doc.getQuery().setEnd(8);

    MockTernDefinitionCollector collector = new MockTernDefinitionCollector();
    server.request(doc, collector);

    Assert.assertNotNull(collector.getFile());
    Assert.assertEquals("myfile.js", collector.getFile());
    Assert.assertNotNull(collector.getStart());
    Assert.assertEquals(216, collector.getStart().longValue());
    Assert.assertNotNull(collector.getEnd());
    Assert.assertEquals(224, collector.getEnd().longValue());
  }
Ejemplo n.º 6
0
 @Override
 public void synchronizeFile(TernDoc doc, ITernFile file) throws IOException {
   writeLock.lock();
   try {
     try {
       TernQuery query = doc.getQuery();
       if (query != null) {
         if (TernResourcesManager.isJSFile(file)) {
           addJSFile(doc, file);
           sendFiles(doc);
           return;
         } else if (TernResourcesManager.isHTMLFile(file)) {
           // This is HTML file case: never keep the file on the server
           String queryType = query.getType();
           if (TernCompletionsQuery.isQueryType(queryType)
               || TernDefinitionQuery.isQueryType(queryType)
               || query instanceof TernLintQuery) {
             addHTMLFile(doc, file);
             return;
           }
         }
       }
       TernFile tf = file.toTernServerFile(getProject());
       String oldText = sentFiles.get(tf.getName());
       if (tf.getText().equals(oldText) && !uploader.cancel(tf.getName())) {
         // no need to synchronize the file, already up-to-date
         return;
       }
       doc.addFile(tf);
     } finally {
       updateSentFiles(doc);
       // as this is
       // wait a bit for the sync to finish
       uploader.join(TIMEOUT);
     }
   } finally {
     writeLock.unlock();
   }
 }
Ejemplo n.º 7
0
 protected void addHTMLFile(TernDoc doc, ITernFile file) throws IOException {
   TernQuery query = doc.getQuery();
   TernFile tf = file.toTernServerFile(getProject());
   doc.addFile(tf);
   query.set("file", "#" + (doc.getFiles().size() - 1)); // $NON-NLS-1$ //$NON-NLS-2$
 }