/** 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)); } }
/** 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)); } }
/** 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)); } }
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(); }
/** * @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; }
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(); } }); }
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; }
/** * 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; } } }
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; }
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; }
@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)); }
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(); }
/** * 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); }
/** * 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); }
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); } }
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); } } }
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; }
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); }
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); } }
@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)); } }