<commit_before>package com.reason.lang.core.psi.impl;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.util.IncorrectOperationException;
import com.reason.lang.core.RmlPsiUtil;
import com.reason.lang.core.psi.*;
import com.reason.lang.core.stub.ModuleStub;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;

public class PsiFileModuleImpl extends PsiModuleImpl {
    public PsiFileModuleImpl(@NotNull ModuleStub stub, @NotNull IStubElementType nodeType) {
        super(stub, nodeType);
    }

    public PsiFileModuleImpl(@NotNull ASTNode node) {
        super(node);
    }

    @Nullable
    @Override
    public PsiSignature getSignature() {
        return null;
    }

    @Nullable
    @Override
    public PsiScopedExpr getBody() {
        return null;
    }

    @NotNull
    @Override
    public Collection<PsiModule> getModules() {
        Collection<PsiModule> result = new ArrayList<>();

        PsiElement element = getFirstChild();
        while (element != null) {
            if (element instanceof PsiModule) {
                result.add((PsiModule) element);
            }
            element = element.getNextSibling();
        }

        return result;
    }

    @NotNull
    @Override
    public Collection<PsiNamedElement> getExpressions() {
        Collection<PsiNamedElement> result = new ArrayList<>();

        PsiElement element = getFirstChild();
        while (element != null) {
            if (element instanceof PsiType || element instanceof PsiModule || element instanceof PsiLet || element instanceof PsiExternal || element instanceof PsiVal) {
                result.add((PsiNamedElement) element);
            }
            element = element.getNextSibling();
        }

        return result;
    }

    @Nullable
    @Override
    public PsiElement getNameIdentifier() {
        return null;
    }

    @Override
    public String getName() {
        return getQualifiedName();
    }

    @Nullable
    @Override
    public String getQualifiedName() {
        ModuleStub stub = getGreenStub();
        if (stub != null) {
            return stub.getQualifiedName();
        }

        return RmlPsiUtil.fileNameToModuleName(getContainingFile());
    }

    @Override
    public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
        return null;
    }

    @Override
    public boolean isComponent() {
        return false;
    }

    @Override
    public String toString() {
        return "FileModule(" + getQualifiedName() + ")";
    }
}<commit_msg>Detect if a file is a React component (naive implementation)<commit_after>package com.reason.lang.core.psi.impl;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import com.reason.lang.core.RmlPsiUtil;
import com.reason.lang.core.psi.*;
import com.reason.lang.core.stub.ModuleStub;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class PsiFileModuleImpl extends PsiModuleImpl {
    public PsiFileModuleImpl(@NotNull ModuleStub stub, @NotNull IStubElementType nodeType) {
        super(stub, nodeType);
    }

    public PsiFileModuleImpl(@NotNull ASTNode node) {
        super(node);
    }

    @Nullable
    @Override
    public PsiSignature getSignature() {
        return null;
    }

    @Nullable
    @Override
    public PsiScopedExpr getBody() {
        return null;
    }

    @NotNull
    @Override
    public Collection<PsiModule> getModules() {
        Collection<PsiModule> result = new ArrayList<>();

        PsiElement element = getFirstChild();
        while (element != null) {
            if (element instanceof PsiModule) {
                result.add((PsiModule) element);
            }
            element = element.getNextSibling();
        }

        return result;
    }

    @NotNull
    @Override
    public Collection<PsiNamedElement> getExpressions() {
        Collection<PsiNamedElement> result = new ArrayList<>();

        PsiElement element = getFirstChild();
        while (element != null) {
            if (element instanceof PsiType || element instanceof PsiModule || element instanceof PsiLet || element instanceof PsiExternal || element instanceof PsiVal) {
                result.add((PsiNamedElement) element);
            }
            element = element.getNextSibling();
        }

        return result;
    }

    @Nullable
    @Override
    public PsiElement getNameIdentifier() {
        return null;
    }

    @Override
    public String getName() {
        return getQualifiedName();
    }

    @Nullable
    @Override
    public String getQualifiedName() {
        ModuleStub stub = getGreenStub();
        if (stub != null) {
            return stub.getQualifiedName();
        }

        return RmlPsiUtil.fileNameToModuleName(getContainingFile());
    }

    @Override
    public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
        return null;
    }

    @Override
    public boolean isComponent() {
        ModuleStub stub = getGreenStub();
        if (stub != null) {
            return stub.isComponent();
        }

        // naive detection

        List<PsiLet> expressions = PsiTreeUtil.getStubChildrenOfTypeAsList(this, PsiLet.class);
        PsiLet componentDef = null;
        PsiLet makeDef = null;
        for (PsiLet let : expressions) {
            if (componentDef == null && "component".equals(let.getName())) {
                componentDef = let;
            } else if (makeDef == null && "make".equals(let.getName())) {
                makeDef = let;
            } else if (componentDef != null && makeDef != null) {
                break;
            }
        }

        return componentDef != null && makeDef != null;
    }

    @Override
    public String toString() {
        return "FModule " + getQualifiedName();
    }
}
{'fraction_non_alphanumeric': 0.09661370566522227, 'fraction_numerical': 0.0, 'mean_word_length': 2.4913165266106443, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2497079', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1686, 'n_words': 400}