List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.dulion.astatium.mesh.shredder.ContextManager.java
private void logTree() { String space = Strings.repeat(" ", 40); Context[] array = new Context[contextMap.size()]; contextMap.values().toArray(array);/* w w w .j a v a 2s . c om*/ sort(array, Context.byContext()); int maxSize = 0; for (Context context : array) { Location location = context.getRange().getLower(); BigInteger numerator = ((RationalLocation) location).getNumerator(); String num = Base64.getEncoder().encodeToString(numerator.toByteArray()); int numSize = numerator.bitLength() / 8 + 1; if (numSize > maxSize) { maxSize = numSize; } BigInteger denominator = ((RationalLocation) location).getDenominator(); String den = Base64.getEncoder().encodeToString(denominator.toByteArray()); int denSize = denominator.bitLength() / 8 + 1; if (denSize > maxSize) { maxSize = denSize; } int depth = context.getDepth() - 1; String indent = space.substring(0, depth << 1); LOG.info(String.format("[%15s|%15s]%s", num, den, indent + context.getName())); } LOG.info("Max byte size: {}", maxSize); }
From source file:org.rf.ide.core.executor.RobotCommandDirectExecutor.java
@Override public Optional<File> getModulePath(final String moduleName, final EnvironmentSearchPaths additionalPaths) { try {// ww w . jav a2 s. com final File scriptFile = RobotRuntimeEnvironment.copyScriptFile("red_modules.py"); final List<String> cmdLine = createCommandLine(scriptFile, additionalPaths, "-modulename", moduleName); if (additionalPaths.hasPythonPaths()) { cmdLine.add(String.join(";", additionalPaths.getExtendedPythonPaths(interpreterType))); } final List<String> lines = new ArrayList<>(); RobotRuntimeEnvironment.runExternalProcess(cmdLine, line -> lines.add(line)); if (lines.size() == 1) { // there should be a single line with path only return Optional.of(new File(lines.get(0).toString())); } else { final String indent = Strings.repeat(" ", 12); final String exception = indent + String.join("\n" + indent, lines); throw new RobotEnvironmentException( "RED python session problem. Following exception has been thrown by python service:\n" + exception); } } catch (final IOException e) { throw new RobotEnvironmentException("Unable to find path of '" + moduleName + "' module", e); } }
From source file:com.google.security.zynamics.zylib.gui.JStackView.JStackPanel.java
/** * Highlights the address of the stack pointer. * /* ww w.j ava 2s .c o m*/ * @param g The graphics context to draw to. * @param row Row where the stack pointer is shown. */ private void highlightStackPointer(final Graphics g, final int row) { g.setColor(Color.RED); final double width = g.getFontMetrics().getStringBounds(Strings.repeat("0", 2 * getElementSize()), g) .getWidth(); g.fillRect(PADDING_LEFT - 2 - (m_charWidth * m_firstColumn), (m_paddingTop + (row * m_rowHeight)) - m_charHeight, (int) width + 4, m_charHeight + 2); }
From source file:com.google.googlejavaformat.java.StringWrapper.java
/** * Reflows the given source text, trying to split on word boundaries. * * @param separator the line separator// w w w.j av a 2s . co m * @param columnLimit the number of columns to wrap at * @param startColumn the column position of the beginning of the original text * @param trailing extra space to leave after the last line * @param components the text to reflow * @param first0 true if the text includes the beginning of its enclosing concat chain, i.e. a */ private static String reflow(String separator, int columnLimit, int startColumn, int trailing, ImmutableList<String> components, boolean first0) { // We have space between the start column and the limit to output the first line. // Reserve two spaces for the quotes. int width = columnLimit - startColumn - 2; Deque<String> input = new ArrayDeque<>(components); List<String> lines = new ArrayList<>(); boolean first = first0; while (!input.isEmpty()) { int length = 0; List<String> line = new ArrayList<>(); if (input.stream().mapToInt(x -> x.length()).sum() <= width) { width -= trailing; } while (!input.isEmpty() && (length <= 4 || (length + input.peekFirst().length()) < width)) { String text = input.removeFirst(); line.add(text); length += text.length(); if (text.endsWith("\\n") || text.endsWith("\\r")) { break; } } if (line.isEmpty()) { line.add(input.removeFirst()); } // add the split line to the output, and process whatever's left lines.add(String.join("", line)); if (first) { width -= 6; // subsequent lines have a four-space continuation indent and a `+ ` first = false; } } return lines.stream().collect(joining( "\"" + separator + Strings.repeat(" ", startColumn + (first0 ? 4 : -2)) + "+ \"", "\"", "\"")); }
From source file:com.github.x3333.dagger.aop.internal.InterceptorGenerator.java
/** * Generate the Interceptor for the {@link TypeElement superClassElement} using {@link MethodBind methodBinds}. * /* w w w. j a va2 s. c om*/ * @param superClassElement Element with method(s) annotated by some annotation. * @param methodBinds Method binds inside this <code>superClassElement</code>. * @return Generated TypeSpec. */ TypeSpec generateInterceptor(final TypeElement superClassElement, final Collection<MethodBind> methodBinds) { final ClassName superClassElementName = ClassName.get(superClassElement); final String interceptorName = INTERCEPTOR_CLASS_PREFIX + Joiner.on("_").join(superClassElementName.simpleNames()); final TypeSpec.Builder classBuilder = TypeSpec.classBuilder(interceptorName) // .addOriginatingElement(superClassElement) // .superclass(ClassName.get(superClassElement)) // .addAnnotation(Sources.generatedAnnotation(InterceptorProcessor.class)) // .addAnnotations(toSpec(superClassElement.getAnnotationMirrors())) // .addModifiers(PUBLIC, FINAL); // Constructor ExecutableElement constructorElement = null; for (final Element el : superClassElement.getEnclosedElements()) { if (el.getKind() == CONSTRUCTOR) { constructorElement = MoreElements.asExecutable(el); break; } } final MethodSpec.Builder constructor; if (constructorElement == null) { constructor = MethodSpec.constructorBuilder().addModifiers(PUBLIC); } else { constructor = cloneConstructor(constructorElement); } constructor.addAnnotation(Inject.class); final CodeBlock.Builder constructorCode = CodeBlock.builder(); // Start Annotation Cache statements. final CodeBlock.Builder annotationsCode = CodeBlock.builder(); final List<Class<? extends Annotation>> interceptorsCreated = new ArrayList<>(); final CodeBlock.Builder staticAnnotationsCacheCode = CodeBlock.builder()// .add("try {\n").indent(); // Methods for (final MethodBind methodBind : methodBinds) { final ExecutableElement methodElement = methodBind.getMethodElement(); final ImmutableList<Class<? extends Annotation>> annotations = methodBind.getAnnotations(); final TypeMirror returnType = methodElement.getReturnType(); final boolean hasReturnValue = returnType.getKind() != VOID; // proceedCall final String methodName = methodElement.getSimpleName().toString(); final Iterable<String> parameterNames = simpleNames(methodElement.getParameters()); final String joinedParameterNames = Joiner.on(", ").join(parameterNames); // proceedMethod final String proceedMethodModifier = hasReturnValue ? "public" : "protected"; final String proceedMethodName = hasReturnValue ? "proceed" : "noReturnProceed"; // interceptorInvoke final String interceptorInvokePrefix = hasReturnValue ? "return " : ""; // FIXME: We must add Parameters to the name or a number, so overloaded methods doesn't collide. final String annotationsFieldName = methodName + ANNOTATIONS_CACHE_SUFFIX; final String methodCacheFieldName = methodName + METHOD_CACHE_SUFFIX; // tryBlock final CodeBlock.Builder tryBlock = CodeBlock.builder()// .add("try {\n") // .indent(); // proceedCall CodeBlock lastInvoke = CodeBlock.builder().addStatement("$L$L.super.$L($L)", // interceptorInvokePrefix, interceptorName, // methodName, // joinedParameterNames).build(); // Process Annotations for (int i = 0; i < annotations.size(); i++) { final Class<? extends Annotation> annotation = annotations.get(i); final InterceptorHandler handler = this.services.get(annotation); final Class<? extends MethodInterceptor> handlerClass = handler.methodInterceptorClass(); final String interceptorFieldName = "$interceptor" + annotation.getSimpleName(); if (!interceptorsCreated.contains(annotation)) { final TypeName handlerTypeName = TypeName.get(handlerClass); classBuilder.addField(handlerTypeName, interceptorFieldName, PRIVATE, FINAL); constructor.addParameter(handlerTypeName, interceptorFieldName, FINAL); constructorCode.addStatement("this.$L = $L", interceptorFieldName, interceptorFieldName); interceptorsCreated.add(annotation); } final CodeBlock invokeMethod = createInvokeMethod(returnType, proceedMethodModifier, proceedMethodName, lastInvoke); lastInvoke = createInterceptorInvoke(returnType, interceptorFieldName, interceptorName, methodCacheFieldName, annotationsFieldName, invokeMethod); } tryBlock.add(lastInvoke).unindent(); final List<? extends TypeMirror> thrownTypes = methodElement.getThrownTypes(); for (final TypeMirror thrownType : thrownTypes) { tryBlock.add("} catch ($T e) {\n", thrownType).indent()// .addStatement("throw e").unindent(); } tryBlock.add("} catch (RuntimeException e) {\n").indent()// .addStatement("throw e").unindent()// .add("} catch (Throwable e) {\n").indent()// .addStatement("throw new RuntimeException(e)").unindent()// .add("}\n"); final CodeBlock argumentsBlock = CodeBlock.builder()// .addStatement("final $T[] arguments = new $T[] { $L }", Object.class, Object.class, joinedParameterNames)// .build(); final MethodSpec method = cloneMethod(MoreElements.asExecutable(methodElement))// .addAnnotation(Override.class)// .addCode(argumentsBlock)// .addCode(tryBlock.build())// .build(); classBuilder.addMethod(method); // Method Cache Field classBuilder.addField(// TypeName.get(Method.class), // methodCacheFieldName, // PRIVATE, // STATIC, // FINAL); // Method Annotations Cache Field classBuilder.addField(// ParameterizedTypeName.get(List.class, Annotation.class), // annotationsFieldName, // PRIVATE, // STATIC, // FINAL); // Method Annotations Cache Statements final List<TypeName> parametersTypes = Lists.transform(methodElement.getParameters(), p -> TypeName.get(p.asType())); final CodeBlock parameters = parametersTypes.size() == 0 ? // CodeBlock.of("") // : CodeBlock.builder().add(// Strings.repeat(", $T.class", parametersTypes.size()), parametersTypes.toArray()) .build(); staticAnnotationsCacheCode// .addStatement("$L = $L.class.getSuperclass().getDeclaredMethod($S$L)", // methodCacheFieldName, // interceptorName, // methodName, parameters)// .addStatement("$L = $T.asList($L.getAnnotations())", // annotationsFieldName, // Arrays.class, // methodCacheFieldName); } constructorCode// .add(annotationsCode.build()); staticAnnotationsCacheCode.unindent()// .add("} catch (NoSuchMethodException | SecurityException e) {\n").indent()// .addStatement("throw new RuntimeException(e)").unindent()// .add("}\n"); constructor.addCode(constructorCode.build()); classBuilder.addStaticBlock(staticAnnotationsCacheCode.build()); // Add constructor at the end so methods can create the annotation cache. classBuilder.addMethod(constructor.build()); return classBuilder.build(); }
From source file:com.google.dart.tools.ui.dialogs.UpdateStatusControl.java
private String padToMatch(String original, String toMatch) { int pad = toMatch.length() - original.length(); if (pad > 0) { return original.concat(Strings.repeat(" ", pad + 5)); }//from ww w . j a v a 2 s . com return original; }
From source file:cz.afri.smg.graphs.SMGObjectNode.java
private String newLineWithOffset(final String pLine) { return Strings.repeat(" ", offset) + pLine + "\n"; }
From source file:com.google.auto.value.processor.AutoValueProcessor.java
private String generatedSubclassName(TypeElement type, int depth) { return generatedClassName(type, Strings.repeat("$", depth) + "AutoValue_"); }
From source file:org.decojer.cavaj.model.code.structs.Struct.java
@Override public String toString() { // calculate prefix from parent indentation level String parentStr;//w ww .j a va2 s . c om String prefix; final Struct parent = getParent(); if (parent == null) { parentStr = null; prefix = ""; } else { parentStr = parent.toString(); prefix = " "; for (int i = 0; i < parentStr.length(); ++i) { if (parentStr.charAt(i) != ' ') { prefix += Strings.repeat(" ", i); break; } } } final StringBuilder sb = new StringBuilder(); sb.append(prefix).append("--- ").append(getClass().getSimpleName()).append(" ---\n"); final String label = getLabel(); if (label != null) { sb.append(prefix).append("Label: ").append(label).append('\n'); } sb.append(prefix).append("Head: BB ").append(getHead().getPc()); final BB follow = getFollow(); if (follow != null) { sb.append(" Follow: BB ").append(follow.getPc()); } sb.append('\n').append(prefix).append("Members: "); int i = 0; for (final Entry<Object, List<BB>> entry : this.value2members.entrySet()) { sb.append("\n ").append(prefix); if (i++ > 5) { sb.append(this.value2members.size()).append(" switches"); break; } if (entry.getKey() != null) { sb.append(entry.getKey() instanceof Object[] ? Arrays.toString((Object[]) entry.getKey()) : entry.getKey()).append(": "); } if (entry.getValue().size() > 20) { sb.append(entry.getValue().size()).append(" BBs"); continue; } for (final BB bb : entry.getValue()) { sb.append("BB ").append(bb.getPc()).append(" "); } } final String special = toStringSpecial(prefix); if (special != null) { sb.append('\n').append(special); } if (parentStr != null) { sb.append('\n').append(parentStr); } return sb.toString(); }
From source file:suneido.runtime.builtin.StringMethods.java
@Params("n") public static Object Repeat(Object self, Object a) { return Strings.repeat(toStr(self), Math.max(0, toInt(a))); }