<commit_before>/*
 * Copyright 2003-2007 <NAME>, <NAME>
 *
 * 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.siyeh.ig.bugs;

import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.*;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.ClassUtils;
import com.siyeh.ig.psiutils.LibraryUtil;
import com.siyeh.ig.ui.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class IgnoreResultOfCallInspection extends BaseInspection {

    /** @noinspection PublicField*/
    public boolean m_reportAllNonLibraryCalls = false;

    /** @noinspection PublicField*/
    @NonNls public String callCheckString = "java.io.InputStream,read," +
        "java.io.InputStream,skip," +
        "java.lang.StringBuffer,toString," +
        "java.lang.StringBuilder,toString," +
        "java.lang.String,.*," +
        "java.math.BigInteger,.*," +
        "java.math.BigDecimal,.*," +
        "java.net.InetAddress,.*";

    final List<String> methodNamePatterns = new ArrayList();
    final List<String> classNames = new ArrayList();
    Map<String, Pattern> patternCache = null;

    public IgnoreResultOfCallInspection(){
        parseCallCheckString();
    }

    @NotNull
    public String getID(){
        return "ResultOfMethodCallIgnored";
    }

    @NotNull
    public String getDisplayName(){
        return InspectionGadgetsBundle.message(
                "result.of.method.call.ignored.display.name");
    }

    @NotNull
    public String buildErrorString(Object... infos){
        final PsiClass containingClass = (PsiClass)infos[0];
        final String className = containingClass.getName();
        return InspectionGadgetsBundle.message(
                "result.of.method.call.ignored.problem.descriptor",
                className);
    }

    public void readSettings(Element element) throws InvalidDataException{
        super.readSettings(element);
        parseCallCheckString();
    }

    private void parseCallCheckString(){
        final String[] strings = callCheckString.split(",");
        methodNamePatterns.clear();
        classNames.clear();
        patternCache = null;
        for (int i = 0; i < strings.length - 1; i += 2){
            final String className = strings[i];
            classNames.add(className);
            final String methodNamePattern = strings[i + 1];
            methodNamePatterns.add(methodNamePattern);
        }
    }

    public void writeSettings(Element element) throws WriteExternalException{
        formatCallCheckString();
        super.writeSettings(element);
    }

    private void formatCallCheckString(){
        final StringBuilder buffer = new StringBuilder();
        final int size = methodNamePatterns.size();
        if (size > 0) {
            buffer.append(classNames.get(0));
            buffer.append(',');
            buffer.append(methodNamePatterns.get(0));
            for (int i = 1; i < size; i++) {
                buffer.append(classNames.get(i));
                buffer.append(',');
                buffer.append(methodNamePatterns.get(0));
            }
        }
        callCheckString = buffer.toString();
    }

    public JComponent createOptionsPanel(){
        final Form form = new Form();
        return form.getContentPanel();
    }

    public boolean isEnabledByDefault(){
        return true;
    }

    public BaseInspectionVisitor buildVisitor(){
        return new IgnoreResultOfCallVisitor();
    }

    private class IgnoreResultOfCallVisitor extends BaseInspectionVisitor{
<commit_msg>write settings fix<commit_after>/*
 * Copyright 2003-2007 <NAME>, <NAME>
 *
 * 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.siyeh.ig.bugs;

import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.*;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.ClassUtils;
import com.siyeh.ig.psiutils.LibraryUtil;
import com.siyeh.ig.ui.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class IgnoreResultOfCallInspection extends BaseInspection {

    /** @noinspection PublicField*/
    public boolean m_reportAllNonLibraryCalls = false;

    /** @noinspection PublicField*/
    @NonNls public String callCheckString = "java.io.InputStream,read," +
        "java.io.InputStream,skip," +
        "java.lang.StringBuffer,toString," +
        "java.lang.StringBuilder,toString," +
        "java.lang.String,.*," +
        "java.math.BigInteger,.*," +
        "java.math.BigDecimal,.*," +
        "java.net.InetAddress,.*";

    final List<String> methodNamePatterns = new ArrayList();
    final List<String> classNames = new ArrayList();
    Map<String, Pattern> patternCache = null;

    public IgnoreResultOfCallInspection(){
        parseCallCheckString();
    }

    @NotNull
    public String getID(){
        return "ResultOfMethodCallIgnored";
    }

    @NotNull
    public String getDisplayName(){
        return InspectionGadgetsBundle.message(
                "result.of.method.call.ignored.display.name");
    }

    @NotNull
    public String buildErrorString(Object... infos){
        final PsiClass containingClass = (PsiClass)infos[0];
        final String className = containingClass.getName();
        return InspectionGadgetsBundle.message(
                "result.of.method.call.ignored.problem.descriptor",
                className);
    }

    public void readSettings(Element element) throws InvalidDataException{
        super.readSettings(element);
        parseCallCheckString();
    }

    private void parseCallCheckString(){
        final String[] strings = callCheckString.split(",");
        methodNamePatterns.clear();
        classNames.clear();
        patternCache = null;
        for (int i = 0; i < strings.length - 1; i += 2){
            final String className = strings[i];
            classNames.add(className);
            final String methodNamePattern = strings[i + 1];
            methodNamePatterns.add(methodNamePattern);
        }
    }

    public void writeSettings(Element element) throws WriteExternalException{
        formatCallCheckString();
        super.writeSettings(element);
    }

    private void formatCallCheckString(){
        final StringBuilder buffer = new StringBuilder();
        final int size = methodNamePatterns.size();
        if (size > 0) {
            buffer.append(classNames.get(0));
            buffer.append(',');
            buffer.append(methodNamePatterns.get(0));
            for (int i = 1; i < size; i++) {
                buffer.append(',');
                buffer.append(classNames.get(i));
                buffer.append(',');
                buffer.append(methodNamePatterns.get(i));
            }
        }
        callCheckString = buffer.toString();
    }

    public JComponent createOptionsPanel(){
        final Form form = new Form();
        return form.getContentPanel();
    }

    public boolean isEnabledByDefault(){
        return true;
    }

    public BaseInspectionVisitor buildVisitor(){
        return new IgnoreResultOfCallVisitor();
    }

    private class IgnoreResultOfCallVisitor extends BaseInspectionVisitor{

{'fraction_non_alphanumeric': 0.10519898015741048, 'fraction_numerical': 0.004766655581421128, 'mean_word_length': 2.9657142857142857, 'pattern_counts': {'":': 0, '<': 17, '<?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': '6443480', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2440, 'n_words': 603}