<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.byteCode;

import com.facebook.presto.byteCode.debug.LocalVariableNode;
import com.facebook.presto.byteCode.instruction.LabelNode;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.tree.InsnNode;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;

import static com.facebook.presto.byteCode.Access.STATIC;
import static com.facebook.presto.byteCode.Access.toAccessModifier;
import static com.facebook.presto.byteCode.NamedParameterDefinition.getNamedParameterType;
import static com.facebook.presto.byteCode.NamedParameterDefinition.getSourceString;
import static com.facebook.presto.byteCode.ParameterizedType.getParameterType;
import static com.facebook.presto.byteCode.ParameterizedType.toParameterizedType;
import static com.facebook.presto.byteCode.ParameterizedType.type;
import static com.google.common.collect.Iterables.transform;
import static org.objectweb.asm.Opcodes.RETURN;

@NotThreadSafe
public class MethodDefinition
{
    private final CompilerContext compilerContext;
    private final ClassDefinition declaringClass;
    private final EnumSet<Access> access;
    private final String name;
    private final List<AnnotationDefinition> annotations = new ArrayList<>();
    private final ParameterizedType returnType;
    private final List<NamedParameterDefinition> parameters;
    private final List<ParameterizedType> parameterTypes;
    private final List<List<AnnotationDefinition>> parameterAnnotations;
    private final List<ParameterizedType> exceptions = new ArrayList<>();
    private final List<LocalVariableNode> localVariableNodes = new ArrayList<>();

    private final Block body;
    private String comment;

    public MethodDefinition(
            CompilerContext compilerContext, ClassDefinition declaringClass,
            EnumSet<Access> access,
            String name,
            ParameterizedType returnType,
            NamedParameterDefinition... parameters
    )
    {
        this(compilerContext, declaringClass, access, name, returnType, ImmutableList.copyOf(parameters));
    }

    public MethodDefinition(
            CompilerContext compilerContext,
            ClassDefinition declaringClass,
            EnumSet<Access> access,
            String name,
            ParameterizedType returnType,
            Iterable<NamedParameterDefinition> parameters
    )
    {
        this.compilerContext = compilerContext;
        this.declaringClass = declaringClass;
        body = new Block(compilerContext);

        this.access = access;
        this.name = name;
        if (returnType != null) {
            this.returnType = returnType;
        }
        else {
            this.returnType = type(void.class);
        }
        this.parameters = ImmutableList.copyOf(parameters);
        this.parameterTypes = Lists.transform(this.parameters, getNamedParameterType());
        this.parameterAnnotations = ImmutableList.copyOf(transform(parameters, new Function<NamedParameterDefinition, List<AnnotationDefinition>>()
        {
            @Override
            public List<AnnotationDefinition> apply(@Nullable NamedParameterDefinition input)
            {
                return new ArrayList<>();
            }
        }));

        if (!access.contains(STATIC)) {
            getCompilerContext().declareThisVariable(type(Object.class));
        }
        int argId = 0;
        for (NamedParameterDefinition parameter : parameters) {
            String parameterName = parameter.getName();
            if (parameterName == null) {
                parameterName = "arg" + argId;
            }
            getCompilerContext().declareParameter(parameter.getType(), parameterName);
            argId++;
        }
    }

    public ClassDefinition getDeclaringClass()
    {
        return declaringClass;
    }

    public List<AnnotationDefinition> getAnnotations()
    {<commit_msg>Declare "this" variable with correct type<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.byteCode;

import com.facebook.presto.byteCode.debug.LocalVariableNode;
import com.facebook.presto.byteCode.instruction.LabelNode;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.tree.InsnNode;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;

import static com.facebook.presto.byteCode.Access.STATIC;
import static com.facebook.presto.byteCode.Access.toAccessModifier;
import static com.facebook.presto.byteCode.NamedParameterDefinition.getNamedParameterType;
import static com.facebook.presto.byteCode.NamedParameterDefinition.getSourceString;
import static com.facebook.presto.byteCode.ParameterizedType.getParameterType;
import static com.facebook.presto.byteCode.ParameterizedType.toParameterizedType;
import static com.facebook.presto.byteCode.ParameterizedType.type;
import static com.google.common.collect.Iterables.transform;
import static org.objectweb.asm.Opcodes.RETURN;

@NotThreadSafe
public class MethodDefinition
{
    private final CompilerContext compilerContext;
    private final ClassDefinition declaringClass;
    private final EnumSet<Access> access;
    private final String name;
    private final List<AnnotationDefinition> annotations = new ArrayList<>();
    private final ParameterizedType returnType;
    private final List<NamedParameterDefinition> parameters;
    private final List<ParameterizedType> parameterTypes;
    private final List<List<AnnotationDefinition>> parameterAnnotations;
    private final List<ParameterizedType> exceptions = new ArrayList<>();
    private final List<LocalVariableNode> localVariableNodes = new ArrayList<>();

    private final Block body;
    private String comment;

    public MethodDefinition(
            CompilerContext compilerContext, ClassDefinition declaringClass,
            EnumSet<Access> access,
            String name,
            ParameterizedType returnType,
            NamedParameterDefinition... parameters
    )
    {
        this(compilerContext, declaringClass, access, name, returnType, ImmutableList.copyOf(parameters));
    }

    public MethodDefinition(
            CompilerContext compilerContext,
            ClassDefinition declaringClass,
            EnumSet<Access> access,
            String name,
            ParameterizedType returnType,
            Iterable<NamedParameterDefinition> parameters
    )
    {
        this.compilerContext = compilerContext;
        this.declaringClass = declaringClass;
        body = new Block(compilerContext);

        this.access = access;
        this.name = name;
        if (returnType != null) {
            this.returnType = returnType;
        }
        else {
            this.returnType = type(void.class);
        }
        this.parameters = ImmutableList.copyOf(parameters);
        this.parameterTypes = Lists.transform(this.parameters, getNamedParameterType());
        this.parameterAnnotations = ImmutableList.copyOf(transform(parameters, new Function<NamedParameterDefinition, List<AnnotationDefinition>>()
        {
            @Override
            public List<AnnotationDefinition> apply(@Nullable NamedParameterDefinition input)
            {
                return new ArrayList<>();
            }
        }));

        if (!access.contains(STATIC)) {
            getCompilerContext().declareThisVariable(declaringClass.getType());
        }
        int argId = 0;
        for (NamedParameterDefinition parameter : parameters) {
            String parameterName = parameter.getName();
            if (parameterName == null) {
                parameterName = "arg" + argId;
            }
            getCompilerContext().declareParameter(parameter.getType(), parameterName);
            argId++;
        }
    }

    public ClassDefinition getDeclaringClass()
    {
        return declaringClass;
    }

    public List<AnnotationDefinition> getAnnotations()
    {
{'fraction_non_alphanumeric': 0.08098518054685869, 'fraction_numerical': 0.0010436234606553956, 'mean_word_length': 3.367821330902461, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5109647', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2323, 'n_words': 603}