org.yaml.snakeyaml.error.Mark类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.yaml.snakeyaml.error.Mark类的一些代码示例,展示了Mark类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mark类的具体详情如下:
包路径:org.yaml.snakeyaml.error.Mark
类名称:Mark

Mark介绍

[英]It's just a record and its only use is producing nice error messages. Parser does not use it for any other purposes.
[中]这只是一条记录,它唯一的用途就是生成漂亮的错误消息。解析器不会将其用于任何其他目的。

代码示例

代码示例来源:origin: redisson/redisson

protected JsonLocation _locationFor(Mark m)
{
  if (m == null) {
    return new JsonLocation(_ioContext.getSourceReference(),
        -1, -1, -1);
  }
  return new JsonLocation(_ioContext.getSourceReference(),
      -1,
      m.getLine() + 1, // from 0- to 1-based
      m.getColumn() + 1); // ditto
}

代码示例来源:origin: redisson/redisson

public int getIndex() {
    return _source.getIndex();
  }
}

代码示例来源:origin: redisson/redisson

public String get_snippet() {
  return _source.get_snippet();
}

代码示例来源:origin: redisson/redisson

@Override
public String toString() {
  StringBuilder lines = new StringBuilder();
  if (context != null) {
    lines.append(context);
    lines.append("\n");
  }
  if (contextMark != null
      && (problem == null || problemMark == null
          || contextMark.getName().equals(problemMark.getName())
          || (contextMark.getLine() != problemMark.getLine()) || (contextMark
          .getColumn() != problemMark.getColumn()))) {
    lines.append(contextMark.toString());
    lines.append("\n");
  }
  if (problem != null) {
    lines.append(problem);
    lines.append("\n");
  }
  if (problemMark != null) {
    lines.append(problemMark.toString());
    lines.append("\n");
  }
  if (note != null) {
    lines.append(note);
    lines.append("\n");
  }
  return lines.toString();
}

代码示例来源:origin: raml-org/raml-java-parser

private static Node buildYamlErrorNode(MarkedYAMLException e, String resourcePath)
{
  final ErrorNode errorNode = new ErrorNode("Underlying error while parsing YAML syntax: '" + e.getMessage() + "'");
  final Mark problemMark = e.getProblemMark();
  errorNode.setStartPosition(new DefaultPosition(problemMark.getIndex(), problemMark.getLine(), 0, resourcePath, new DefaultResourceLoader()));
  errorNode.setEndPosition(new DefaultPosition(problemMark.getIndex() + 1, problemMark.getLine(), problemMark.getColumn(), resourcePath, new DefaultResourceLoader()));
  return errorNode;
}

代码示例来源:origin: redisson/redisson

public int getLine() {
  return _source.getLine();
}

代码示例来源:origin: com.github.sbaudoin/sonar-yaml-plugin

/**
 * Constructor
 *
 * @param content the YAML content to highlight
 * @param mark a mark to be pointed to (and certainly highlighted) in the YAML code
 */
YamlLocation(String content, Mark mark) {
  this(content, mark.getLine() + 1, mark.getColumn() + 1, mark.getPointer());
}

代码示例来源:origin: info.magnolia.core/magnolia-configuration

private static String formatYamlExceptionMessage(Resource res, YAMLException ye) {
    final StringBuilder sb = new StringBuilder();
    sb.append("YAML parsing error in ").append(res);
    if (ye instanceof MarkedYAMLException) {
      final Mark mark = ((MarkedYAMLException) ye).getProblemMark();
      final String snippet = mark != null ? mark.get_snippet() : null;
      final String problem = ((MarkedYAMLException) ye).getProblem();
      if (mark != null) {
        sb.append(" at line ").append(mark.getLine()).append(", column ").append(mark.getColumn());
      }
      if (snippet != null) {
        sb.append(":\n");
        sb.append(snippet);
      }
      if (problem != null) {
        // TODO SnakeYaml tends to be a bit nasty about this "problem", e.g org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens() prints the actual char THEN it's representation, so you end up with a big fat actual tab in the message instead of JUST \t(TAB)
        // See https://code.google.com/p/snakeyaml/issues/detail?id=209
        sb.append(": ").append(problem.replaceAll("\\s*\\t\\s*", " "));
      }
    } else {
      sb.append(": ").append(ye.getMessage());
    }

    return sb.toString();
  }
}

代码示例来源:origin: redisson/redisson

public int getColumn() {
  return _source.getColumn();
}

代码示例来源:origin: com.opentext.ia/infoarchive-yaml

