Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import jolie.lang.parse.ast.types.TypeDefinitionLink;
import jolie.lang.parse.ast.types.TypeInlineDefinition;
import jolie.lang.parse.context.ParsingContext;
import jolie.lang.parse.context.URIParsingContext;
import jolie.util.Range;
import jolie.xml.xsd.XsdToJolieConverter;
import jolie.xml.xsd.XsdUtils;
Expand All @@ -61,7 +60,7 @@
public class XsdToJolieConverterImpl implements XsdToJolieConverter {
private final Logger logger;
private final List< TypeDefinition > jolieTypes = new ArrayList<>();
private final static ParsingContext PARSING_CONTEXT = URIParsingContext.DEFAULT;
private final static ParsingContext PARSING_CONTEXT = ParsingContext.DEFAULT;
private final boolean strict;
private final XSSchemaSet schemaSet;
private final Map< String, TypeDefinition > complexTypes = new HashMap<>();
Expand Down
14 changes: 7 additions & 7 deletions lib/jolie-xml/src/main/java/joliex/wsdl/WSDLConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import jolie.lang.Constants;
import jolie.lang.NativeType;
import jolie.lang.parse.ast.types.*;
import jolie.lang.parse.context.URIParsingContext;
import jolie.lang.parse.context.ParsingContext;
import jolie.util.Pair;
import jolie.xml.xsd.XsdToJolieConverter;
import jolie.xml.xsd.XsdUtils;
Expand Down Expand Up @@ -480,7 +480,7 @@ private String convertOperationMessage( Message message, String operationName, S
Map< String, Part > parts = message.getParts();
if( parts.size() > 1 || style == Style.RPC ) {
typeName = message.getQName().getLocalPart();
TypeInlineDefinition requestType = new TypeInlineDefinition( URIParsingContext.DEFAULT, typeName,
TypeInlineDefinition requestType = new TypeInlineDefinition( ParsingContext.DEFAULT, typeName,
BasicTypeDefinition.of( NativeType.VOID ), jolie.lang.Constants.RANGE_ONE_TO_ONE );
for( Entry< String, Part > entry : parts.entrySet() ) {
Part part = entry.getValue();
Expand All @@ -490,14 +490,14 @@ private String convertOperationMessage( Message message, String operationName, S
+ operationName + "." );
}
TypeDefinitionLink link = new TypeDefinitionLink(
URIParsingContext.DEFAULT,
ParsingContext.DEFAULT,
part.getName(),
jolie.lang.Constants.RANGE_ONE_TO_ONE,
XsdUtils.xsdToNativeType( part.getTypeName().getLocalPart() ).id() );
requestType.putSubType( link );
} else {
TypeDefinitionLink link = new TypeDefinitionLink(
URIParsingContext.DEFAULT,
ParsingContext.DEFAULT,
part.getName(),
jolie.lang.Constants.RANGE_ONE_TO_ONE,
part.getElementName().getLocalPart() );
Expand Down Expand Up @@ -552,7 +552,7 @@ private joliex.wsdl.impl.Operation convertOperation( Operation operation, Style
parts = entry.getValue().getMessage().getParts();
if( parts.size() > 1 ) {
String typeName = faultName = faultTypeName;
TypeInlineDefinition faultType = new TypeInlineDefinition( URIParsingContext.DEFAULT, typeName,
TypeInlineDefinition faultType = new TypeInlineDefinition( ParsingContext.DEFAULT, typeName,
BasicTypeDefinition.of( NativeType.VOID ), jolie.lang.Constants.RANGE_ONE_TO_ONE );
for( Entry< String, Part > partEntry : parts.entrySet() ) {
Part part = partEntry.getValue();
Expand All @@ -562,14 +562,14 @@ private joliex.wsdl.impl.Operation convertOperation( Operation operation, Style
+ operation.getName() + "." );
}
TypeDefinitionLink link = new TypeDefinitionLink(
URIParsingContext.DEFAULT,
ParsingContext.DEFAULT,
part.getName(),
jolie.lang.Constants.RANGE_ONE_TO_ONE,
XsdUtils.xsdToNativeType( part.getTypeName().getLocalPart() ).id() );
faultType.putSubType( link );
} else {
TypeDefinitionLink link = new TypeDefinitionLink(
URIParsingContext.DEFAULT,
ParsingContext.DEFAULT,
part.getName(),
jolie.lang.Constants.RANGE_ONE_TO_ONE,
part.getElementName().getLocalPart() );
Expand Down
5 changes: 2 additions & 3 deletions libjolie/src/main/java/jolie/lang/CodeCheckMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Optional;
import jolie.lang.parse.ast.OLSyntaxNode;
import jolie.lang.parse.context.ParsingContext;
import jolie.lang.parse.context.URIParsingContext;

public class CodeCheckMessage {
private final ParsingContext context;
Expand Down Expand Up @@ -77,7 +76,7 @@ public static CodeCheckMessage buildWithHelp( OLSyntaxNode node, String message,
throw new InvalidParameterException( "Parameter help cannot be null." );
}
return new CodeCheckMessage(
(node != null) ? node.context() : URIParsingContext.DEFAULT,
(node != null) ? node.context() : ParsingContext.DEFAULT,
message, null );
}

Expand All @@ -102,7 +101,7 @@ public static CodeCheckMessage withoutHelp( ParsingContext context, String descr
*/
public static CodeCheckMessage buildWithoutHelp( OLSyntaxNode node, String message ) {
return new CodeCheckMessage(
(node != null) ? node.context() : URIParsingContext.DEFAULT,
(node != null) ? node.context() : ParsingContext.DEFAULT,
message, null );
}

Expand Down
57 changes: 28 additions & 29 deletions libjolie/src/main/java/jolie/lang/parse/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.commons.text.similarity.LevenshteinDistance;

import jolie.lang.parse.context.ParsingContext;
import jolie.lang.parse.context.URIParsingContext;
import jolie.lang.CodeCheckMessage;
import jolie.lang.Keywords;

Expand Down Expand Up @@ -186,7 +185,7 @@ protected final void setScanner( Scanner scanner ) {
* @return the current {@link ParsingContext} from the underlying {@link Scanner}
*/
public final ParsingContext getContext() {
return new URIParsingContext( scanner.source(), scanner.line(), scanner.line(), scanner.errorColumn(),
return new ParsingContext( scanner.source(), scanner.line(), scanner.line(), scanner.errorColumn(),
scanner.errorColumn() + token.content().length(),
scanner.codeLine() );
}
Expand All @@ -211,32 +210,32 @@ public final ParsingContext getContextDuringError() throws IOException {
scanner.codeLine().remove( scanner.codeLine().size() - 1 );
int column = scanner.codeLine().get( scanner.codeLine().size() - 1 ).length() - 1; // last index of
// (new)last line
URIParsingContext newContext =
new URIParsingContext( scanner.source(), scanner.line() - 1, scanner.line() - 1,
ParsingContext newContext =
new ParsingContext( scanner.source(), scanner.line() - 1, scanner.line() - 1,
column, column, scanner.codeLine() );
return newContext;
} else if( scanner.errorColumn() == -1 && scanner.line() <= 0 ) { // nothing has been read yet
return new URIParsingContext( scanner.source(), scanner.line(), scanner.line(),
return new ParsingContext( scanner.source(), scanner.line(), scanner.line(),
0, 0 + token.content().length(), scanner.codeLine() );
} else { // errorColum >= 0
return new URIParsingContext( scanner.source(), scanner.line(), scanner.line(),
return new ParsingContext( scanner.source(), scanner.line(), scanner.line(),
scanner.errorColumn(), scanner.errorColumn() + token.content().length(),
scanner.codeLine() );
}
}
// if the start and end line are larger than 0 and the error column is -1
if( scanner.errorColumn() == -1 && lineState == 1 ) {
int newColumn = scanner.codeLine().get( scanner.codeLine().size() - 1 ).length() - 1;
return new URIParsingContext( scanner.source(), scanner.startLine(), scanner.endLine() - 1,
return new ParsingContext( scanner.source(), scanner.startLine(), scanner.endLine() - 1,
newColumn, newColumn + token.content().length(),
scanner.codeLine() );
} else if( scanner.errorColumn() == -1 && lineState == 2 ) {
int newColumn = scanner.codeLine().get( scanner.codeLine().size() - 1 ).length() - 1;
return new URIParsingContext( scanner.source(), scanner.startLine() - 1, scanner.endLine() - 1,
return new ParsingContext( scanner.source(), scanner.startLine() - 1, scanner.endLine() - 1,
newColumn, newColumn + token.content().length(),
scanner.codeLine() );
}
return new URIParsingContext( scanner.source(), scanner.startLine(), scanner.endLine(),
return new ParsingContext( scanner.source(), scanner.startLine(), scanner.endLine(),
scanner.errorColumn(), scanner.errorColumn() + token.content().length(),
scanner.codeLine() );
}
Expand Down Expand Up @@ -571,7 +570,7 @@ protected final void throwException( String mesg )
// curly bracket and not at/before the curly bracket
// example, if service does not have a name
context =
new URIParsingContext( context.source(), context.startLine(), context.endLine(),
new ParsingContext( context.source(), context.startLine(), context.endLine(),
context.startColumn() - 1, context.endColumn() - 1,
context.enclosingCode() );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
Expand Down Expand Up @@ -629,23 +628,23 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
// if the starting curly bracket is missing,
// set the correct line and column for the context, so it points to the start of the port
int column = context.enclosingCode().get( 0 ).length() - 1;
context = new URIParsingContext( context.source(), context.startLine(), context.startLine(), column,
context = new ParsingContext( context.source(), context.startLine(), context.startLine(), column,
column, context.enclosingCode() );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else if( extralines.get( extralines.size() - 1 ).contains( "}" ) ) {
// If a term is missing, it needs the column of the last curly bracket instead of where it
// originally threw the error
int columnNumber = extralines.get( extralines.size() - 1 ).lastIndexOf( "}" );
context =
new URIParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
new ParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
columnNumber + token.content().length(),
extralines );
help = createHelpMessageWithScope( context, token.content(), scope );
exceptionMessage = CodeCheckMessage.withHelp( context, mesg, help );
} else if( extralines.get( 0 ).contains( "{" ) && mesg.contains( "expected inputPort name" ) ) {
// inputport is missing name, set column to curly starting curly bracket
int columnNumber = extralines.get( 0 ).lastIndexOf( "{" );
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
context = new ParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
columnNumber, extralines );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else if( mesg.contains( "expected :" ) ) {
Expand All @@ -665,12 +664,12 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
} else {
column = context.startColumn();
}
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(),
context = new ParsingContext( context.source(), context.startLine(), context.endLine(),
column, column, extralines );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else {
// in all other cases, set the endColumn to the startColumn+token
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(),
context = new ParsingContext( context.source(), context.startLine(), context.endLine(),
context.startColumn(), context.startColumn() + token.content().length(), extralines );
help = createHelpMessageWithScope( context, token.content(), scope );
exceptionMessage = CodeCheckMessage.withHelp( context, mesg, help );
Expand All @@ -691,7 +690,7 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
startColumn = context.startColumn();
endColumn = context.endColumn();
}
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(),
context = new ParsingContext( context.source(), context.startLine(), context.endLine(),
startColumn, endColumn, extralines );
help = createHelpMessageWithScope( context, token.content(), scope );
exceptionMessage = CodeCheckMessage.withHelp( context, mesg, help );
Expand All @@ -702,7 +701,7 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
extralines = getWholeScope( scopeName, scope );
int columnNumber = (!extralines.isEmpty()) ? extralines.get( extralines.size() - 1 ).length() - 1 : 0;
context =
new URIParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
new ParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
columnNumber, extralines );
help = createHelpMessageWithScope( context, token.content(), scope );
exceptionMessage = CodeCheckMessage.withoutHelp( context,
Expand All @@ -712,13 +711,13 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
extralines = getWholeScope( scopeName, scope );
// set column to last index on line with service
int column = extralines.get( 0 ).length() - 1;
context = new URIParsingContext( context.source(), context.startLine(), context.startLine(),
context = new ParsingContext( context.source(), context.startLine(), context.startLine(),
column, column, extralines );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else if( mesg.contains( "expected {" ) ) {
// no need to getWholeScope when token.conten() is not empty
int column = context.enclosingCode().get( 0 ).length() - 1;
context = new URIParsingContext( context.source(), context.startLine(), context.startLine(),
context = new ParsingContext( context.source(), context.startLine(), context.startLine(),
column, column, context.enclosingCode() );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else if( token.content().isEmpty() ) {
Expand All @@ -738,7 +737,7 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
int columnNumber = (tempSplit[ 0 ] + " " + tempSplit[ 1 ] + " ").length();
// set the columns to match the wrongly spelled import
context =
new URIParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
new ParsingContext( context.source(), context.startLine(), context.endLine(), columnNumber,
columnNumber + tempSplit[ 2 ].length(), extralines );
String importHelp = createHelpMessage( context, tempSplit[ 2 ], List.of( "from" ) );
exceptionMessage = CodeCheckMessage.withHelp( context, mesg, importHelp );
Expand All @@ -756,13 +755,13 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
if( mesg.contains( "expected {" ) ) { // interface is missing starting curly bracket
extralines = getWholeScope( scopeName, scope );
int column = extralines.get( 0 ).length() - 1;
context = new URIParsingContext( context.source(), context.startLine(), context.startLine(),
context = new ParsingContext( context.source(), context.startLine(), context.startLine(),
column, column, List.of( extralines.get( 0 ) ) );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else if( mesg.contains( "expected }" ) ) { // interface is missing ending curly bracket
extralines = getWholeScope( scopeName, scope );
int column = extralines.get( extralines.size() - 1 ).length() - 1;
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(),
context = new ParsingContext( context.source(), context.startLine(), context.endLine(),
column, column, extralines );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else {
Expand All @@ -772,13 +771,13 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
// empty
extralines = getWholeScope( scopeName, scope );
int column = extralines.get( 0 ).length() - 1;
context = new URIParsingContext( context.source(), context.startLine(), context.startLine(),
context = new ParsingContext( context.source(), context.startLine(), context.startLine(),
column, column, List.of( extralines.get( 0 ) ) );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else if( mesg.contains( "expected }" ) ) { // missing ending curly bracket and token.content() is not
// empty
// only have the last line of enclosingCode in the context
context = new URIParsingContext( context.source(), context.endLine(), context.endLine(),
context = new ParsingContext( context.source(), context.endLine(), context.endLine(),
context.startColumn(), context.endColumn(),
List.of( context.enclosingCode().get( context.enclosingCode().size() - 1 ) ) );
help = createHelpMessageWithScope( context, token.content(), scope );
Expand All @@ -793,11 +792,11 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
if( mesg.contains( "expected basic statement" ) ) { // if main is empty
// set column to ending curly bracket
int column = context.enclosingCode().get( context.enclosingCode().size() - 1 ).lastIndexOf( "}" );
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(),
context = new ParsingContext( context.source(), context.startLine(), context.endLine(),
column, column, context.enclosingCode() );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else {
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(),
context = new ParsingContext( context.source(), context.startLine(), context.endLine(),
context.endColumn(), context.endColumn(), context.enclosingCode() );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
}
Expand All @@ -815,20 +814,20 @@ protected final void throwExceptionWithScope( String mesg, String scopeName, Str
correctLine = string;
int column = correctLine.indexOf( ':' );
context =
new URIParsingContext( context.source(), i, i, column, column, List.of( correctLine ) );
new ParsingContext( context.source(), i, i, column, column, List.of( correctLine ) );
break;
}
i += 1;
}
if( correctLine.isEmpty() ) {
context = new URIParsingContext( context.source(), context.startLine(), context.endLine(),
context = new ParsingContext( context.source(), context.startLine(), context.endLine(),
context.startColumn(), context.endColumn(), extralines );
}
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
} else {
// any other error for type scope
extralines = getWholeScope( scopeName, scope );
context = new URIParsingContext( context.source(), context.startLine(), context.startLine(),
context = new ParsingContext( context.source(), context.startLine(), context.startLine(),
context.startColumn(), context.endColumn(), extralines );
exceptionMessage = CodeCheckMessage.withoutHelp( context, mesg );
}
Expand Down
Loading
Loading