org.eclipse.xtext.util.Strings.split()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(75)

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

Strings.split介绍

[英]Splits a string around matches of the given delimiter character.

This method works similar to String#split(String) but does not treat the delimiter as a regular expression. This makes it perform better in most cases where this feature is not necessary. Furthermore this implies that trailing empty segments will not be part of the result.
[中]围绕给定分隔符字符的匹配项拆分字符串。
此方法的工作原理类似于String#split(String),但不将分隔符视为正则表达式。这使得它在大多数不需要此功能的情况下性能更好。此外,这意味着后面的空段不会成为结果的一部分。

代码示例

代码示例来源:origin: io.sarl.lang/io.sarl.lang

/** Change the classpath.
 *
 * <p>The classpath is a list the names of folders or jar files that are separated by {@link File#pathSeparator}.
 *
 * @param classpath the new classpath.
 */
public void setClassPath(String classpath) {
  this.classpath = new ArrayList<>();
  for (final String path : Strings.split(classpath, Pattern.quote(File.pathSeparator))) {
    this.classpath.add(normalizeFile(path));
  }
}

代码示例来源:origin: io.sarl.lang/io.sarl.lang

/** Change the source path.
 *
 * <p>The source path is a list the names of folders that are separated by {@link File#pathSeparator}.
 *
 * @param sourcePath the new source path.
 */
public void setSourcePath(String sourcePath) {
  this.sourcePath = new ArrayList<>();
  for (final String path : Strings.split(sourcePath, Pattern.quote(File.pathSeparator))) {
    this.sourcePath.add(normalizeFile(path));
  }
}

代码示例来源:origin: io.sarl.lang/io.sarl.lang

/** Change the boot classpath.
 *
 * <p>The boot classpath is a list the names of folders or jar files that are separated by {@link File#pathSeparator}.
 *
 * @param bootClasspath the new boot classpath.
 */
public void setBootClassPath(String bootClasspath) {
  this.bootClasspath = new ArrayList<>();
  for (final String path : Strings.split(bootClasspath, Pattern.quote(File.pathSeparator))) {
    this.bootClasspath.add(normalizeFile(path));
  }
}

代码示例来源:origin: org.codehaus.openxma/dsl-core

protected String toEscapedString(String value) {
  List<String> segments = Strings.split(value, ".");
  StringBuilder builder = new StringBuilder();
  boolean isFirst = true;
  for (String segment : segments) {
    if (!isFirst)
      builder.append(".");
    isFirst = false;
    if (mustEscape(segment))
      builder.append("^");
    builder.append(segment);
  }
  return builder.toString();
}

代码示例来源:origin: org.eclipse/xtext

/**
 * @since 2.4
 */
public INode getNode(EObject object, String fragment) {
  List<String> split = Strings.split(fragment, LazyURIEncoder.SEP);
  INode compositeNode = NodeModelUtils.getNode(object);
  if (compositeNode == null)
    throw new IllegalStateException("Couldn't resolve lazy link, because no node model is attached.");
  INode node = getNode(compositeNode, split.get(3));
  return node;
}

代码示例来源:origin: org.eclipse.xtend/org.eclipse.xtend.core

protected List<String> getDirectories(String path) {
  if (Strings.isEmpty(path)) {
    return Lists.newArrayList();
  }
  final List<String> split = split(emptyIfNull(path), File.pathSeparator);
  return transform(split, new Function<String, String>() {
    @Override
    public String apply(String from) {
      return new File(new File(from).getAbsoluteFile().toURI().normalize()).getAbsolutePath();
    }
  });
}

代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.common.types

private JvmType doTryFindInIndex(String name, IndexedJvmTypeAccess indexAccess) throws UnknownNestedTypeException {
  int index = name.indexOf('$');
  if (index < 0)
    index = name.indexOf('[');
  String qualifiedNameString = index < 0 ? name : name.substring(0, index);
  List<String> nameSegments = Strings.split(qualifiedNameString, '.');
  QualifiedName qualifiedName = QualifiedName.create(nameSegments);
  EObject candidate = indexAccess.getIndexedJvmType(qualifiedName, name, getResourceSet());
  if (candidate instanceof JvmType)
    return (JvmType) candidate;
  return null;
}

代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.xbase

/**
   * Returns decoded delegation key or <code>null</code> if encodedValue can not be parsed.
   * @return {@link Pair} where getFirst() is delegationKey and getSecond() is the defaultSeverity.
   * @see XbaseSeverityConverter#encodeDefaultSeverity(String, String)
   */
  public static Pair<String, String> decodeDelegationKey(String encodedValue) {
    List<String> split = Strings.split(encodedValue, DEFAULT_SEVERITY_SEPARATOR);
    if (split.size() == 2) {
      return Tuples.create(split.get(0), split.get(1));
    } else if (split.size() == 1) {
      return Tuples.create(split.get(0), SeverityConverter.SEVERITY_WARNING);
    } else {
      return null;
    }
  }
}

