_id
stringlengths 2
7
| title
stringlengths 3
140
| partition
stringclasses 3
values | text
stringlengths 73
34.1k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q0 | SCryptUtil.check | train | public static boolean check(String passwd, String hashed) {
try {
String[] parts = hashed.split("\\$");
if (parts.length != 5 || !parts[1].equals("s0")) {
throw new IllegalArgumentException("Invalid hashed value");
}
long params = Long.parseLong(parts[2], 16);
byte[] salt = decode(parts[3].toCharArray());
byte[] derived0 = decode(parts[4].toCharArray());
int N = (int) Math.pow(2, params >> 16 & 0xffff);
int r = (int) params >> 8 & 0xff;
int p = (int) params & 0xff;
byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32);
if (derived0.length != derived1.length) return false;
int result = 0;
for (int i = 0; i < derived0.length; i++) {
result |= derived0[i] ^ derived1[i];
}
return result == 0;
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("JVM doesn't support UTF-8?");
} catch (GeneralSecurityException e) {
throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?");
}
} | java | {
"resource": ""
} |
q1 | Platform.detect | train | public static Platform detect() throws UnsupportedPlatformException {
String osArch = getProperty("os.arch");
String osName = getProperty("os.name");
for (Arch arch : Arch.values()) {
if (arch.pattern.matcher(osArch).matches()) {
for (OS os : OS.values()) {
if (os.pattern.matcher(osName).matches()) {
return new Platform(arch, os);
}
}
}
}
String msg = String.format("Unsupported platform %s %s", osArch, osName);
throw new UnsupportedPlatformException(msg);
} | java | {
"resource": ""
} |
q2 | ASTNode.getNodeMetaData | train | public <T> T getNodeMetaData(Object key) {
if (metaDataMap == null) {
return (T) null;
}
return (T) metaDataMap.get(key);
} | java | {
"resource": ""
} |
q3 | ASTNode.copyNodeMetaData | train | public void copyNodeMetaData(ASTNode other) {
if (other.metaDataMap == null) {
return;
}
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
metaDataMap.putAll(other.metaDataMap);
} | java | {
"resource": ""
} |
q4 | ASTNode.setNodeMetaData | train | public void setNodeMetaData(Object key, Object value) {
if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
Object old = metaDataMap.put(key,value);
if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+".");
} | java | {
"resource": ""
} |
q5 | ASTNode.putNodeMetaData | train | public Object putNodeMetaData(Object key, Object value) {
if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + ".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
return metaDataMap.put(key, value);
} | java | {
"resource": ""
} |
q6 | ASTNode.removeNodeMetaData | train | public void removeNodeMetaData(Object key) {
if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+".");
if (metaDataMap == null) {
return;
}
metaDataMap.remove(key);
} | java | {
"resource": ""
} |
q7 | IntRange.subListBorders | train | public RangeInfo subListBorders(int size) {
if (inclusive == null) throw new IllegalStateException("Should not call subListBorders on a non-inclusive aware IntRange");
int tempFrom = from;
if (tempFrom < 0) {
tempFrom += size;
}
int tempTo = to;
if (tempTo < 0) {
tempTo += size;
}
if (tempFrom > tempTo) {
return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true);
}
return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false);
} | java | {
"resource": ""
} |
q8 | BindableASTTransformation.createSetterMethod | train | protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock) {
MethodNode setter = new MethodNode(
setterName,
propertyNode.getModifiers(),
ClassHelper.VOID_TYPE,
params(param(propertyNode.getType(), "value")),
ClassNode.EMPTY_ARRAY,
setterBlock);
setter.setSynthetic(true);
// add it to the class
declaringClass.addMethod(setter);
} | java | {
"resource": ""
} |
q9 | CompilationUnit.applyToPrimaryClassNodes | train | public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body) throws CompilationFailedException {
Iterator classNodes = getPrimaryClassNodes(body.needSortedInput()).iterator();
while (classNodes.hasNext()) {
SourceUnit context = null;
try {
ClassNode classNode = (ClassNode) classNodes.next();
context = classNode.getModule().getContext();
if (context == null || context.phase < phase || (context.phase == phase && !context.phaseComplete)) {
int offset = 1;
Iterator<InnerClassNode> iterator = classNode.getInnerClasses();
while (iterator.hasNext()) {
iterator.next();
offset++;
}
body.call(context, new GeneratorContext(this.ast, offset), classNode);
}
} catch (CompilationFailedException e) {
// fall through, getErrorReporter().failIfErrors() will trigger
} catch (NullPointerException npe) {
GroovyBugError gbe = new GroovyBugError("unexpected NullpointerException", npe);
changeBugText(gbe, context);
throw gbe;
} catch (GroovyBugError e) {
changeBugText(e, context);
throw e;
} catch (NoClassDefFoundError e) {
// effort to get more logging in case a dependency of a class is loaded
// although it shouldn't have
convertUncaughtExceptionToCompilationError(e);
} catch (Exception e) {
convertUncaughtExceptionToCompilationError(e);
}
}
getErrorCollector().failIfErrors();
} | java | {
"resource": ""
} |
q10 | SocketGroovyMethods.withStreams | train | public static <T> T withStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.InputStream","java.io.OutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
try {
T result = closure.call(new Object[]{input, output});
InputStream temp1 = input;
input = null;
temp1.close();
OutputStream temp2 = output;
output = null;
temp2.close();
return result;
} finally {
closeWithWarning(input);
closeWithWarning(output);
}
} | java | {
"resource": ""
} |
q11 | SocketGroovyMethods.withObjectStreams | train | public static <T> T withObjectStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.ObjectInputStream","java.io.ObjectOutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(output);
ObjectInputStream ois = new ObjectInputStream(input);
try {
T result = closure.call(new Object[]{ois, oos});
InputStream temp1 = ois;
ois = null;
temp1.close();
temp1 = input;
input = null;
temp1.close();
OutputStream temp2 = oos;
oos = null;
temp2.close();
temp2 = output;
output = null;
temp2.close();
return result;
} finally {
closeWithWarning(ois);
closeWithWarning(input);
closeWithWarning(oos);
closeWithWarning(output);
}
} | java | {
"resource": ""
} |
q12 | MethodKey.createCopy | train | public MethodKey createCopy() {
int size = getParameterCount();
Class[] paramTypes = new Class[size];
for (int i = 0; i < size; i++) {
paramTypes[i] = getParameterType(i);
}
return new DefaultMethodKey(sender, name, paramTypes, isCallToSuper);
} | java | {
"resource": ""
} |
q13 | TraitComposer.doExtendTraits | train | public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) {
if (cNode.isInterface()) return;
boolean isItselfTrait = Traits.isTrait(cNode);
SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit);
if (isItselfTrait) {
checkTraitAllowed(cNode, unit);
return;
}
if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) {
List<ClassNode> traits = findTraits(cNode);
for (ClassNode trait : traits) {
TraitHelpersTuple helpers = Traits.findHelpers(trait);
applyTrait(trait, cNode, helpers);
superCallTransformer.visitClass(cNode);
if (unit!=null) {
ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader());
collector.visitClass(cNode);
}
}
}
} | java | {
"resource": ""
} |
q14 | ErrorCollector.getSyntaxError | train | public SyntaxException getSyntaxError(int index) {
SyntaxException exception = null;
Message message = getError(index);
if (message != null && message instanceof SyntaxErrorMessage) {
exception = ((SyntaxErrorMessage) message).getCause();
}
return exception;
} | java | {
"resource": ""
} |
q15 | GroovyInternalPosixParser.gobble | train | private void gobble(Iterator iter)
{
if (eatTheRest)
{
while (iter.hasNext())
{
tokens.add(iter.next());
}
}
} | java | {
"resource": ""
} |
q16 | StaticTypeCheckingSupport.allParametersAndArgumentsMatch | train | public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args) {
if (params==null) {
params = Parameter.EMPTY_ARRAY;
}
int dist = 0;
if (args.length<params.length) return -1;
// we already know the lengths are equal
for (int i = 0; i < params.length; i++) {
ClassNode paramType = params[i].getType();
ClassNode argType = args[i];
if (!isAssignableTo(argType, paramType)) return -1;
else {
if (!paramType.equals(argType)) dist+=getDistance(argType, paramType);
}
}
return dist;
} | java | {
"resource": ""
} |
q17 | StaticTypeCheckingSupport.excessArgumentsMatchesVargsParameter | train | static int excessArgumentsMatchesVargsParameter(Parameter[] params, ClassNode[] args) {
// we already know parameter length is bigger zero and last is a vargs
// the excess arguments are all put in an array for the vargs call
// so check against the component type
int dist = 0;
ClassNode vargsBase = params[params.length - 1].getType().getComponentType();
for (int i = params.length; i < args.length; i++) {
if (!isAssignableTo(args[i],vargsBase)) return -1;
else if (!args[i].equals(vargsBase)) dist+=getDistance(args[i], vargsBase);
}
return dist;
} | java | {
"resource": ""
} |
q18 | StaticTypeCheckingSupport.lastArgMatchesVarg | train | static int lastArgMatchesVarg(Parameter[] params, ClassNode... args) {
if (!isVargs(params)) return -1;
// case length ==0 handled already
// we have now two cases,
// the argument is wrapped in the vargs array or
// the argument is an array that can be used for the vargs part directly
// we test only the wrapping part, since the non wrapping is done already
ClassNode lastParamType = params[params.length - 1].getType();
ClassNode ptype = lastParamType.getComponentType();
ClassNode arg = args[args.length - 1];
if (isNumberType(ptype) && isNumberType(arg) && !ptype.equals(arg)) return -1;
return isAssignableTo(arg, ptype)?Math.min(getDistance(arg, lastParamType), getDistance(arg, ptype)):-1;
} | java | {
"resource": ""
} |
q19 | StaticTypeCheckingSupport.buildParameter | train | private static Parameter buildParameter(final Map<String, GenericsType> genericFromReceiver, final Map<String, GenericsType> placeholdersFromContext, final Parameter methodParameter, final ClassNode paramType) {
if (genericFromReceiver.isEmpty() && (placeholdersFromContext==null||placeholdersFromContext.isEmpty())) {
return methodParameter;
}
if (paramType.isArray()) {
ClassNode componentType = paramType.getComponentType();
Parameter subMethodParameter = new Parameter(componentType, methodParameter.getName());
Parameter component = buildParameter(genericFromReceiver, placeholdersFromContext, subMethodParameter, componentType);
return new Parameter(component.getType().makeArray(), component.getName());
}
ClassNode resolved = resolveClassNodeGenerics(genericFromReceiver, placeholdersFromContext, paramType);
return new Parameter(resolved, methodParameter.getName());
} | java | {
"resource": ""
} |
q20 | StaticTypeCheckingSupport.isClassClassNodeWrappingConcreteType | train | public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) {
GenericsType[] genericsTypes = classNode.getGenericsTypes();
return ClassHelper.CLASS_Type.equals(classNode)
&& classNode.isUsingGenerics()
&& genericsTypes!=null
&& !genericsTypes[0].isPlaceholder()
&& !genericsTypes[0].isWildcard();
} | java | {
"resource": ""
} |
q21 | IOGroovyMethods.splitEachLine | train | public static <T> T splitEachLine(InputStream stream, String regex, String charset, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException {
return splitEachLine(new BufferedReader(new InputStreamReader(stream, charset)), regex, closure);
} | java | {
"resource": ""
} |
q22 | IOGroovyMethods.transformChar | train | public static void transformChar(Reader self, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException {
int c;
try {
char[] chars = new char[1];
while ((c = self.read()) != -1) {
chars[0] = (char) c;
writer.write((String) closure.call(new String(chars)));
}
writer.flush();
Writer temp2 = writer;
writer = null;
temp2.close();
Reader temp1 = self;
self = null;
temp1.close();
} finally {
closeWithWarning(self);
closeWithWarning(writer);
}
} | java | {
"resource": ""
} |
q23 | IOGroovyMethods.withCloseable | train | public static <T, U extends Closeable> T withCloseable(U self, @ClosureParams(value=FirstParam.class) Closure<T> action) throws IOException {
try {
T result = action.call(self);
Closeable temp = self;
self = null;
temp.close();
return result;
} finally {
DefaultGroovyMethodsSupport.closeWithWarning(self);
}
} | java | {
"resource": ""
} |
q24 | MetaArrayLengthProperty.getProperty | train | public Object getProperty(Object object) {
return java.lang.reflect.Array.getLength(object);
} | java | {
"resource": ""
} |
q25 | ProxyGeneratorAdapter.makeDelegateCall | train | protected MethodVisitor makeDelegateCall(final String name, final String desc, final String signature, final String[] exceptions, final int accessFlags) {
MethodVisitor mv = super.visitMethod(accessFlags, name, desc, signature, exceptions);
mv.visitVarInsn(ALOAD, 0); // load this
mv.visitFieldInsn(GETFIELD, proxyName, DELEGATE_OBJECT_FIELD, BytecodeHelper.getTypeDescription(delegateClass)); // load delegate
// using InvokerHelper to allow potential intercepted calls
int size;
mv.visitLdcInsn(name); // method name
Type[] args = Type.getArgumentTypes(desc);
BytecodeHelper.pushConstant(mv, args.length);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
size = 6;
int idx = 1;
for (int i = 0; i < args.length; i++) {
Type arg = args[i];
mv.visitInsn(DUP);
BytecodeHelper.pushConstant(mv, i);
// primitive types must be boxed
if (isPrimitive(arg)) {
mv.visitIntInsn(getLoadInsn(arg), idx);
String wrappedType = getWrappedClassDescriptor(arg);
mv.visitMethodInsn(INVOKESTATIC, wrappedType, "valueOf", "(" + arg.getDescriptor() + ")L" + wrappedType + ";", false);
} else {
mv.visitVarInsn(ALOAD, idx); // load argument i
}
size = Math.max(size, 5+registerLen(arg));
idx += registerLen(arg);
mv.visitInsn(AASTORE); // store value into array
}
mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/InvokerHelper", "invokeMethod", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;", false);
unwrapResult(mv, desc);
mv.visitMaxs(size, registerLen(args) + 1);
return mv;
} | java | {
"resource": ""
} |
q26 | CachedSAMClass.getSAMMethod | train | public static Method getSAMMethod(Class<?> c) {
// SAM = single public abstract method
// if the class is not abstract there is no abstract method
if (!Modifier.isAbstract(c.getModifiers())) return null;
if (c.isInterface()) {
Method[] methods = c.getMethods();
// res stores the first found abstract method
Method res = null;
for (Method mi : methods) {
// ignore methods, that are not abstract and from Object
if (!Modifier.isAbstract(mi.getModifiers())) continue;
// ignore trait methods which have a default implementation
if (mi.getAnnotation(Traits.Implemented.class)!=null) continue;
try {
Object.class.getMethod(mi.getName(), mi.getParameterTypes());
continue;
} catch (NoSuchMethodException e) {/*ignore*/}
// we have two methods, so no SAM
if (res!=null) return null;
res = mi;
}
return res;
} else {
LinkedList<Method> methods = new LinkedList();
getAbstractMethods(c, methods);
if (methods.isEmpty()) return null;
ListIterator<Method> it = methods.listIterator();
while (it.hasNext()) {
Method m = it.next();
if (hasUsableImplementation(c, m)) it.remove();
}
return getSingleNonDuplicateMethod(methods);
}
} | java | {
"resource": ""
} |
q27 | MopWriter.generateMopCalls | train | protected void generateMopCalls(LinkedList<MethodNode> mopCalls, boolean useThis) {
for (MethodNode method : mopCalls) {
String name = getMopMethodName(method, useThis);
Parameter[] parameters = method.getParameters();
String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameters());
MethodVisitor mv = controller.getClassVisitor().visitMethod(ACC_PUBLIC | ACC_SYNTHETIC, name, methodDescriptor, null, null);
controller.setMethodVisitor(mv);
mv.visitVarInsn(ALOAD, 0);
int newRegister = 1;
OperandStack operandStack = controller.getOperandStack();
for (Parameter parameter : parameters) {
ClassNode type = parameter.getType();
operandStack.load(parameter.getType(), newRegister);
// increment to next register, double/long are using two places
newRegister++;
if (type == ClassHelper.double_TYPE || type == ClassHelper.long_TYPE) newRegister++;
}
operandStack.remove(parameters.length);
ClassNode declaringClass = method.getDeclaringClass();
// JDK 8 support for default methods in interfaces
// this should probably be strenghtened when we support the A.super.foo() syntax
int opcode = declaringClass.isInterface()?INVOKEINTERFACE:INVOKESPECIAL;
mv.visitMethodInsn(opcode, BytecodeHelper.getClassInternalName(declaringClass), method.getName(), methodDescriptor, opcode == INVOKEINTERFACE);
BytecodeHelper.doReturn(mv, method.getReturnType());
mv.visitMaxs(0, 0);
mv.visitEnd();
controller.getClassNode().addMethod(name, ACC_PUBLIC | ACC_SYNTHETIC, method.getReturnType(), parameters, null, null);
}
} | java | {
"resource": ""
} |
q28 | ClassHelper.getWrapper | train | public static ClassNode getWrapper(ClassNode cn) {
cn = cn.redirect();
if (!isPrimitiveType(cn)) return cn;
if (cn==boolean_TYPE) {
return Boolean_TYPE;
} else if (cn==byte_TYPE) {
return Byte_TYPE;
} else if (cn==char_TYPE) {
return Character_TYPE;
} else if (cn==short_TYPE) {
return Short_TYPE;
} else if (cn==int_TYPE) {
return Integer_TYPE;
} else if (cn==long_TYPE) {
return Long_TYPE;
} else if (cn==float_TYPE) {
return Float_TYPE;
} else if (cn==double_TYPE) {
return Double_TYPE;
} else if (cn==VOID_TYPE) {
return void_WRAPPER_TYPE;
}
else {
return cn;
}
} | java | {
"resource": ""
} |
q29 | ClassHelper.findSAM | train | public static MethodNode findSAM(ClassNode type) {
if (!Modifier.isAbstract(type.getModifiers())) return null;
if (type.isInterface()) {
List<MethodNode> methods = type.getMethods();
MethodNode found=null;
for (MethodNode mi : methods) {
// ignore methods, that are not abstract and from Object
if (!Modifier.isAbstract(mi.getModifiers())) continue;
// ignore trait methods which have a default implementation
if (Traits.hasDefaultImplementation(mi)) continue;
if (mi.getDeclaringClass().equals(OBJECT_TYPE)) continue;
if (OBJECT_TYPE.getDeclaredMethod(mi.getName(), mi.getParameters())!=null) continue;
// we have two methods, so no SAM
if (found!=null) return null;
found = mi;
}
return found;
} else {
List<MethodNode> methods = type.getAbstractMethods();
MethodNode found = null;
if (methods!=null) {
for (MethodNode mi : methods) {
if (!hasUsableImplementation(type, mi)) {
if (found!=null) return null;
found = mi;
}
}
}
return found;
}
} | java | {
"resource": ""
} |
q30 | Types.getPrecedence | train | public static int getPrecedence( int type, boolean throwIfInvalid ) {
switch( type ) {
case LEFT_PARENTHESIS:
return 0;
case EQUAL:
case PLUS_EQUAL:
case MINUS_EQUAL:
case MULTIPLY_EQUAL:
case DIVIDE_EQUAL:
case INTDIV_EQUAL:
case MOD_EQUAL:
case POWER_EQUAL:
case LOGICAL_OR_EQUAL:
case LOGICAL_AND_EQUAL:
case LEFT_SHIFT_EQUAL:
case RIGHT_SHIFT_EQUAL:
case RIGHT_SHIFT_UNSIGNED_EQUAL:
case BITWISE_OR_EQUAL:
case BITWISE_AND_EQUAL:
case BITWISE_XOR_EQUAL:
return 5;
case QUESTION:
return 10;
case LOGICAL_OR:
return 15;
case LOGICAL_AND:
return 20;
case BITWISE_OR:
case BITWISE_AND:
case BITWISE_XOR:
return 22;
case COMPARE_IDENTICAL:
case COMPARE_NOT_IDENTICAL:
return 24;
case COMPARE_NOT_EQUAL:
case COMPARE_EQUAL:
case COMPARE_LESS_THAN:
case COMPARE_LESS_THAN_EQUAL:
case COMPARE_GREATER_THAN:
case COMPARE_GREATER_THAN_EQUAL:
case COMPARE_TO:
case FIND_REGEX:
case MATCH_REGEX:
case KEYWORD_INSTANCEOF:
return 25;
case DOT_DOT:
case DOT_DOT_DOT:
return 30;
case LEFT_SHIFT:
case RIGHT_SHIFT:
case RIGHT_SHIFT_UNSIGNED:
return 35;
case PLUS:
case MINUS:
return 40;
case MULTIPLY:
case DIVIDE:
case INTDIV:
case MOD:
return 45;
case NOT:
case REGEX_PATTERN:
return 50;
case SYNTH_CAST:
return 55;
case PLUS_PLUS:
case MINUS_MINUS:
case PREFIX_PLUS_PLUS:
case PREFIX_MINUS_MINUS:
case POSTFIX_PLUS_PLUS:
case POSTFIX_MINUS_MINUS:
return 65;
case PREFIX_PLUS:
case PREFIX_MINUS:
return 70;
case POWER:
return 72;
case SYNTH_METHOD:
case LEFT_SQUARE_BRACKET:
return 75;
case DOT:
case NAVIGATE:
return 80;
case KEYWORD_NEW:
return 85;
}
if( throwIfInvalid ) {
throw new GroovyBugError( "precedence requested for non-operator" );
}
return -1;
} | java | {
"resource": ""
} |
q31 | NullObject.with | train | public <T> T with( Closure<T> closure ) {
return DefaultGroovyMethods.with( null, closure ) ;
} | java | {
"resource": ""
} |
q32 | DefaultGrailsDomainClassInjector.implementsMethod | train | private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) {
List methods = classNode.getMethods();
if (argTypes == null || argTypes.length ==0) {
for (Iterator i = methods.iterator(); i.hasNext();) {
MethodNode mn = (MethodNode) i.next();
boolean methodMatch = mn.getName().equals(methodName);
if(methodMatch)return true;
// TODO Implement further parameter analysis
}
}
return false;
} | java | {
"resource": ""
} |
q33 | MethodNode.getTypeDescriptor | train | public String getTypeDescriptor() {
if (typeDescriptor == null) {
StringBuilder buf = new StringBuilder(name.length() + parameters.length * 10);
buf.append(returnType.getName());
buf.append(' ');
buf.append(name);
buf.append('(');
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
buf.append(", ");
}
Parameter param = parameters[i];
buf.append(formatTypeName(param.getType()));
}
buf.append(')');
typeDescriptor = buf.toString();
}
return typeDescriptor;
} | java | {
"resource": ""
} |
q34 | MethodNode.getText | train | @Override
public String getText() {
String retType = AstToTextHelper.getClassText(returnType);
String exceptionTypes = AstToTextHelper.getThrowsClauseText(exceptions);
String parms = AstToTextHelper.getParametersText(parameters);
return AstToTextHelper.getModifiersText(modifiers) + " " + retType + " " + name + "(" + parms + ") " + exceptionTypes + " { ... }";
} | java | {
"resource": ""
} |
q35 | SimpleGroovyClassDoc.constructors | train | public GroovyConstructorDoc[] constructors() {
Collections.sort(constructors);
return constructors.toArray(new GroovyConstructorDoc[constructors.size()]);
} | java | {
"resource": ""
} |
q36 | SimpleGroovyClassDoc.innerClasses | train | public GroovyClassDoc[] innerClasses() {
Collections.sort(nested);
return nested.toArray(new GroovyClassDoc[nested.size()]);
} | java | {
"resource": ""
} |
q37 | SimpleGroovyClassDoc.fields | train | public GroovyFieldDoc[] fields() {
Collections.sort(fields);
return fields.toArray(new GroovyFieldDoc[fields.size()]);
} | java | {
"resource": ""
} |
q38 | SimpleGroovyClassDoc.properties | train | public GroovyFieldDoc[] properties() {
Collections.sort(properties);
return properties.toArray(new GroovyFieldDoc[properties.size()]);
} | java | {
"resource": ""
} |
q39 | SimpleGroovyClassDoc.enumConstants | train | public GroovyFieldDoc[] enumConstants() {
Collections.sort(enumConstants);
return enumConstants.toArray(new GroovyFieldDoc[enumConstants.size()]);
} | java | {
"resource": ""
} |
q40 | SimpleGroovyClassDoc.methods | train | public GroovyMethodDoc[] methods() {
Collections.sort(methods);
return methods.toArray(new GroovyMethodDoc[methods.size()]);
} | java | {
"resource": ""
} |
q41 | DataSet.add | train | public void add(Map<String, Object> map) throws SQLException {
if (withinDataSetBatch) {
if (batchData.size() == 0) {
batchKeys = map.keySet();
} else {
if (!map.keySet().equals(batchKeys)) {
throw new IllegalArgumentException("Inconsistent keys found for batch add!");
}
}
batchData.add(map);
return;
}
int answer = executeUpdate(buildListQuery(map), new ArrayList<Object>(map.values()));
if (answer != 1) {
LOG.warning("Should have updated 1 row not " + answer + " when trying to add: " + map);
}
} | java | {
"resource": ""
} |
q42 | DataSet.each | train | public void each(int offset, int maxRows, Closure closure) throws SQLException {
eachRow(getSql(), getParameters(), offset, maxRows, closure);
} | java | {
"resource": ""
} |
q43 | VetoableASTTransformation.wrapSetterMethod | train | private void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName) {
String getterName = "get" + MetaClassHelper.capitalize(propertyName);
MethodNode setter = classNode.getSetterMethod("set" + MetaClassHelper.capitalize(propertyName));
if (setter != null) {
// Get the existing code block
Statement code = setter.getCode();
Expression oldValue = varX("$oldValue");
Expression newValue = varX("$newValue");
Expression proposedValue = varX(setter.getParameters()[0].getName());
BlockStatement block = new BlockStatement();
// create a local variable to hold the old value from the getter
block.addStatement(declS(oldValue, callThisX(getterName)));
// add the fireVetoableChange method call
block.addStatement(stmt(callThisX("fireVetoableChange", args(
constX(propertyName), oldValue, proposedValue))));
// call the existing block, which will presumably set the value properly
block.addStatement(code);
if (bindable) {
// get the new value to emit in the event
block.addStatement(declS(newValue, callThisX(getterName)));
// add the firePropertyChange method call
block.addStatement(stmt(callThisX("firePropertyChange", args(constX(propertyName), oldValue, newValue))));
}
// replace the existing code block with our new one
setter.setCode(block);
}
} | java | {
"resource": ""
} |
q44 | ResourceGroovyMethods.directorySize | train | public static long directorySize(File self) throws IOException, IllegalArgumentException
{
final long[] size = {0L};
eachFileRecurse(self, FileType.FILES, new Closure<Void>(null) {
public void doCall(Object[] args) {
size[0] += ((File) args[0]).length();
}
});
return size[0];
} | java | {
"resource": ""
} |
q45 | ResourceGroovyMethods.splitEachLine | train | public static <T> T splitEachLine(File self, String regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure<T> closure) throws IOException {
return IOGroovyMethods.splitEachLine(newReader(self), regex, closure);
} | java | {
"resource": ""
} |
q46 | ResourceGroovyMethods.write | train | public static void write(File file, String text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file);
writeUTF16BomIfRequired(charset, out);
writer = new OutputStreamWriter(out, charset);
writer.write(text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | {
"resource": ""
} |
q47 | ResourceGroovyMethods.append | train | public static void append(File file, Object text) throws IOException {
Writer writer = null;
try {
writer = new FileWriter(file, true);
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | {
"resource": ""
} |
q48 | ResourceGroovyMethods.append | train | public static void append(File file, Object text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file, true);
if (!file.exists()) {
writeUTF16BomIfRequired(charset, out);
}
writer = new OutputStreamWriter(out, charset);
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | {
"resource": ""
} |
q49 | ResourceGroovyMethods.append | train | public static void append(File file, Writer writer, String charset) throws IOException {
appendBuffered(file, writer, charset);
} | java | {
"resource": ""
} |
q50 | ResourceGroovyMethods.writeUtf16Bom | train | private static void writeUtf16Bom(OutputStream stream, boolean bigEndian) throws IOException {
if (bigEndian) {
stream.write(-2);
stream.write(-1);
} else {
stream.write(-1);
stream.write(-2);
}
} | java | {
"resource": ""
} |
q51 | GroovyClassLoader.getClassCacheEntry | train | protected Class getClassCacheEntry(String name) {
if (name == null) return null;
synchronized (classCache) {
return classCache.get(name);
}
} | java | {
"resource": ""
} |
q52 | MetaClassRegistryImpl.getMetaClassRegistryChangeEventListeners | train | public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners() {
synchronized (changeListenerList) {
ArrayList<MetaClassRegistryChangeEventListener> ret =
new ArrayList<MetaClassRegistryChangeEventListener>(changeListenerList.size()+nonRemoveableChangeListenerList.size());
ret.addAll(nonRemoveableChangeListenerList);
ret.addAll(changeListenerList);
return ret.toArray(new MetaClassRegistryChangeEventListener[ret.size()]);
}
} | java | {
"resource": ""
} |
q53 | MetaClassRegistryImpl.getInstance | train | public static MetaClassRegistry getInstance(int includeExtension) {
if (includeExtension != DONT_LOAD_DEFAULT) {
if (instanceInclude == null) {
instanceInclude = new MetaClassRegistryImpl();
}
return instanceInclude;
} else {
if (instanceExclude == null) {
instanceExclude = new MetaClassRegistryImpl(DONT_LOAD_DEFAULT);
}
return instanceExclude;
}
} | java | {
"resource": ""
} |
q54 | Reduction.get | train | public CSTNode get( int index )
{
CSTNode element = null;
if( index < size() )
{
element = (CSTNode)elements.get( index );
}
return element;
} | java | {
"resource": ""
} |
q55 | Reduction.set | train | public CSTNode set( int index, CSTNode element )
{
if( elements == null )
{
throw new GroovyBugError( "attempt to set() on a EMPTY Reduction" );
}
if( index == 0 && !(element instanceof Token) )
{
//
// It's not the greatest of design that the interface allows this, but it
// is a tradeoff with convenience, and the convenience is more important.
throw new GroovyBugError( "attempt to set() a non-Token as root of a Reduction" );
}
//
// Fill slots with nulls, if necessary.
int count = elements.size();
if( index >= count )
{
for( int i = count; i <= index; i++ )
{
elements.add( null );
}
}
//
// Then set in the element.
elements.set( index, element );
return element;
} | java | {
"resource": ""
} |
q56 | ManagedLinkedList.add | train | public void add(T value) {
Element<T> element = new Element<T>(bundle, value);
element.previous = tail;
if (tail != null) tail.next = element;
tail = element;
if (head == null) head = element;
} | java | {
"resource": ""
} |
q57 | ManagedLinkedList.toArray | train | public T[] toArray(T[] tArray) {
List<T> array = new ArrayList<T>(100);
for (Iterator<T> it = iterator(); it.hasNext();) {
T val = it.next();
if (val != null) array.add(val);
}
return array.toArray(tArray);
} | java | {
"resource": ""
} |
q58 | ValueMapImpl.get | train | public Value get(Object key) {
/* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */
if (map == null && items.length < 20) {
for (Object item : items) {
MapItemValue miv = (MapItemValue) item;
if (key.equals(miv.name.toValue())) {
return miv.value;
}
}
return null;
} else {
if (map == null) buildIfNeededMap();
return map.get(key);
}
} | java | {
"resource": ""
} |
q59 | DefaultGroovyMethods.unique | train | public static <T> Iterator<T> unique(Iterator<T> self) {
return toList((Iterable<T>) unique(toList(self))).listIterator();
} | java | {
"resource": ""
} |
q60 | DefaultGroovyMethods.numberAwareCompareTo | train | public static int numberAwareCompareTo(Comparable self, Comparable other) {
NumberAwareComparator<Comparable> numberAwareComparator = new NumberAwareComparator<Comparable>();
return numberAwareComparator.compare(self, other);
} | java | {
"resource": ""
} |
q61 | DefaultGroovyMethods.any | train | public static boolean any(Object self, Closure closure) {
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
if (bcw.call(iter.next())) return true;
}
return false;
} | java | {
"resource": ""
} |
q62 | DefaultGroovyMethods.findResult | train | public static Object findResult(Object self, Object defaultResult, Closure closure) {
Object result = findResult(self, closure);
if (result == null) return defaultResult;
return result;
} | java | {
"resource": ""
} |
q63 | DefaultGroovyMethods.groupAnswer | train | protected static <K, T> void groupAnswer(final Map<K, List<T>> answer, T element, K value) {
if (answer.containsKey(value)) {
answer.get(value).add(element);
} else {
List<T> groupedElements = new ArrayList<T>();
groupedElements.add(element);
answer.put(value, groupedElements);
}
} | java | {
"resource": ""
} |
q64 | DefaultGroovyMethods.asImmutable | train | public static <K,V> Map<K,V> asImmutable(Map<? extends K, ? extends V> self) {
return Collections.unmodifiableMap(self);
} | java | {
"resource": ""
} |
q65 | DefaultGroovyMethods.asImmutable | train | public static <K,V> SortedMap<K,V> asImmutable(SortedMap<K, ? extends V> self) {
return Collections.unmodifiableSortedMap(self);
} | java | {
"resource": ""
} |
q66 | DefaultGroovyMethods.asImmutable | train | public static <T> List<T> asImmutable(List<? extends T> self) {
return Collections.unmodifiableList(self);
} | java | {
"resource": ""
} |
q67 | DefaultGroovyMethods.asImmutable | train | public static <T> Set<T> asImmutable(Set<? extends T> self) {
return Collections.unmodifiableSet(self);
} | java | {
"resource": ""
} |
q68 | DefaultGroovyMethods.asImmutable | train | public static <T> SortedSet<T> asImmutable(SortedSet<T> self) {
return Collections.unmodifiableSortedSet(self);
} | java | {
"resource": ""
} |
q69 | DefaultGroovyMethods.sort | train | public static <T> T[] sort(T[] self, Comparator<T> comparator) {
return sort(self, true, comparator);
} | java | {
"resource": ""
} |
q70 | DefaultGroovyMethods.addAll | train | public static <T> boolean addAll(Collection<T> self, Iterator<T> items) {
boolean changed = false;
while (items.hasNext()) {
T next = items.next();
if (self.add(next)) changed = true;
}
return changed;
} | java | {
"resource": ""
} |
q71 | DefaultGroovyMethods.addAll | train | public static <T> boolean addAll(Collection<T> self, Iterable<T> items) {
boolean changed = false;
for (T next : items) {
if (self.add(next)) changed = true;
}
return changed;
} | java | {
"resource": ""
} |
q72 | DefaultGroovyMethods.minus | train | public static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe) {
final Map<K,V> ansMap = createSimilarMap(self);
ansMap.putAll(self);
if (removeMe != null && removeMe.size() > 0) {
for (Map.Entry<K, V> e1 : self.entrySet()) {
for (Object e2 : removeMe.entrySet()) {
if (DefaultTypeTransformation.compareEqual(e1, e2)) {
ansMap.remove(e1.getKey());
}
}
}
}
return ansMap;
} | java | {
"resource": ""
} |
q73 | DefaultGroovyMethods.findLastIndexOf | train | public static int findLastIndexOf(Object self, int startIndex, Closure closure) {
int result = -1;
int i = 0;
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); i++) {
Object value = iter.next();
if (i < startIndex) {
continue;
}
if (bcw.call(value)) {
result = i;
}
}
return result;
} | java | {
"resource": ""
} |
q74 | DefaultGroovyMethods.findIndexValues | train | public static List<Number> findIndexValues(Object self, Closure closure) {
return findIndexValues(self, 0, closure);
} | java | {
"resource": ""
} |
q75 | DefaultGroovyMethods.findIndexValues | train | public static List<Number> findIndexValues(Object self, Number startIndex, Closure closure) {
List<Number> result = new ArrayList<Number>();
long count = 0;
long startCount = startIndex.longValue();
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); count++) {
Object value = iter.next();
if (count < startCount) {
continue;
}
if (bcw.call(value)) {
result.add(count);
}
}
return result;
} | java | {
"resource": ""
} |
q76 | HandleMetaClass.getProperty | train | public Object getProperty(String property) {
if(ExpandoMetaClass.isValidExpandoProperty(property)) {
if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) ||
property.equals(ExpandoMetaClass.CONSTRUCTOR) ||
myMetaClass.hasProperty(this, property) == null) {
return replaceDelegate().getProperty(property);
}
}
return myMetaClass.getProperty(this, property);
} | java | {
"resource": ""
} |
q77 | Message.create | train | public static Message create( String text, Object data, ProcessingUnit owner )
{
return new SimpleMessage( text, data, owner);
} | java | {
"resource": ""
} |
q78 | JsonDelegate.invokeMethod | train | public Object invokeMethod(String name, Object args) {
Object val = null;
if (args != null && Object[].class.isAssignableFrom(args.getClass())) {
Object[] arr = (Object[]) args;
if (arr.length == 1) {
val = arr[0];
} else if (arr.length == 2 && arr[0] instanceof Collection && arr[1] instanceof Closure) {
Closure<?> closure = (Closure<?>) arr[1];
Iterator<?> iterator = ((Collection) arr[0]).iterator();
List<Object> list = new ArrayList<Object>();
while (iterator.hasNext()) {
list.add(curryDelegateAndGetContent(closure, iterator.next()));
}
val = list;
} else {
val = Arrays.asList(arr);
}
}
content.put(name, val);
return val;
} | java | {
"resource": ""
} |
q79 | Binding.setVariable | train | public void setVariable(String name, Object value) {
if (variables == null)
variables = new LinkedHashMap();
variables.put(name, value);
} | java | {
"resource": ""
} |
q80 | MetaBeanProperty.getProperty | train | public Object getProperty(Object object) {
MetaMethod getter = getGetter();
if (getter == null) {
if (field != null) return field.getProperty(object);
//TODO: create a WriteOnlyException class?
throw new GroovyRuntimeException("Cannot read write-only property: " + name);
}
return getter.invoke(object, MetaClassHelper.EMPTY_ARRAY);
} | java | {
"resource": ""
} |
q81 | MetaBeanProperty.setProperty | train | public void setProperty(Object object, Object newValue) {
MetaMethod setter = getSetter();
if (setter == null) {
if (field != null && !Modifier.isFinal(field.getModifiers())) {
field.setProperty(object, newValue);
return;
}
throw new GroovyRuntimeException("Cannot set read-only property: " + name);
}
newValue = DefaultTypeTransformation.castToType(newValue, getType());
setter.invoke(object, new Object[]{newValue});
} | java | {
"resource": ""
} |
q82 | MetaBeanProperty.getModifiers | train | public int getModifiers() {
MetaMethod getter = getGetter();
MetaMethod setter = getSetter();
if (setter != null && getter == null) return setter.getModifiers();
if (getter != null && setter == null) return getter.getModifiers();
int modifiers = getter.getModifiers() | setter.getModifiers();
int visibility = 0;
if (Modifier.isPublic(modifiers)) visibility = Modifier.PUBLIC;
if (Modifier.isProtected(modifiers)) visibility = Modifier.PROTECTED;
if (Modifier.isPrivate(modifiers)) visibility = Modifier.PRIVATE;
int states = getter.getModifiers() & setter.getModifiers();
states &= ~(Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE);
states |= visibility;
return states;
} | java | {
"resource": ""
} |
q83 | Traits.isTrait | train | public static boolean isTrait(final ClassNode cNode) {
return cNode!=null
&& ((cNode.isInterface() && !cNode.getAnnotations(TRAIT_CLASSNODE).isEmpty())
|| isAnnotatedWithTrait(cNode));
} | java | {
"resource": ""
} |
q84 | Traits.getBridgeMethodTarget | train | public static Method getBridgeMethodTarget(Method someMethod) {
TraitBridge annotation = someMethod.getAnnotation(TraitBridge.class);
if (annotation==null) {
return null;
}
Class aClass = annotation.traitClass();
String desc = annotation.desc();
for (Method method : aClass.getDeclaredMethods()) {
String methodDescriptor = BytecodeHelper.getMethodDescriptor(method.getReturnType(), method.getParameterTypes());
if (desc.equals(methodDescriptor)) {
return method;
}
}
return null;
} | java | {
"resource": ""
} |
q85 | FindReplaceUtility.findNext | train | private static int findNext(boolean reverse, int pos) {
boolean backwards = IS_BACKWARDS_CHECKBOX.isSelected();
backwards = backwards ? !reverse : reverse;
String pattern = (String) FIND_FIELD.getSelectedItem();
if (pattern != null && pattern.length() > 0) {
try {
Document doc = textComponent.getDocument();
doc.getText(0, doc.getLength(), SEGMENT);
}
catch (Exception e) {
// should NEVER reach here
e.printStackTrace();
}
pos += textComponent.getSelectedText() == null ?
(backwards ? -1 : 1) : 0;
char first = backwards ?
pattern.charAt(pattern.length() - 1) : pattern.charAt(0);
char oppFirst = Character.isUpperCase(first) ?
Character.toLowerCase(first) : Character.toUpperCase(first);
int start = pos;
boolean wrapped = WRAP_SEARCH_CHECKBOX.isSelected();
int end = backwards ? 0 : SEGMENT.getEndIndex();
pos += backwards ? -1 : 1;
int length = textComponent.getDocument().getLength();
if (pos > length) {
pos = wrapped ? 0 : length;
}
boolean found = false;
while (!found && (backwards ? pos > end : pos < end)) {
found = !MATCH_CASE_CHECKBOX.isSelected() && SEGMENT.array[pos] == oppFirst;
found = found ? found : SEGMENT.array[pos] == first;
if (found) {
pos += backwards ? -(pattern.length() - 1) : 0;
for (int i = 0; found && i < pattern.length(); i++) {
char c = pattern.charAt(i);
found = SEGMENT.array[pos + i] == c;
if (!MATCH_CASE_CHECKBOX.isSelected() && !found) {
c = Character.isUpperCase(c) ?
Character.toLowerCase(c) :
Character.toUpperCase(c);
found = SEGMENT.array[pos + i] == c;
}
}
}
if (!found) {
pos += backwards ? -1 : 1;
if (pos == end && wrapped) {
pos = backwards ? SEGMENT.getEndIndex() : 0;
end = start;
wrapped = false;
}
}
}
pos = found ? pos : -1;
}
return pos;
} | java | {
"resource": ""
} |
q86 | IndyInterface.invalidateSwitchPoints | train | protected static void invalidateSwitchPoints() {
if (LOG_ENABLED) {
LOG.info("invalidating switch point");
}
SwitchPoint old = switchPoint;
switchPoint = new SwitchPoint();
synchronized(IndyInterface.class) { SwitchPoint.invalidateAll(new SwitchPoint[]{old}); }
} | java | {
"resource": ""
} |
q87 | IndyInterface.bootstrapCurrent | train | public static CallSite bootstrapCurrent(Lookup caller, String name, MethodType type) {
return realBootstrap(caller, name, CALL_TYPES.METHOD.ordinal(), type, false, true, false);
} | java | {
"resource": ""
} |
q88 | IndyInterface.realBootstrap | train | private static CallSite realBootstrap(Lookup caller, String name, int callID, MethodType type, boolean safe, boolean thisCall, boolean spreadCall) {
// since indy does not give us the runtime types
// we produce first a dummy call site, which then changes the target to one,
// that does the method selection including the the direct call to the
// real method.
MutableCallSite mc = new MutableCallSite(type);
MethodHandle mh = makeFallBack(mc,caller.lookupClass(),name,callID,type,safe,thisCall,spreadCall);
mc.setTarget(mh);
return mc;
} | java | {
"resource": ""
} |
q89 | TableLayout.addCell | train | public void addCell(TableLayoutCell cell) {
GridBagConstraints constraints = cell.getConstraints();
constraints.insets = new Insets(cellpadding, cellpadding, cellpadding, cellpadding);
add(cell.getComponent(), constraints);
} | java | {
"resource": ""
} |
q90 | CompileUnit.addClass | train | public void addClass(ClassNode node) {
node = node.redirect();
String name = node.getName();
ClassNode stored = classes.get(name);
if (stored != null && stored != node) {
// we have a duplicate class!
// One possibility for this is, that we declared a script and a
// class in the same file and named the class like the file
SourceUnit nodeSource = node.getModule().getContext();
SourceUnit storedSource = stored.getModule().getContext();
String txt = "Invalid duplicate class definition of class " + node.getName() + " : ";
if (nodeSource == storedSource) {
// same class in same source
txt += "The source " + nodeSource.getName() + " contains at least two definitions of the class " + node.getName() + ".\n";
if (node.isScriptBody() || stored.isScriptBody()) {
txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" +
" the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
}
} else {
txt += "The sources " + nodeSource.getName() + " and " + storedSource.getName() + " each contain a class with the name " + node.getName() + ".\n";
}
nodeSource.getErrorCollector().addErrorAndContinue(
new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), nodeSource)
);
}
classes.put(name, node);
if (classesToCompile.containsKey(name)) {
ClassNode cn = classesToCompile.get(name);
cn.setRedirect(node);
classesToCompile.remove(name);
}
} | java | {
"resource": ""
} |
q91 | LoaderConfiguration.getSlashyPath | train | private String getSlashyPath(final String path) {
String changedPath = path;
if (File.separatorChar != '/')
changedPath = changedPath.replace(File.separatorChar, '/');
return changedPath;
} | java | {
"resource": ""
} |
q92 | NioGroovyMethods.write | train | public static void write(Path self, String text, String charset) throws IOException {
Writer writer = null;
try {
writer = new OutputStreamWriter(Files.newOutputStream(self, CREATE, APPEND), Charset.forName(charset));
writer.write(text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | {
"resource": ""
} |
q93 | NioGroovyMethods.append | train | public static void append(Path self, Object text) throws IOException {
Writer writer = null;
try {
writer = new OutputStreamWriter(Files.newOutputStream(self, CREATE, APPEND), Charset.defaultCharset());
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.close();
} finally {
closeWithWarning(writer);
}
} | java | {
"resource": ""
} |
q94 | StringGroovyMethods.count | train | public static int count(CharSequence self, CharSequence text) {
int answer = 0;
for (int idx = 0; true; idx++) {
idx = self.toString().indexOf(text.toString(), idx);
// break once idx goes to -1 or for case of empty string once
// we get to the end to avoid JDK library bug (see GROOVY-5858)
if (idx < answer) break;
++answer;
}
return answer;
} | java | {
"resource": ""
} |
q95 | StringGroovyMethods.eachMatch | train | public static <T extends CharSequence> T eachMatch(T self, CharSequence regex, @ClosureParams(value=FromString.class, options={"List<String>","String[]"}) Closure closure) {
eachMatch(self.toString(), regex.toString(), closure);
return self;
} | java | {
"resource": ""
} |
q96 | StringGroovyMethods.eachMatch | train | public static String eachMatch(String self, String regex, @ClosureParams(value=FromString.class, options={"List<String>","String[]"}) Closure closure) {
return eachMatch(self, Pattern.compile(regex), closure);
} | java | {
"resource": ""
} |
q97 | StringGroovyMethods.expandLine | train | public static String expandLine(CharSequence self, int tabStop) {
String s = self.toString();
int index;
while ((index = s.indexOf('\t')) != -1) {
StringBuilder builder = new StringBuilder(s);
int count = tabStop - index % tabStop;
builder.deleteCharAt(index);
for (int i = 0; i < count; i++) builder.insert(index, " ");
s = builder.toString();
}
return s;
} | java | {
"resource": ""
} |
q98 | StringGroovyMethods.find | train | public static String find(CharSequence self, CharSequence regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure closure) {
return find(self.toString(), Pattern.compile(regex.toString()), closure);
} | java | {
"resource": ""
} |
q99 | StringGroovyMethods.getAt | train | public static String getAt(CharSequence self, Collection indices) {
StringBuilder answer = new StringBuilder();
for (Object value : indices) {
if (value instanceof Range) {
answer.append(getAt(self, (Range) value));
} else if (value instanceof Collection) {
answer.append(getAt(self, (Collection) value));
} else {
int idx = DefaultTypeTransformation.intUnbox(value);
answer.append(getAt(self, idx));
}
}
return answer.toString();
} | java | {
"resource": ""
} |