All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.goikosoft.textprocessor.operations.flow.Return Maven / Gradle / Ivy

package com.goikosoft.textprocessor.operations.flow;

import java.util.Map;

import com.goikosoft.textprocessor.exceptions.IncompatibleVariables;
import com.goikosoft.textprocessor.exceptions.OperationInputException;
import com.goikosoft.textprocessor.exceptions.VariableException;
import com.goikosoft.textprocessor.generator.annotations.Input;
import com.goikosoft.textprocessor.generator.annotations.UsableOperation;
import com.goikosoft.textprocessor.generator.annotations.VisibleInfo;
import com.goikosoft.textprocessor.operations.BaseVoidOperation;
import com.goikosoft.textprocessor.validation.IncompatibleInput;
import com.goikosoft.textprocessor.validation.ValidationErrorImpl;
import com.goikosoft.textprocessor.validation.ValidationReport;
import com.goikosoft.textprocessor.validation.ValidationReportImpl;
import com.goikosoft.textprocessor.variables.Scope;
import com.goikosoft.textprocessor.variables.Type;
import com.goikosoft.textprocessor.variables.Variable;
import com.goikosoft.textprocessor.variables.VariableWrite;

/**
* FIXME: Revisar como interactua esto con los result normales, puede que nos joda ¿eh?
* 

Operation description: Invokes the setter for the given property

* Output type: {@link Void} - No output
* Number of inputs: 2
*

    *
  1. input: variable to store in the result variable, so the parent will return it instead it's normal return. *
      *
    • Type: {@link Object}
    • *
    • Allows null: {@code false}
    • *
    • Optional: {@code false}
    • *
    *
  2. *
* Number of parameters 0
* Number of meta-parameters 2 see {@link BaseVoidOperation} * * @author Dario Goikoetxea * @see BaseVoidOperation * @see VariableWrite#assign(Variable) * @see com.goikosoft.textprocessor.exceptions.Return */ @UsableOperation @VisibleInfo(displayName = "Return", description = "Terminates the current function or program") public class Return extends BaseVoidOperation implements FlowOperation { public static final String INPUT_NAME = "input"; @Input @VisibleInfo(displayName = "Return value", description = "The value to store into the expected return vbariable. Can only be used in functions") private Variable input; private VariableWrite result; @Override protected Void executionLogic() throws com.goikosoft.textprocessor.exceptions.Return, OperationInputException { if(input != null) { try { result.assign(input); } catch (IncompatibleVariables e) { throw new OperationInputException("input is not assignable to result", this, e); } catch (NullPointerException e) { if(result == null) throw new OperationInputException("result variable not found", this, e); throw new OperationInputException("unexpected exception assigning input to result", this, e); } } throw new com.goikosoft.textprocessor.exceptions.Return(this); } @Override protected Map fetchInputs(Scope scope) throws VariableException, NullPointerException { Map temp = super.fetchInputs(scope); input = temp.get(INPUT_NAME); if(input != null) { try { result = scope.getResultVariable(); } catch (UnsupportedOperationException e){ throw new VariableException("scope doesn't allow to search result variable", e); } }else { result = null; } return temp; } @Override protected ValidationReport validateInputVariables(Map inputVariables) { if(input != null) { Type type = input.getType(); if(result == null) { return new ValidationReportImpl(false, new ValidationErrorImpl(this, "output not found when input is configured", null)); } if(!result.isAssignableFrom(type)) { return new ValidationReportImpl(false, new IncompatibleInput(null, input, result.getType())); } } return new ValidationReportImpl(true); } @Override protected ValidationReport validateParams() { return new ValidationReportImpl(true); } @Override public Return clone() { Return clonedInstance = new Return(); cloneHelper(clonedInstance); return clonedInstance; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy