<commit_before>/*
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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 org.apache.flex.compiler.internal.codegen.externals.reference;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.flex.compiler.clients.ExternCConfiguration.ExcludedMember;
import org.apache.flex.compiler.internal.codegen.externals.utils.FunctionUtils;

import com.google.common.collect.Lists;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.jstype.JSType;

public class MethodReference extends MemberReference
{

    private boolean isStatic;
    private MethodReference override;
    private Node paramNode;

    private List<ParameterReference> parameters;

    private MethodReference getContext()
    {
        return override == null ? this : override;
    }

    public boolean isStatic()
    {
        return isStatic;
    }

    public void setStatic(boolean isStatic)
    {
        this.isStatic = isStatic;
    }

    public List<ParameterReference> getParameters()
    {
        return parameters;
    }

    public Set<String> getParameterNames()
    {
        return getComment().getParameterNames();
    }

    public String toReturnTypeAnnotationString()
    {
        JSType jsType = getModel().evaluate(getComment().getReturnType());
        return jsType.toAnnotationString();
    }

    public MethodReference(ReferenceModel model, ClassReference classReference, Node node, String name,
            JSDocInfo comment, boolean isStatic)
    {
        super(model, classReference, node, name, comment);
        this.isStatic = isStatic;

        if (node.isFunction())
        {
            this.paramNode = node.getChildAtIndex(1);
        }
        else if (node.getLastChild().isFunction())
        {
            this.paramNode = node.getLastChild().getChildAtIndex(1);
        }

        addParameterReferences();
    }

    private void addParameterReferences()
    {

        parameters = new ArrayList<ParameterReference>();

        if (paramNode != null)
        {

            final boolean isDocumented = comment.getParameterCount() > 0;
            List<String> parameterNames = null;

            if (isDocumented)
            {
                parameterNames = Lists.newArrayList(comment.getParameterNames());
            }

            for (Node param : paramNode.children())
            {
                ParameterReference parameterReference;

                if (isDocumented && parameterNames.contains(param.getString()))
                {
                    final String qualifiedName = FunctionUtils.toParameterType(this, param.getString());
                    parameterReference = new ParameterReference(getModel(), param, qualifiedName);
                }
                else
                {
                    parameterReference = new ParameterReference(getModel(), param);
                }

                parameters.add(parameterReference);
            }
        }
    }

    @Override
    public void emit(StringBuilder sb)
    {
    	String className = getClassReference().getBaseName();
    	
        // XXX HACK TEMP!
        if (getComment().isConstructor() && !getBaseName().equals(className))
            return;

        if (isConstructor())
        {
            emitConstructor(sb);
            return;
        }

        String qName = getQualifiedName();
        // allow overrides of toString for Number, int and uint
        if (!qName.equals("toString") && getClassReference().hasSuperMethod(qName))
            return;
        else if (qName.equals("toString") &&
        		!(className.equals("Number") || className.equals("int") || className.equals("uint")))
        	return;

        emitComment(sb);

        ExcludedMember excluded = isExcluded();
        if (excluded != null)
        {
            excluded.print(sb);
        }

        emitCode(sb);

        override = null;
    }

    public void emitCode(StringBuilder sb)
    {
        String staticValue = (isStatic) ? "static " : "";
        if (getClassReference().isInterface())
            staticValue = "";
<commit_msg>fixed missing toString() in externc output<commit_after>/*
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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 org.apache.flex.compiler.internal.codegen.externals.reference;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.flex.compiler.clients.ExternCConfiguration.ExcludedMember;
import org.apache.flex.compiler.internal.codegen.externals.utils.FunctionUtils;

import com.google.common.collect.Lists;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.jstype.JSType;

public class MethodReference extends MemberReference
{

    private boolean isStatic;
    private MethodReference override;
    private Node paramNode;

    private List<ParameterReference> parameters;

    private MethodReference getContext()
    {
        return override == null ? this : override;
    }

    public boolean isStatic()
    {
        return isStatic;
    }

    public void setStatic(boolean isStatic)
    {
        this.isStatic = isStatic;
    }

    public List<ParameterReference> getParameters()
    {
        return parameters;
    }

    public Set<String> getParameterNames()
    {
        return getComment().getParameterNames();
    }

    public String toReturnTypeAnnotationString()
    {
        JSType jsType = getModel().evaluate(getComment().getReturnType());
        return jsType.toAnnotationString();
    }

    public MethodReference(ReferenceModel model, ClassReference classReference, Node node, String name,
            JSDocInfo comment, boolean isStatic)
    {
        super(model, classReference, node, name, comment);
        this.isStatic = isStatic;

        if (node.isFunction())
        {
            this.paramNode = node.getChildAtIndex(1);
        }
        else if (node.getLastChild().isFunction())
        {
            this.paramNode = node.getLastChild().getChildAtIndex(1);
        }

        addParameterReferences();
    }

    private void addParameterReferences()
    {

        parameters = new ArrayList<ParameterReference>();

        if (paramNode != null)
        {

            final boolean isDocumented = comment.getParameterCount() > 0;
            List<String> parameterNames = null;

            if (isDocumented)
            {
                parameterNames = Lists.newArrayList(comment.getParameterNames());
            }

            for (Node param : paramNode.children())
            {
                ParameterReference parameterReference;

                if (isDocumented && parameterNames.contains(param.getString()))
                {
                    final String qualifiedName = FunctionUtils.toParameterType(this, param.getString());
                    parameterReference = new ParameterReference(getModel(), param, qualifiedName);
                }
                else
                {
                    parameterReference = new ParameterReference(getModel(), param);
                }

                parameters.add(parameterReference);
            }
        }
    }

    @Override
    public void emit(StringBuilder sb)
    {
    	String className = getClassReference().getBaseName();
    	
        // XXX HACK TEMP!
        if (getComment().isConstructor() && !getBaseName().equals(className))
            return;

        if (isConstructor())
        {
            emitConstructor(sb);
            return;
        }

        String qName = getQualifiedName();
        // allow overrides of toString for Number, int and uint
        if (!qName.equals("toString") && getClassReference().hasSuperMethod(qName))
            return;
        else if (qName.equals("toString") && className.equals("Object"))
        	return;

        emitComment(sb);

        ExcludedMember excluded = isExcluded();
        if (excluded != null)
        {
            excluded.print(sb);
        }

        emitCode(sb);

        override = null;
    }

    public void emitCode(StringBuilder sb)
    {
        String staticValue = (isStatic) ? "static " : "";
        if (getClassReference().isInterface())
            staticValue = "";

{'fraction_non_alphanumeric': 0.09183777709674124, 'fraction_numerical': 0.00143017672898151, 'mean_word_length': 2.3573388203017833, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '5049040', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2420, 'n_words': 657}