代码示例来源:origin: org.eclipse.xtext.common/types

private JvmType doTryFindInIndex(String name, IndexedJvmTypeAccess indexAccess) {
  int index = name.indexOf('$');
  if (index < 0)
    index = name.indexOf('[');
  String qualifiedNameString = index < 0 ? name : name.substring(0, index);
  List<String> nameSegments = Strings.split(qualifiedNameString, '.');
  QualifiedName qualifiedName = QualifiedName.create(nameSegments);
  EObject candidate = indexAccess.getIndexedJvmType(qualifiedName, name, getResourceSet());
  if (candidate instanceof JvmType)
    return (JvmType) candidate;
  return null;
}

代码示例来源:origin: org.eclipse/xtext

public EObject resolveShortFragment(Resource res, String shortFragment) {
  List<String> split = Strings.split(shortFragment, '.');
  int contentsIdx = Integer.parseInt(split.get(0));
  EObject result = res.getContents().get(contentsIdx);
  int splitIdx = 1;
  while(splitIdx < split.size()) {
    int featureId = Integer.parseInt(split.get(splitIdx++));
    EReference reference = (EReference) result.eClass().getEStructuralFeature(featureId);
    if (reference.isMany()) {
      List<?> list = (List<?>) result.eGet(reference);
      int listIdx = Integer.parseInt(split.get(splitIdx++));
      result = (EObject) list.get(listIdx);
    } else {
      result = (EObject) result.eGet(reference);
    }
  }
  return result;
}

代码示例来源:origin: org.eclipse.xtend/org.eclipse.xtend.core

@Override
protected void doGetDescriptions(JvmType type, JvmType declarator, int index, List<IEObjectDescription> result) {
  String typeName = type.getQualifiedName('.');
  String declaratorName = declarator.getQualifiedName('.');
  int declaratorLength = declaratorName.length();
  String subName = typeName.substring(declaratorLength + 1);
  List<String> segments = Strings.split(subName, '.');
  result.add(EObjectDescription.create(QualifiedName.create(segments), type));
  result.add(EObjectDescription.create(subName.replace('.', '$'), type));
}

代码示例来源:origin: org.eclipse/xtext

public String toString(String value) {
  StringBuilder buffer = new StringBuilder();
  boolean isFirst = true;
  for (String segment : Strings.split(value, getValueNamespaceDelimiter())) {
    if (!isFirst)
      buffer.append(getStringNamespaceDelimiter());
    isFirst = false;
    if(getWildcardLiteral().equals(segment)) {
      buffer.append(getWildcardLiteral());
    } else {
      buffer.append(delegateToString(segment));
    }
  }
  return buffer.toString();
}

代码示例来源:origin: org.eclipse/xtext

/**
 * decodes the uriFragment
 * 
 * @param res the resource that contains the feature holder
 * @param uriFragment the fragment that should be decoded
 * @return the decoded information
 * @see LazyURIEncoder#encode(EObject, EReference, INode)
 */
public Triple<EObject, EReference, INode> decode(Resource res, String uriFragment) {
  List<String> split = Strings.split(uriFragment, SEP);
  EObject source = resolveShortFragment(res, split.get(1));
  EReference ref = fromShortExternalForm(source.eClass(), split.get(2));
  INode compositeNode = NodeModelUtils.getNode(source);
  if (compositeNode==null)
    throw new IllegalStateException("Couldn't resolve lazy link, because no node model is attached.");
  INode textNode = getNode(compositeNode, split.get(3));
  return Tuples.create(source, ref, textNode);
}

代码示例来源:origin: org.eclipse/xtext

/**
 * Splits the given string into segments and returns them as a {@link QualifiedName}.
 * 
 * @exception IllegalArgumentException
 *                if the input is empty or null.
 */
public QualifiedName toQualifiedName(String qualifiedNameAsString) {
  if (qualifiedNameAsString == null)
    throw new IllegalArgumentException("Qualified name cannot be null");
  if (qualifiedNameAsString.equals(""))
    throw new IllegalArgumentException("Qualified name cannot be empty");
  if (Strings.isEmpty(getDelimiter()))
    return QualifiedName.create(qualifiedNameAsString);
  List<String> segs = getDelimiter().length() == 1 ? Strings.split(qualifiedNameAsString, getDelimiter()
      .charAt(0)) : Strings.split(qualifiedNameAsString, getDelimiter());
  return QualifiedName.create(segs);
}

