Skip to content

Commit

Permalink
Small error handling refactor
Browse files Browse the repository at this point in the history
Added new live template for @input @output @Result
Updated other live templates so they comply with the new changes.

Signed-off-by: sorin <sorin@hpe.com>
  • Loading branch information
sorin committed Jan 30, 2017
1 parent 514554c commit dd5fdec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
49 changes: 23 additions & 26 deletions src/io/cloudslang/intellij/lang/annotator/ExecutableAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.spring.model.xml.beans.Meta;
import io.cloudslang.intellij.lang.dependencies.CloudSlangDependenciesProvider;
import io.cloudslang.intellij.lang.exceptions.LocatedRuntimeException;
import io.cloudslang.lang.compiler.MetadataExtractor;
Expand All @@ -35,17 +34,6 @@
import io.cloudslang.lang.compiler.modeller.result.SystemPropertyModellingResult;
import io.cloudslang.lang.compiler.parser.YamlParser;
import io.cloudslang.lang.compiler.parser.model.ParsedSlang;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -58,6 +46,17 @@
import org.jetbrains.yaml.psi.YAMLValue;
import org.jetbrains.yaml.psi.impl.YAMLBlockMappingImpl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static io.cloudslang.intellij.lang.CloudSlangFileUtils.isCloudSlangFile;
import static io.cloudslang.intellij.lang.CloudSlangFileUtils.isCloudSlangSystemPropertiesFile;
Expand Down Expand Up @@ -115,23 +114,21 @@ public ModellingResult collectInformation(@NotNull PsiFile file) {

private List<RuntimeException> mergeModellingResults(ModellingResult result1, ModellingResult result2) {
List<RuntimeException> runtimeExceptions = new ArrayList<>();
if (!result2.getErrors().isEmpty()) {
runtimeExceptions = result2.getErrors()
.stream()
.map(this::transformMessageToExceptionList)
.flatMap(List::stream)
.collect(toList());
}
if (!result1.getErrors().isEmpty()) {
runtimeExceptions.addAll(result1.getErrors()
.stream()
.map(this::transformMessageToExceptionList)
.flatMap(List::stream)
.collect(toList()));
}

runtimeExceptions.addAll(getExceptionsFromResult(result2));
runtimeExceptions.addAll(getExceptionsFromResult(result1));

return runtimeExceptions;
}

private List<RuntimeException> getExceptionsFromResult(ModellingResult result1) {
return result1.getErrors()
.stream()
.map(this::transformMessageToExceptionList)
.flatMap(List::stream)
.collect(toList());
}

@NotNull
private ModellingResult processExceptionToModellingResult(RuntimeException e) {
final List<RuntimeException> runtimeExceptions = transformMessageToExceptionList(e);
Expand Down
8 changes: 4 additions & 4 deletions src/io/cloudslang/intellij/lang/templates/CloudSlang.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<templateSet group="CloudSlang">
<template name="operation" value="####################################################&#10;#!!&#10;#! @description: $operation_description$&#10;#!&#10;#! @input $input_1_name$: $standard_description$&#10;#! @input $input_2_name$: $standard_description$&#10;#! @output $output_name$: $standard_description$&#10;#! @result $result_1_name$: $result_1_description$&#10;#! @result $result_2_name$: $result_2_description$&#10;#!!#&#10;####################################################&#10;&#10;namespace: $namespace$&#10;&#10;operation:&#10; name: $operation_name$&#10;&#10; inputs:&#10; - $input_1$&#10; - $input_2$&#10;&#10; java_action:&#10; gav: '$group$:$artifact$:$version$'&#10; class_name: $class$&#10; method_name: $method$&#10;&#10; outputs:&#10; - $output$&#10;&#10; results:&#10; - $result_1$: ${$success_condition$}&#10; - $result_2$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<template name="operation" value="########################################################################################################################&#10;#!!&#10;#! @description: $operation_description$&#10;#!&#10;#! @input $input_1_name$: $standard_description$&#10;#! @input $input_2_name$: $standard_description$&#10;#! @output $output_name$: $standard_description$&#10;#! @result $result_1_name$: $result_1_description$&#10;#! @result $result_2_name$: $result_2_description$&#10;#!!#&#10;########################################################################################################################&#10;&#10;namespace: $namespace$&#10;&#10;operation:&#10; name: $operation_name$&#10;&#10; inputs:&#10; - $input_1$&#10; - $input_2$&#10;&#10; java_action:&#10; gav: '$group$:$artifact$:$version$'&#10; class_name: $class$&#10; method_name: $method$&#10;&#10; outputs:&#10; - $output$&#10;&#10; results:&#10; - $result_1$: ${$success_condition$}&#10; - $result_2$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<variable name="namespace" expression="relativePathToProject" defaultValue="" alwaysStopAt="true" />
<variable name="input_1" expression="" defaultValue="&quot;input_1&quot;" alwaysStopAt="true" />
<variable name="input_2" expression="" defaultValue="&quot;input_2&quot;" alwaysStopAt="true" />
Expand Down Expand Up @@ -49,7 +49,7 @@
<variable name="result_1_name" expression="result_1" defaultValue="" alwaysStopAt="false" />
<variable name="result_2_name" expression="result_2" defaultValue="" alwaysStopAt="false" />
<variable name="result_1_description" expression="" defaultValue="&quot;Flow completed successfully.&quot;" alwaysStopAt="false" />
<variable name="result_2_description" expression="" defaultValue="&quot;Failure occured during execution.&quot;" alwaysStopAt="false" />
<variable name="result_2_description" expression="" defaultValue="&quot;Failure occurred during execution.&quot;" alwaysStopAt="false" />
<variable name="standard_description" expression="" defaultValue="&quot;Generated description&quot;" alwaysStopAt="false" />
<variable name="flow_description" expression="" defaultValue="&quot;Generated flow description&quot;" alwaysStopAt="false" />
<context>
Expand Down Expand Up @@ -169,8 +169,8 @@
<option name="CloudSlang" value="true" />
</context>
</template>
<template name="required" value="required: $default_requierd$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<variable name="default_requierd" expression="" defaultValue="&quot;false&quot;" alwaysStopAt="true" />
<template name="required" value="required: $default_required$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<variable name="default_required" expression="" defaultValue="&quot;false&quot;" alwaysStopAt="true" />
<context>
<option name="CloudSlang" value="true" />
</context>
Expand Down

0 comments on commit dd5fdec

Please sign in to comment.