public static String autocast(StringValue x, String y) { return x.getValue(); } }
public StringValue getBefore() { if (before == null) { before = new StringValue(StringUtils.EMPTY); } return before; }
private void checkRowValue(StringValue operation, String columnName, StringValue columnValue, ValueNecessity columnNecessity) throws SyntaxNodeException { if (columnNecessity == ValueNecessity.REQUIRED && columnValue.isEmpty()) { IOpenSourceCodeModule source = columnValue.asSourceCodeModule(); if (source.getUri() == null) { // Column <columnName> is absent. Point to <operation> cell instead. String errMsg = String.format("%s is required for operation \"%s\"!", columnName, operation); throw SyntaxNodeExceptionUtils.createError(errMsg, operation.asSourceCodeModule()); } else { // Column <columnName> exists but still is empty. Point to empty <columnValue> cell. String errMsg = String.format("Operation must have value in %s!", columnName); throw SyntaxNodeExceptionUtils.createError(errMsg, source); } } if (columnNecessity == ValueNecessity.PROHIBITED && !columnValue.isEmpty()) { String errMsg = String.format("Operation must not have value in %s!", columnName); throw SyntaxNodeExceptionUtils.createError(errMsg, columnValue.asSourceCodeModule()); } }
private TableParserSpecificationBean getSpecification(StringValue operation, boolean multiline) throws SyntaxNodeException { String operationName = operation.getValue(); boolean foundButNotMatch = false; for (TableParserSpecificationBean specification : specifications) { String specKeyword = specification.getKeyword(); if (operationName.equalsIgnoreCase(specKeyword)) { if (specification.isMultiline() == multiline) { return specification; } foundButNotMatch = true; } } if (foundButNotMatch) { String errorMessage; if (multiline) { // If operation is used as multiline and it doesn't match the specification the error should be next // errorMessage = "Operation %s can not be multiline! Nested operations are not allowed here."; } else { // If the operation is used as single line and it doesn't match the specification, the error should be next // errorMessage = "Operation %s can not be singleline!"; } throw SyntaxNodeExceptionUtils.createError(String.format(errorMessage,operationName), operation.asSourceCodeModule()); } String errMsg = "No such operation: " + operationName; throw SyntaxNodeExceptionUtils.createError(errMsg, operation.asSourceCodeModule()); }
public Object convertParam(List<AlgorithmTreeNode> nodesToCompile, Class<?> clazz, String operationParam) throws SyntaxNodeException { ParameterConverter converter = parameterConverters.get(clazz); if (converter == null) { IOpenSourceCodeModule errorSource = nodesToCompile.get(0).getAlgorithmRow().getOperation() .asSourceCodeModule(); throw SyntaxNodeExceptionUtils.createError(String.format("Compilation failure. Can't convert parameter %s to type %s", operationParam, clazz.toString()), errorSource); } return converter.convert(nodesToCompile, operationParam); }
public IOpenSourceCodeModule asSourceCodeModule() { return new StringSourceCodeModule(value, getMetaInfo().getSourceUrl()); }
private void analyzeReturnCorrectness() throws SyntaxNodeException { if (functionBody.size() > 0) { int i = 0; for (AlgorithmTreeNode algorithmTreeNode : functionBody){ StringValue operation = algorithmTreeNode.getAlgorithmRow().getOperation(); if (operation != null && TBasicSpecificationKey.RETURN.toString().equals(operation.toString())){ SuitablityAsReturn status = new ReturnAnalyzer(getReturnType(), compiler).analyze(functionBody.get(i) .getChildren()); if (status == SuitablityAsReturn.NONE) { IOpenSourceCodeModule errorSource = functionBody.get(i).getAlgorithmRow() .getOperation().asSourceCodeModule(); throw SyntaxNodeExceptionUtils.createError("The method must return value of type '" + getReturnType().getDisplayName(INamedThing.REGULAR) + "'", errorSource); } } i++; } } }
public static TextInterval createTextInterval(StringValue text) { return createTextInterval(0, text.length()); } }
/** * Sets the metainfo for the value */ public void setMetaInfo(IMetaInfo metaInfo) { if (metaInfo instanceof ValueMetaInfo) { setMetaInfo((ValueMetaInfo) metaInfo); } else { try { ValueMetaInfo valueMetaInfo = new ValueMetaInfo(metaInfo.getDisplayName(IMetaInfo.SHORT), metaInfo.getDisplayName(IMetaInfo.LONG), new URLSourceCodeModule(new URL(metaInfo.getSourceUrl()))); setMetaInfo(valueMetaInfo); } catch (Exception e) { log.debug("Failed to set meta info for StringValue \"{}\"", value, e); setMetaInfo((ValueMetaInfo) null); } } }
public IOpenClass getTypeOfField(StringValue fieldContent) { // TODO: make rational type detecting(without creating of // CompositeMethod) IOpenSourceCodeModule src = fieldContent.asSourceCodeModule(); OpenL openl = context.getOpenL(); IMethodSignature signature = header.getSignature(); return OpenLCellExpressionsCompiler .makeMethodWithUnknownType(openl, src, "cell_" + fieldContent.getValue(), signature, thisTargetClass, getAlgorithmBindingContext()) .getMethod() .getType(); }
public IOpenSourceCodeModule getSourceModule() { return sourceNode.getAlgorithmRow().getOperation().asSourceCodeModule(); }
public IOpenSourceCodeModule asSourceCodeModule() { return new StringSourceCodeModule(value, getMetaInfo().getSourceUrl()); }
public static TextInterval createTextInterval(StringValue text) { return createTextInterval(0, text.length()); } }
/** * Sets the metainfo for the value */ public void setMetaInfo(IMetaInfo metaInfo) { if (metaInfo instanceof ValueMetaInfo) { setMetaInfo((ValueMetaInfo) metaInfo); } else { try { ValueMetaInfo valueMetaInfo = new ValueMetaInfo(metaInfo.getDisplayName(IMetaInfo.SHORT), metaInfo.getDisplayName(IMetaInfo.LONG), new URLSourceCodeModule(new URL(metaInfo.getSourceUrl()))); setMetaInfo(valueMetaInfo); } catch (Exception e) { log.debug("Failed to set meta info for StringValue \"{}\"", value, e); setMetaInfo((ValueMetaInfo) null); } } }
public String marshal(StringValue val) throws Exception { return val.getValue(); } }
public StringValue getLabel() { if (label == null) { label = new StringValue(StringUtils.EMPTY); } return label; }
/** * Find out the type of the array element. And define the internal variable */ private void declareArrayElement(List<AlgorithmTreeNode> nodesToCompile, ConversionRuleStep conversionStep) throws SyntaxNodeException { // Points to the location of the elementName in the TBasic table // String elementNameParameter = conversionStep.getOperationParam1(); // Points to the location of the iterable array parameter in the Tbasic // table // String iterableArrayParameter = conversionStep.getOperationParam2(); // Extract the element name // StringValue elementName = AlgorithmCompilerTool.getCellContent(nodesToCompile, elementNameParameter); // Extract the type of the iterable array // IOpenClass iterableArrayType = getTypeOfField( AlgorithmCompilerTool.getCellContent(nodesToCompile, iterableArrayParameter)); if (!iterableArrayType.isArray()) { IOpenSourceCodeModule errorSource = nodesToCompile.get(0) .getAlgorithmRow() .getAction() .asSourceCodeModule(); throw SyntaxNodeExceptionUtils.createError("Compilation failure. The cell should be of the array type", errorSource); } IOpenClass elementType = iterableArrayType.getComponentClass(); initNewInternalVariable(elementName.getValue(), elementType); }
private void preprocessConversionStep(List<AlgorithmTreeNode> nodesToCompile, ConversionRuleStep conversionStep) throws SyntaxNodeException { assert nodesToCompile.size() > 0; assert conversionStep != null; String operationType = conversionStep.getOperationType(); if (operationType.startsWith("!") && !operationType.equals(OperationType.CHECK_LABEL.toString())) { OperationPreprocessor preprocessor = operationPreprocessors.get(operationType); if (preprocessor == null) { IOpenSourceCodeModule errorSource = nodesToCompile.get(0) .getAlgorithmRow() .getOperation() .asSourceCodeModule(); throw SyntaxNodeExceptionUtils .createError(String.format("Unknown compilation instruction %s", operationType), errorSource); } else { preprocessor.preprocess(nodesToCompile, conversionStep); } } }
@Override public Object convert(List<AlgorithmTreeNode> nodesToCompile, String operationParam) throws SyntaxNodeException { if (operationParam == null) { return null; } StringValue cellContent = AlgorithmCompilerTool.getCellContent(nodesToCompile, operationParam); AlgorithmTreeNode executionNode = AlgorithmCompilerTool.extractOperationNode(nodesToCompile, operationParam); String methodName = String.format("%s_row_%s", operationParam.replace('.', '_'), executionNode.getAlgorithmRow().getRowNumber()); IOpenSourceCodeModule src = cellContent.getMetaInfo().getSource(); // return statements for the whole Algorithm(TBasic) should be casted to the return type of // whole Algorithm rule if (labelManager.isReturnInstruction(operationParam)) { /** create method and cast its value to the appropriate return type*/ return compiler.makeMethodWithCast(src, methodName, returnType); } else { return compiler.makeMethod(src, methodName); } } }