Search in sources :

Example 16 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project n4js by eclipse.

the class NodeEngineCommandBuilder method generateBootCode.

/**
 * Generates JS code to the this that will be configured with data for execution.
 *
 * This method uses provided working dir to transform it into nodejs-project-like structure, to allow proper
 * configuration of the executions. In particular:
 *
 * <pre>
 * <ol>
 * <li> add node module to the folder</li>
 * <li> generate startup script</li>
 * <li> return path to the startup script</li>
 * </ol>
 * </pre>
 *
 * Note that some configuration will be performed by the startup script when it is executed.
 *
 * @param nodeRunOptions
 *            options used to generate boot code
 * @return path to the script that has to be called by node
 * @throws IOException
 *             for IO operations
 */
private String generateBootCode(NodeRunOptions nodeRunOptions, Path workDir) throws IOException {
    // 1 generate fake node project
    Path projectRootPath = workDir;
    // 2 create 'node_modules' to the #1
    final File node_modules = new File(projectRootPath.toFile(), "node_modules");
    node_modules.mkdirs();
    addNodeModulesDeleteHook(node_modules);
    // 3 generate elf script in #1
    final File elf = Files.createTempFile(projectRootPath, "N4JSNodeELF", "." + N4JSGlobals.JS_FILE_EXTENSION).toFile();
    elf.deleteOnExit();
    String[] paths = nodeRunOptions.getCoreProjectPaths().split(NODE_PATH_SEP);
    List<Pair<String, String>> path2name = new ArrayList<>();
    for (int i = 0; i < paths.length; i++) {
        String string = paths[i];
        Path p = Paths.get(string);
        path2name.add(new Pair<>(string, p.getFileName().toString()));
    }
    // early throw, to prevent debugging runtime processes
    String execModule = nodeRunOptions.getExecModule();
    if (Strings.isNullOrEmpty(execModule))
        throw new RuntimeException("Execution module not provided.");
    List<String> initModules = nodeRunOptions.getInitModules();
    // TODO-1932 redesign of the runners and testers pending
    // some runtime environments (the N4JS projects) bootstrap execution
    // is against Runners/Testers design. We want those to fix those runtime
    // projects, but also there was redesign of the whole concept pending.
    // For the time being we just patch data generated by the IDE to work
    // with the user projects.
    initModules = Arrays.asList();
    String eflCode = getELFCode(nodeRunOptions, node_modules, path2name, execModule, initModules);
    writeContentToFile(eflCode, elf);
    return elf.getAbsolutePath();
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) File(java.io.File) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 17 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project n4js by eclipse.

the class ComposedMemberInfo method handleFParameters.

private void handleFParameters(TMember member, RuleEnvironment G) {
    EList<TFormalParameter> fpars = null;
    if (member instanceof TMethod) {
        TMethod method = (TMethod) member;
        fpars = method.getFpars();
    }
    if (member instanceof TSetter) {
        TSetter setter = (TSetter) member;
        fpars = new BasicEList<>();
        fpars.add(setter.getFpar());
    }
    if (fpars != null) {
        for (int i = 0; i < fpars.size(); i++) {
            TFormalParameter fpar = fpars.get(i);
            if (fParameters.size() <= i) {
                fParameters.add(new ComposedFParInfo());
            }
            ComposedFParInfo fpAggr = fParameters.get(i);
            Pair<TFormalParameter, RuleEnvironment> fpPair = new Pair<>(fpar, G);
            fpAggr.fpSiblings.add(fpPair);
        }
    }
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) TSetter(org.eclipse.n4js.ts.types.TSetter) TMethod(org.eclipse.n4js.ts.types.TMethod) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 18 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project metalib by softlang.

the class Tests method annotatedParse.

/**
 * Helper for parsing a model and annotating it with the warnings and
 * errors the parsing process generated
 */