代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.xbase

protected void addDescriptions(JvmDeclaredType type, JvmType declarator, List<IEObjectDescription> result) {
  String typeName = type.getQualifiedName('.');
  String declaratorName = declarator.getQualifiedName('.');
  int declaratorLength = declaratorName.length();
  String subName = typeName.substring(declaratorLength + 1);
  List<String> segments = Strings.split(subName, '.');
  result.add(EObjectDescription.create(QualifiedName.create(segments), type));
  result.add(EObjectDescription.create(subName.replace('.', '$'), type));
  for(JvmDeclaredType nestedType: type.getAllNestedTypes()) {
    addDescriptions(nestedType, declarator, result);
  }
}

代码示例来源:origin: org.eclipse.elk/org.eclipse.elk.graph.text

private String quoteIfNecessary(final String s) {
 try {
  final QualifiedName qname = QualifiedName.create(Strings.split(s, ElkGraphQualifiedNameConverter.DELIMITER));
  return this.qualifiedNameConverter.toString(qname);
 } catch (final Throwable _t) {
  if (_t instanceof ValueConverterException) {
   final ValueConverterException e = (ValueConverterException)_t;
   return (("\"" + s) + "\"");
  } else {
   throw Exceptions.sneakyThrow(_t);
  }
 }
}

代码示例来源:origin: org.eclipse.xtend/org.eclipse.xtend.core

protected JvmType findNestedType(JvmType result, int index, QualifiedName name) {
  List<String> segments = name.getSegmentCount() == 1 ? Strings.split(name.getFirstSegment(), '$') : name.getSegments();
  for(int i = 1; i < segments.size() && result instanceof JvmDeclaredType; i++) {
    JvmDeclaredType declaredType = (JvmDeclaredType) result;
    String simpleName = segments.get(i);
    // TODO handle ambiguous types
    for(JvmMember member: declaredType.findAllNestedTypesByName(simpleName)) {
      result = (JvmType) member;
      break;
    }
    if (declaredType == result) {
      return null;
    }
  }
  return result;
}

代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.xtext.generator

protected void normalizeTokens(final IXtextGeneratorFileSystemAccess fsa, final String tokenFile) {
 String content = fsa.readTextFile(tokenFile).toString();
 content = this.newLineNormalizer.postProcess(fsa.getURI(tokenFile), content).toString();
 final List<String> splitted = Strings.split(content, this.codeConfig.getLineDelimiter());
 Collections.<String>sort(splitted);
 String _concat = Strings.concat(this.codeConfig.getLineDelimiter(), splitted);
 String _lineDelimiter = this.codeConfig.getLineDelimiter();
 String _plus = (_concat + _lineDelimiter);
 content = _plus;
 fsa.generateFile(tokenFile, content);
}

代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.common.types

private JvmType doFindTypeByName(String name) {
  try {
    // seems to be the only reliable way to locate nested types
    // since dollar signs are a quite good indicator but not necessarily the best
    BinaryClass clazz = findClassByName(name);
    return findTypeByClass(clazz);
  } catch (ClassNotFoundExceptionWithBaseName e) {
    String outerName = e.getBaseName();
    JvmType outer = doFindTypeByName(outerName);
    if (outer instanceof JvmDeclaredType) {
      String nestedNames = name.substring(outerName.length() + 1);
      List<String> segments = Strings.split(nestedNames, ".");
      return findNestedType((JvmDeclaredType) outer, segments, 0);
    }
    return null;
  } catch (ClassNotFoundException e) {
    return tryFindTypeInIndex(name, false);
  }
}

代码示例来源:origin: org.eclipse.xtend/org.eclipse.xtend.core

@Override
protected void doGetDescriptions(JvmType type, JvmType knownType, int index, List<IEObjectDescription> result) {
  if (type == knownType) {
    result.add(EObjectDescription.create(QualifiedName.create(type.getSimpleName()), type));
  } else if (type.eContainer() == knownType) {
    result.add(EObjectDescription.create(QualifiedName.create(knownType.getSimpleName(), type.getSimpleName()), type));
    result.add(EObjectDescription.create(QualifiedName.create(knownType.getSimpleName() + '$' + type.getSimpleName()), type));
  } else {
    String knownTypeName = knownType.getQualifiedName();
    String withDollar = type.getQualifiedName('$');
    String withDot = type.getQualifiedName('.');
    result.add(EObjectDescription.create(QualifiedName.create(Strings.split(withDot.substring(knownTypeName.length()), '.')), type));
    result.add(EObjectDescription.create(QualifiedName.create(withDollar.substring(knownTypeName.length())), type));
  }
}

相关文章