Search in sources :

Example 16 with IntRange

use of org.apache.commons.lang.math.IntRange in project pinot by linkedin.

the class DataGenerator method init.

public void init(DataGeneratorSpec spec) throws IOException {
    genSpec = spec;
    outDir = new File(genSpec.getOutputDir());
    if (outDir.exists() && !genSpec.isOverrideOutDir()) {
        LOGGER.error("output directory already exists, and override is set to false");
        throw new RuntimeException("output directory exists");
    }
    if (outDir.exists()) {
        FileUtils.deleteDirectory(outDir);
    }
    outDir.mkdir();
    for (final String column : genSpec.getColumns()) {
        DataType dataType = genSpec.getDataTypesMap().get(column);
        if (genSpec.getCardinalityMap().containsKey(column)) {
            generators.put(column, GeneratorFactory.getGeneratorFor(dataType, genSpec.getCardinalityMap().get(column)));
        } else if (genSpec.getRangeMap().containsKey(column)) {
            IntRange range = genSpec.getRangeMap().get(column);
            generators.put(column, GeneratorFactory.getGeneratorFor(dataType, range.getMinimumInteger(), range.getMaximumInteger()));
        } else {
            LOGGER.error("cardinality for this column does not exist : " + column);
            throw new RuntimeException("cardinality for this column does not exist");
        }
        generators.get(column).init();
    }
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) DataType(com.linkedin.pinot.common.data.FieldSpec.DataType) File(java.io.File)

Example 17 with IntRange

use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.

the class GotoSymbolContributor method getItemsFromCallDefinitionClause.

private void getItemsFromCallDefinitionClause(@NotNull List<NavigationItem> items, @NotNull EnclosingModularByCall enclosingModularByCall, @NotNull Map<CallDefinition.Tuple, CallDefinition> callDefinitionByTuple, @NotNull Call call) {
    Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(call);
    if (nameArityRange != null) {
        String callName = nameArityRange.first;
        IntRange arityRange = nameArityRange.second;
        Timed.Time time = CallDefinitionClause.time(call);
        Modular modular = enclosingModularByCall.putNew(call);
        if (modular == null) {
            // don't throw an error if really EEX, but has wrong extension
            if (!call.getText().contains("<%=")) {
                error("Cannot find enclosing Modular", call);
            }
        } else {
            for (int arity = arityRange.getMinimumInteger(); arity <= arityRange.getMaximumInteger(); arity++) {
                CallDefinition.Tuple tuple = new CallDefinition.Tuple(modular, time, callName, arity);
                CallDefinition callDefinition = callDefinitionByTuple.get(tuple);
                if (callDefinition == null) {
                    callDefinition = new CallDefinition(tuple.modular, tuple.time, tuple.name, tuple.arity);
                    items.add(callDefinition);
                    callDefinitionByTuple.put(tuple, callDefinition);
                }
                CallDefinitionClause callDefinitionClause = callDefinition.clause(call);
                items.add(callDefinitionClause);
            }
        }
    }
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) Modular(org.elixir_lang.structure_view.element.modular.Modular)

Example 18 with IntRange

use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.

the class ImportTest method testCallDefinitionClauseCallWhileImportModuleExceptNameArity.

public void testCallDefinitionClauseCallWhileImportModuleExceptNameArity() {
    myFixture.configureByFiles("import_module_except_name_arity.ex", "imported.ex");
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement maybeCall = elementAtCaret.getParent().getParent();
    assertInstanceOf(maybeCall, Call.class);
    Call call = (Call) maybeCall;
    assertTrue(Import.is(call));
    final ArrayList<Call> importedCallList = new ArrayList<Call>();
    Import.callDefinitionClauseCallWhile(call, new Function<Call, Boolean>() {

        @Override
        public Boolean fun(Call call) {
            importedCallList.add(call);
            return true;
        }
    });
    assertEquals(2, importedCallList.size());
    List<Pair<String, IntRange>> nameArityRangeList = ContainerUtil.map(importedCallList, new Function<Call, Pair<String, IntRange>>() {

        @Override
        public Pair<String, IntRange> fun(Call call) {
            return nameArityRange(call);
        }
    });
    assertContainsElements(Arrays.asList(pair("imported", new IntRange(1)), pair("imported", new IntRange(0))), nameArityRangeList);
}
Also used : Call(org.elixir_lang.psi.call.Call) ArrayList(java.util.ArrayList) IntRange(org.apache.commons.lang.math.IntRange) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Example 19 with IntRange

use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.

the class ImportTest method testCallDefinitionClauseCallWhileImportModuleOnlyNameArity.

public void testCallDefinitionClauseCallWhileImportModuleOnlyNameArity() {
    myFixture.configureByFiles("import_module_only_name_arity.ex", "imported.ex");
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement maybeCall = elementAtCaret.getParent().getParent();
    assertInstanceOf(maybeCall, Call.class);
    Call call = (Call) maybeCall;
    assertTrue(Import.is(call));
    final ArrayList<Call> importedCallList = new ArrayList<Call>();
    Import.callDefinitionClauseCallWhile(call, new Function<Call, Boolean>() {

        @Override
        public Boolean fun(Call call) {
            importedCallList.add(call);
            return true;
        }
    });
    assertEquals(1, importedCallList.size());
    Call importedCall = importedCallList.get(0);
    assertEquals(pair("imported", new IntRange(0)), nameArityRange(importedCall));
}
Also used : Call(org.elixir_lang.psi.call.Call) ArrayList(java.util.ArrayList) IntRange(org.apache.commons.lang.math.IntRange) PsiElement(com.intellij.psi.PsiElement)

Example 20 with IntRange

use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.

the class Import method onlyCallDefinitionClauseCallFilter.

@NotNull
private static Function<Call, Boolean> onlyCallDefinitionClauseCallFilter(PsiElement element) {
    final Map<String, List<Integer>> aritiesByName = aritiesByNameFromNameByArityKeywordList(element);
    return new Function<Call, Boolean>() {

        @Override
        public Boolean fun(Call call) {
            Pair<String, IntRange> callNameArityRange = nameArityRange(call);
            boolean include = false;
            if (callNameArityRange != null) {
                String callName = callNameArityRange.first;
                if (callName != null) {
                    List<Integer> arities = aritiesByName.get(callName);
                    if (arities != null) {
                        IntRange callArityRange = callNameArityRange.second;
                        for (int arity : arities) {
                            if (callArityRange.containsInteger(arity)) {
                                include = true;
                                break;
                            }
                        }
                    }
                }
            }
            return include;
        }
    };
}
Also used : Function(com.intellij.util.Function) Call(org.elixir_lang.psi.call.Call) IntRange(org.apache.commons.lang.math.IntRange) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IntRange (org.apache.commons.lang.math.IntRange)31 Call (org.elixir_lang.psi.call.Call)10 PsiElement (com.intellij.psi.PsiElement)6 File (java.io.File)6 Nullable (org.jetbrains.annotations.Nullable)6 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)4 Test (org.testng.annotations.Test)4 Pair (com.intellij.openapi.util.Pair)3 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)3 DataGeneratorSpec (com.linkedin.pinot.tools.data.generator.DataGeneratorSpec)3 List (java.util.List)3 AtUnqualifiedNoParenthesesCall (org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 PsiReference (com.intellij.psi.PsiReference)2 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)2 FieldType (com.linkedin.pinot.common.data.FieldSpec.FieldType)2 DataGenerator (com.linkedin.pinot.tools.data.generator.DataGenerator)2 HashMap (java.util.HashMap)2 TimeUnit (java.util.concurrent.TimeUnit)2