本文整理汇总了Java中org.codehaus.groovy.runtime.StringGroovyMethods类的典型用法代码示例。如果您正苦于以下问题:Java StringGroovyMethods类的具体用法?Java StringGroovyMethods怎么用?Java StringGroovyMethods使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringGroovyMethods类属于org.codehaus.groovy.runtime包,在下文中一共展示了StringGroovyMethods类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addInstallTask
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
private void addInstallTask(final Project project, final Distribution distribution) {
String taskName = TASK_INSTALL_NAME;
if (!MAIN_DISTRIBUTION_NAME.equals(distribution.getName())) {
taskName = "install" + StringGroovyMethods.capitalize(distribution.getName()) + "Dist";
}
Sync installTask = project.getTasks().create(taskName, Sync.class);
installTask.setDescription("Installs the project as a distribution as-is.");
installTask.setGroup(DISTRIBUTION_GROUP);
installTask.with(distribution.getContents());
installTask.into(new Callable<File>() {
@Override
public File call() throws Exception {
return project.file("" + project.getBuildDir() + "/install/" + distribution.getBaseName());
}
});
}
示例2: escapeXml
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
/**
* Escape the following characters {@code " ' & < >} with their XML entities, e.g.
* {@code "bread" & "butter"} becomes {@code "bread" & "butter"}.
* Notes:<ul>
* <li>Supports only the five basic XML entities (gt, lt, quot, amp, apos)</li>
* <li>Does not escape control characters</li>
* <li>Does not support DTDs or external entities</li>
* <li>Does not treat surrogate pairs specially</li>
* <li>Does not perform Unicode validation on its input</li>
* </ul>
*
* @param orig the original String
* @return A new string in which all characters that require escaping
* have been replaced with the corresponding XML entities.
* @see #escapeControlCharacters(String)
*/
public static String escapeXml(String orig) {
return StringGroovyMethods.collectReplacements(orig, new Closure<String>(null) {
public String doCall(Character arg) {
switch (arg) {
case '&':
return "&";
case '<':
return "<";
case '>':
return ">";
case '"':
return """;
case '\'':
return "'";
}
return null;
}
});
}
示例3: replaceHexEscapes
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
public static String replaceHexEscapes(String text) {
if (!text.contains(BACKSLASH)) {
return text;
}
Pattern p = Pattern.compile("(\\\\*)\\\\u([0-9abcdefABCDEF]{4})");
return StringGroovyMethods.replaceAll((CharSequence) text, p, new Closure<Void>(null, null) {
Object doCall(String _0, String _1, String _2) {
if (isLengthOdd(_1)) {
return _0;
}
return _1 + new String(Character.toChars(Integer.parseInt(_2, 16)));
}
});
}
示例4: replaceOctalEscapes
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
public static String replaceOctalEscapes(String text) {
if (!text.contains(BACKSLASH)) {
return text;
}
Pattern p = Pattern.compile("(\\\\*)\\\\([0-3]?[0-7]?[0-7])");
return StringGroovyMethods.replaceAll((CharSequence) text, p, new Closure<Void>(null, null) {
Object doCall(String _0, String _1, String _2) {
if (isLengthOdd(_1)) {
return _0;
}
return _1 + new String(Character.toChars(Integer.parseInt(_2, 8)));
}
});
}
示例5: replaceStandardEscapes
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
public static String replaceStandardEscapes(String text) {
if (!text.contains(BACKSLASH)) {
return text;
}
Pattern p = Pattern.compile("(\\\\*)\\\\([btnfr\"'])");
String result = StringGroovyMethods.replaceAll((CharSequence) text, p, new Closure<Void>(null, null) {
Object doCall(String _0, String _1, String _2) {
if (isLengthOdd(_1)) {
return _0;
}
Character character = STANDARD_ESCAPES.get(_2.charAt(0));
return _1 + (character != null ? character : _2);
}
});
return replace(result,"\\\\", "\\");
}
示例6: replaceLineEscape
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
private static String replaceLineEscape(String text) {
if (!text.contains(BACKSLASH)) {
return text;
}
Pattern p = Pattern.compile("(\\\\*)\\\\\r?\n");
text = StringGroovyMethods.replaceAll((CharSequence) text, p, new Closure<Void>(null, null) {
Object doCall(String _0, String _1) {
if (isLengthOdd(_1)) {
return _0;
}
return _1;
}
});
return text;
}
示例7: toString
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
public String toString() {
List buffer = new ArrayList();
if (this.years != 0) buffer.add(this.years + " years");
if (this.months != 0) buffer.add(this.months + " months");
if (this.days != 0) buffer.add(this.days + " days");
if (this.hours != 0) buffer.add(this.hours + " hours");
if (this.minutes != 0) buffer.add(this.minutes + " minutes");
if (this.seconds != 0 || this.millis != 0) {
int norm_millis = this.millis % 1000;
int norm_seconds = this.seconds + DefaultGroovyMethods.intdiv(this.millis - norm_millis, 1000).intValue();
CharSequence millisToPad = "" + Math.abs(norm_millis);
buffer.add((norm_seconds == 0 ? (norm_millis < 0 ? "-0" : "0") : norm_seconds) + "." + StringGroovyMethods.padLeft(millisToPad, 3, "0") + " seconds");
}
if (!buffer.isEmpty()) {
return DefaultGroovyMethods.join(buffer.iterator(), ", ");
} else {
return "0";
}
}
示例8: addAssembleTask
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
private void addAssembleTask(Project project, Distribution distribution, Task... tasks) {
String taskName = TASK_ASSEMBLE_NAME;
if (!MAIN_DISTRIBUTION_NAME.equals(distribution.getName())) {
taskName = "assemble" + StringGroovyMethods.capitalize(distribution.getName()) + "Dist";
}
Task assembleTask = project.getTasks().create(taskName);
assembleTask.setDescription("Assembles the " + distribution.getName() + " distributions");
assembleTask.setGroup(DISTRIBUTION_GROUP);
assembleTask.dependsOn((Object[]) tasks);
}
示例9: createShrinkResourcesTask
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
private ShrinkResources createShrinkResourcesTask(
final ApkVariantOutputData variantOutputData) {
BaseVariantData<?> variantData = (BaseVariantData<?>) variantOutputData.variantData;
ShrinkResources task = scope.getGlobalScope().getProject().getTasks()
.create("shrink" + StringGroovyMethods
.capitalize(variantOutputData.getFullName())
+ "Resources", ShrinkResources.class);
task.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
task.variantOutputData = variantOutputData;
final String outputBaseName = variantOutputData.getBaseName();
task.setCompressedResources(new File(
scope.getGlobalScope().getBuildDir() + "/" + FD_INTERMEDIATES + "/res/" +
"resources-" + outputBaseName + "-stripped.ap_"));
ConventionMappingHelper.map(task, "uncompressedResources", new Callable<File>() {
@Override
public File call() {
return variantOutputData.processResourcesTask.getPackageOutputFile();
}
});
task.dependsOn(
scope.getVariantScope().getObfuscationTask().getName(),
scope.getManifestProcessorTask().getName(),
variantOutputData.processResourcesTask);
return task;
}
示例10: createGroovyToken
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
private org.codehaus.groovy.syntax.Token createGroovyToken(Token token, int cardinality) {
String text = StringGroovyMethods.multiply((CharSequence) token.getText(), cardinality);
return new org.codehaus.groovy.syntax.Token(
"..<".equals(token.getText()) || "..".equals(token.getText())
? Types.RANGE_OPERATOR
: Types.lookup(text, Types.ANY),
text,
token.getLine(),
token.getCharPositionInLine() + 1
);
}
示例11: paintComponent
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
// starting position in document
int start = textEditor.viewToModel(getViewport().getViewPosition());
// end position in document
int end = textEditor.viewToModel(new Point(10,
getViewport().getViewPosition().y +
(int) textEditor.getVisibleRect().getHeight())
);
// translate offsets to lines
Document doc = textEditor.getDocument();
int startline = doc.getDefaultRootElement().getElementIndex(start) + 1;
int endline = doc.getDefaultRootElement().getElementIndex(end) + 1;
Font f = textEditor.getFont();
int fontHeight = g.getFontMetrics(f).getHeight();
int fontDesc = g.getFontMetrics(f).getDescent();
int startingY = -1;
try {
startingY = textEditor.modelToView(start).y + fontHeight - fontDesc;
} catch (BadLocationException e1) {
System.err.println(e1.getMessage());
}
g.setFont(f);
for (int line = startline, y = startingY; line <= endline; y += fontHeight, line++) {
String lineNumber = StringGroovyMethods.padLeft(Integer.toString(line), 4, " ");
g.drawString(lineNumber, 0, y);
}
}
示例12: createComparatorFor
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
private static void createComparatorFor(ClassNode classNode, PropertyNode property, boolean reversed) {
String propName = StringGroovyMethods.capitalize((CharSequence) property.getName());
String className = classNode.getName() + "$" + propName + "Comparator";
ClassNode superClass = makeClassSafeWithGenerics(AbstractComparator.class, classNode);
InnerClassNode cmpClass = new InnerClassNode(classNode, className, ACC_PRIVATE | ACC_STATIC, superClass);
classNode.getModule().addClass(cmpClass);
cmpClass.addMethod(new MethodNode(
"compare",
ACC_PUBLIC,
ClassHelper.int_TYPE,
params(param(newClass(classNode), ARG0), param(newClass(classNode), ARG1)),
ClassNode.EMPTY_ARRAY,
createCompareMethodBody(property, reversed)
));
String fieldName = "this$" + propName + "Comparator";
// private final Comparator this$<property>Comparator = new <type>$<property>Comparator();
FieldNode cmpField = classNode.addField(
fieldName,
ACC_STATIC | ACC_FINAL | ACC_PRIVATE | ACC_SYNTHETIC,
COMPARATOR_TYPE,
ctorX(cmpClass));
classNode.addMethod(new MethodNode(
"comparatorBy" + propName,
ACC_PUBLIC | ACC_STATIC,
COMPARATOR_TYPE,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
returnS(fieldX(cmpField))
));
}
示例13: asCollection
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
public static Collection asCollection(Object value) {
if (value == null) {
return Collections.EMPTY_LIST;
} else if (value instanceof Collection) {
return (Collection) value;
} else if (value instanceof Map) {
Map map = (Map) value;
return map.entrySet();
} else if (value.getClass().isArray()) {
return arrayAsCollection(value);
} else if (value instanceof MethodClosure) {
MethodClosure method = (MethodClosure) value;
IteratorClosureAdapter adapter = new IteratorClosureAdapter(method.getDelegate());
method.call(adapter);
return adapter.asList();
} else if (value instanceof String || value instanceof GString) {
return StringGroovyMethods.toList((CharSequence) value);
} else if (value instanceof File) {
try {
return ResourceGroovyMethods.readLines((File) value);
} catch (IOException e) {
throw new GroovyRuntimeException("Error reading file: " + value, e);
}
} else if (value instanceof Class && ((Class) value).isEnum()) {
Object[] values = (Object[]) InvokerHelper.invokeMethod(value, "values", EMPTY_OBJECT_ARRAY);
return Arrays.asList(values);
} else {
// let's assume it's a collection of 1
return Collections.singletonList(value);
}
}
示例14: writeValue
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
private static void writeValue(String key, String space, String prefix, Object value, BufferedWriter out) throws IOException {
// key = key.indexOf('.') > -1 ? InvokerHelper.inspect(key) : key;
boolean isKeyword = KEYWORDS.contains(key);
key = isKeyword ? InvokerHelper.inspect(key) : key;
if (!StringGroovyMethods.asBoolean(prefix) && isKeyword) prefix = "this.";
out.append(space).append(prefix).append(key).append('=').append(InvokerHelper.inspect(value));
out.newLine();
}
示例15: aFile
import org.codehaus.groovy.runtime.StringGroovyMethods; //导入依赖的package包/类
@And("^a file \"([^\"]*)\":$")
public void aFile(String file, String body) throws Throwable {
Files.write(projectDir.resolve(file), StringUtils.trim(StringGroovyMethods.stripIndent((CharSequence) body)).getBytes());
}