This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch gh2518-cdt in repository https://gitbox.apache.org/repos/asf/jena.git
commit e51a685a95059ba231f525aee8ebdc91d8ef8bca Author: Andy Seaborne <[email protected]> AuthorDate: Thu Aug 29 12:44:09 2024 +0100 Fix white space and deprecation warnings --- .../jena/riot/system/CDTAwareParserProfile.java | 170 +++++++++++---------- 1 file changed, 87 insertions(+), 83 deletions(-) diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/CDTAwareParserProfile.java b/jena-arq/src/main/java/org/apache/jena/riot/system/CDTAwareParserProfile.java index 660b0c2580..1deaa592d9 100644 --- a/jena-arq/src/main/java/org/apache/jena/riot/system/CDTAwareParserProfile.java +++ b/jena-arq/src/main/java/org/apache/jena/riot/system/CDTAwareParserProfile.java @@ -45,88 +45,92 @@ import org.apache.jena.sparql.util.Context; */ public class CDTAwareParserProfile extends ParserProfileStd { - public CDTAwareParserProfile( final FactoryRDF factory, - final ErrorHandler errorHandler, - final IRIxResolver resolver, - final PrefixMap prefixMap, - final Context context, - final boolean checking, - final boolean strictMode ) { - super(factory, errorHandler, resolver, prefixMap, context, checking, strictMode); - } - - @Override - public Node createTypedLiteral( final String lex, final RDFDatatype datatype, final long line, final long col ) { - // cdt:List and cdt:Map literals need to be treated in a special way - // because we need to construct their value by parsing them using this - // same parser profile; this is necessary to make sure that blank node - // identifiers inside the lexical forms of multiple of these literals - // within the same file are all mapped to the same blank node, and so - // are all blank node identifers that occur directly in the file (i.e., - // ourside of CDT literals). - - if ( datatype.equals(CompositeDatatypeList.type) ) { - return createListLiteral(lex); - } - - if ( datatype.equals(CompositeDatatypeMap.type) ) { - return createMapLiteral(lex); - } - - return super.createTypedLiteral(lex, datatype, line, col); - } - - protected Node createListLiteral( final String lex ) { - // Attention: In contrast to the overridden createTypedLiteral function - // in the superclass, for literals of the CDT datatypes we do not perform - // a checkLiteral check because that would parse the lexical form of the - // literal already once before doing the other parse to obtain the value. - - // parse the given lexical form using this same parser profile - final List<CDTValue> value; - try { - value = ParserForCDTLiterals.parseListLiteral(this, lex); - } - catch ( final Exception ex ) { - throw new DatatypeFormatException(lex, CompositeDatatypeList.type, ex); - } - - // At this point we have both the lexical form (which, after the - // parsing, we now know is well formed) and the corresponding value - // of the literal. We create a LiteralLabel with both of them, for - // the following reasons. - // If we were to create the LiteralLabel with the lexical form only, - // then the LiteralLabel implementation would parse that lexical form - // again, which gives us an unnecessary performance penalty (in - // particular for huge lists). - // If we were to create the LiteralLabel with the value only, then the - // LiteralLabel implementation would reproduce the lexical form, which - // may not be identical to the lexical form with which we have created - // the value here. The issue with that is that a SAMETERM comparison - // would incorrectly return false. - final LiteralLabel ll = LiteralLabelFactory.createIncludingValue(lex, value, CompositeDatatypeList.type); - return NodeFactory.createLiteral(ll); - } - - protected Node createMapLiteral( final String lex ) { - // Attention: In contrast to the overridden createTypedLiteral function - // in the superclass, for literals of the CDT datatypes we do not perform - // a checkLiteral check because that would parse the lexical form of the - // literal already once before doing the other parse to obtain the value. - - // parse the given lexical form using this same parser profile - final Map<CDTKey,CDTValue> value; - try { - value = ParserForCDTLiterals.parseMapLiteral(this, lex); - } - catch ( final Exception ex ) { - throw new DatatypeFormatException(lex, CompositeDatatypeMap.type, ex); - } - - // We create a LiteralLabel with both the lexical form and the value, - // for the same reasons as described above in createListLiteral(). - final LiteralLabel ll = LiteralLabelFactory.createIncludingValue(lex, value, CompositeDatatypeMap.type); - return NodeFactory.createLiteral(ll); - } + public CDTAwareParserProfile( final FactoryRDF factory, + final ErrorHandler errorHandler, + final IRIxResolver resolver, + final PrefixMap prefixMap, + final Context context, + final boolean checking, + final boolean strictMode ) { + super(factory, errorHandler, resolver, prefixMap, context, checking, strictMode); + } + + @Override + public Node createTypedLiteral( final String lex, final RDFDatatype datatype, final long line, final long col ) { + // cdt:List and cdt:Map literals need to be treated in a special way + // because we need to construct their value by parsing them using this + // same parser profile; this is necessary to make sure that blank node + // identifiers inside the lexical forms of multiple of these literals + // within the same file are all mapped to the same blank node, and so + // are all blank node identifers that occur directly in the file (i.e., + // ourside of CDT literals). + + if ( datatype.equals(CompositeDatatypeList.type) ) { + return createListLiteral(lex); + } + + if ( datatype.equals(CompositeDatatypeMap.type) ) { + return createMapLiteral(lex); + } + + return super.createTypedLiteral(lex, datatype, line, col); + } + + protected Node createListLiteral( final String lex ) { + // Attention: In contrast to the overridden createTypedLiteral function + // in the superclass, for literals of the CDT datatypes we do not perform + // a checkLiteral check because that would parse the lexical form of the + // literal already once before doing the other parse to obtain the value. + + // parse the given lexical form using this same parser profile + final List<CDTValue> value; + try { + value = ParserForCDTLiterals.parseListLiteral(this, lex); + } + catch ( final Exception ex ) { + throw new DatatypeFormatException(lex, CompositeDatatypeList.type, ex); + } + + // At this point we have both the lexical form (which, after the + // parsing, we now know is well formed) and the corresponding value + // of the literal. We create a LiteralLabel with both of them, for + // the following reasons. + // If we were to create the LiteralLabel with the lexical form only, + // then the LiteralLabel implementation would parse that lexical form + // again, which gives us an unnecessary performance penalty (in + // particular for huge lists). + // If we were to create the LiteralLabel with the value only, then the + // LiteralLabel implementation would reproduce the lexical form, which + // may not be identical to the lexical form with which we have created + // the value here. The issue with that is that a SAMETERM comparison + // would incorrectly return false. + final LiteralLabel ll = LiteralLabelFactory.createIncludingValue(lex, value, CompositeDatatypeList.type); + @SuppressWarnings("deprecation") + Node n = NodeFactory.createLiteral(ll); + return n; + } + + protected Node createMapLiteral( final String lex ) { + // Attention: In contrast to the overridden createTypedLiteral function + // in the superclass, for literals of the CDT datatypes we do not perform + // a checkLiteral check because that would parse the lexical form of the + // literal already once before doing the other parse to obtain the value. + + // parse the given lexical form using this same parser profile + final Map<CDTKey,CDTValue> value; + try { + value = ParserForCDTLiterals.parseMapLiteral(this, lex); + } + catch ( final Exception ex ) { + throw new DatatypeFormatException(lex, CompositeDatatypeMap.type, ex); + } + + // We create a LiteralLabel with both the lexical form and the value, + // for the same reasons as described above in createListLiteral(). + final LiteralLabel ll = LiteralLabelFactory.createIncludingValue(lex, value, CompositeDatatypeMap.type); + @SuppressWarnings("deprecation") + Node n = NodeFactory.createLiteral(ll); + return n; + } }