public Pair<FSM, Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>> annotatedParse(final CharSequence s) {
    try {
        final XtextResourceSet resourceSet = new XtextResourceSet();
        final FSM parsed = this.parseHelper.parse(s, resourceSet);
        EList<Resource> _resources = resourceSet.getResources();
        final Resource resource = IterableExtensions.<Resource>last(_resources);
        EList<Resource.Diagnostic> _warnings = resource.getWarnings();
        EList<Resource.Diagnostic> _errors = resource.getErrors();
        Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _mappedTo = Pair.<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>of(_warnings, _errors);
        return Pair.<FSM, Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>>of(parsed, _mappedTo);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : FSM(org.softlang.metalib.xtext.fsml.fsml.FSM) EList(org.eclipse.emf.common.util.EList) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 19 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project dsl-devkit by dsldevkit.

the class AbstractXtextTestUtil method processDiagnostic.

/**
 * Gets the offset and the error message for a given {@link Diagnostic}.
 *
 * @param diagnostic
 *          instance of {@link Diagnostic}
 * @return
 *         offset and error message
 */
private Pair<Integer, String> processDiagnostic(final Diagnostic diagnostic) {
    StringBuilder errorMessage = new StringBuilder();
    if (diagnostic instanceof AbstractValidationDiagnostic) {
        AbstractValidationDiagnostic avd = (AbstractValidationDiagnostic) diagnostic;
        errorMessage.append("Unexpected issue found. Code '");
        errorMessage.append(avd.getIssueCode()).append("'\n");
        errorMessage.append(avd.getMessage());
        if (avd instanceof FeatureBasedDiagnostic && ((FeatureBasedDiagnostic) avd).getFeature() != null) {
            List<INode> nodes = NodeModelUtils.findNodesForFeature(avd.getSourceEObject(), ((FeatureBasedDiagnostic) avd).getFeature());
            if (nodes != null && !nodes.isEmpty()) {
                return new Pair<Integer, String>(findFirstNonHiddenLeafNode(nodes.get(0)).getTotalOffset(), errorMessage.toString());
            }
        } else if (avd instanceof RangeBasedDiagnostic) {
            return new Pair<Integer, String>(((RangeBasedDiagnostic) avd).getOffset(), errorMessage.toString());
        } else {
            return new Pair<Integer, String>(NodeModelUtils.getNode(avd.getSourceEObject()).getTotalOffset(), errorMessage.toString());
        }
    }
    return null;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) RangeBasedDiagnostic(org.eclipse.xtext.validation.RangeBasedDiagnostic) AbstractValidationDiagnostic(org.eclipse.xtext.validation.AbstractValidationDiagnostic) FeatureBasedDiagnostic(org.eclipse.xtext.validation.FeatureBasedDiagnostic) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 20 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project xtext-xtend by eclipse.

the class Solution_014 method main.

public static void main(final String[] args) {
    final BitSet numbersSeen = new BitSet(1_000_000);
    final Function1<Integer, Pair<Integer, Integer>> _function = (Integer it) -> {
        int _size = IteratorExtensions.size(new Solution_014((it).intValue(), numbersSeen));
        return Pair.<Integer, Integer>of(it, Integer.valueOf(_size));
    };
    final Function2<Pair<Integer, Integer>, Pair<Integer, Integer>, Pair<Integer, Integer>> _function_1 = (Pair<Integer, Integer> r1, Pair<Integer, Integer> r2) -> {
        Pair<Integer, Integer> _xifexpression = null;
        Integer _value = r1.getValue();
        Integer _value_1 = r2.getValue();
        boolean _greaterThan = (_value.compareTo(_value_1) > 0);
        if (_greaterThan) {
            _xifexpression = r1;
        } else {
            _xifexpression = r2;
        }
        return _xifexpression;
    };
    InputOutput.<Integer>println(IterableExtensions.<Pair<Integer, Integer>>reduce(IterableExtensions.<Integer, Pair<Integer, Integer>>map(new IntegerRange(1_000_000, 1), _function), _function_1).getKey());
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) BitSet(java.util.BitSet) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

Pair (org.eclipse.xtext.xbase.lib.Pair)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)22 Test (org.junit.Test)15 Collection (java.util.Collection)11 List (java.util.List)11 ArrayList (java.util.ArrayList)9 AbstractHierarchyBuilderTest (org.eclipse.xtext.junit4.ide.AbstractHierarchyBuilderTest)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 Map (java.util.Map)6 EObject (org.eclipse.emf.ecore.EObject)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 AbstractElement (org.eclipse.xtext.AbstractElement)6 HashMap (java.util.HashMap)5 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)5 Type (org.eclipse.n4js.ts.types.Type)5 EList (org.eclipse.emf.common.util.EList)4 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)4 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3