public MarkedYAMLException apply(MarkedYAMLException e, String yaml) throws IOException {
 Mark problemMark = e.getProblemMark();
 Optional<YamlLine> prevLine = getLine(yaml, problemMark.getLine() - 1);
 Optional<YamlLine> line = getLine(problemMark.get_snippet(0, 100), 0);
 if (prevLine.isPresent() && line.isPresent()) {
  YamlLine prev = prevLine.get();
  YamlLine current = line.get();
  if (isIncorrectIndentation(prev, current)) {
   return incorrectIndentationException(prev, current, e);
  } else if (isItemOutsideSequence(prev, current)) {
   return itemOutsideSequence(e);
  }
 }
 return new YamlSyntaxErrorException(e.getMessage(), e);
}

代码示例来源:origin: redisson/redisson

public Mark getMark() {
  return new Mark(name, this.index, this.line, this.column, this.dataWindow, this.pointer);
}

代码示例来源:origin: org.onehippo.cms/hippo-configuration-management-model

@Override
public String toString() {
  final String sourceInfix = source != null ? source + " " : "";
  if (node == null) {
    return getClass().getName() + ": " + sourceInfix + getMessage();
  } else {
    return getClass().getName() + ": " + sourceInfix + getMessage() + node.getStartMark().toString();
  }
}

代码示例来源:origin: redisson/redisson

public String getName() {
  return _source.getName();
}

代码示例来源:origin: stackoverflow.com

txaDisplay.append("Names:"+"\t\t"+"Marks");
for (Mark mark : marks)
{
  txaDisplay.append(mark.getName()+"\t\t"+mark.getMark()+"\n");
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod
public IRubyObject mark(ThreadContext context) {
  Ruby runtime = context.runtime;
  Event event = null;
  if (parser != null) {
    event = parser.peekEvent();
    if (event == null) event = this.event;
  }
  if (event == null) {
    return ((RubyClass)context.runtime.getClassFromPath("Psych::Parser::Mark")).newInstance(
        context,
        runtime.newFixnum(0),
        runtime.newFixnum(0),
        runtime.newFixnum(0),
        Block.NULL_BLOCK
    );
  }
  Mark mark = event.getStartMark();
  return ((RubyClass)context.runtime.getClassFromPath("Psych::Parser::Mark")).newInstance(
      context,
      runtime.newFixnum(mark.getIndex()),
      runtime.newFixnum(mark.getLine()),
      runtime.newFixnum(mark.getColumn()),
      Block.NULL_BLOCK
  );
}

代码示例来源:origin: pl.droidsonroids.yaml/snakeyaml

@Override
public String toString() {
  StringBuilder lines = new StringBuilder();
  if (context != null) {
    lines.append(context);
    lines.append("\n");
  }
  if (contextMark != null
      && (problem == null || problemMark == null
          || contextMark.getName().equals(problemMark.getName())
          || (contextMark.getLine() != problemMark.getLine()) || (contextMark
          .getColumn() != problemMark.getColumn()))) {
    lines.append(contextMark.toString());
    lines.append("\n");
  }
  if (problem != null) {
    lines.append(problem);
    lines.append("\n");
  }
  if (problemMark != null) {
    lines.append(problemMark.toString());
    lines.append("\n");
  }
  if (note != null) {
    lines.append(note);
    lines.append("\n");
  }
  return lines.toString();
}

代码示例来源:origin: com.fasterxml.jackson.dataformat/jackson-dataformat-yaml

public int getLine() {
  return _source.getLine();
}

代码示例来源:origin: com.fasterxml.jackson.dataformat/jackson-dataformat-yaml

public int getColumn() {
  return _source.getColumn();
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

public Mark getMark() {
  return new Mark(name, this.line, this.column, this.dataWindow, this.pointer);
}

代码示例来源:origin: org.onehippo.cms/hippo-configuration-management-model

private NodeEvent nextNodeEvent(final Parser parser) throws ParserException {
  if (parser.checkEvent(Event.ID.Alias)) {
    final AliasEvent event = (AliasEvent) parser.getEvent();
    final String anchor = event.getAnchor();
    throw new ParserException("Encounter node alias '" + anchor +
        "' which is not supported when parsing a document head only, " + event.getStartMark().toString());
  } else {
    final NodeEvent event = (NodeEvent) parser.getEvent();
    final String anchor = event.getAnchor();
    if (anchor != null) {
      throw new ParserException("Encountered node anchor '" + anchor +
          "' which is not supported when parsing a document head only, " + event.getStartMark().toString());
    }
    return event;
  }
}

相关文章