Commit 118cd72b authored by gmantele's avatar gmantele
Browse files

[ADQL] Add position on all objects generated by the ADQLParser.

(merge branch 'objectPosition')
parents 37e26a11 163ec172
Loading
Loading
Loading
Loading
+26 −13
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ import adql.search.SimpleSearchHandler;
 * </i></p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 1.3 (05/2015)
 * @version 1.4 (06/2015)
 */
public class DBChecker implements QueryChecker {

@@ -819,7 +819,7 @@ public class DBChecker implements QueryChecker {
				if (match < 0){
					// ...if the type of all parameters is resolved, add an error (no match is possible):
					if (isAllParamTypesResolved(udf))
						errors.addException(new UnresolvedFunctionException(udf));	// TODO Add the ADQLOperand position!
						errors.addException(new UnresolvedFunctionException(udf));
					// ...otherwise, try to resolved it later (when other UDFs will be mostly resolved):
					else
						toResolveLater.add(udf);
@@ -836,7 +836,7 @@ public class DBChecker implements QueryChecker {
				match = binSearch.search(udf, allowedUdfs);
				// if no match, add an error:
				if (match < 0)
					errors.addException(new UnresolvedFunctionException(udf));	// TODO Add the ADQLOperand position!
					errors.addException(new UnresolvedFunctionException(udf));
				// otherwise, metadata may be attached (particularly if the function is built automatically by the syntactic parser):
				else if (udf instanceof DefaultUDF)
					((DefaultUDF)udf).setDefinition(allowedUdfs[match]);
@@ -1003,7 +1003,7 @@ public class DBChecker implements QueryChecker {
		try{
			checkCoordinateSystem(STCS.parseCoordSys(coordSysStr), adqlCoordSys, errors);
		}catch(ParseException pe){
			errors.addException(new ParseException(pe.getMessage())); // TODO Missing object position!
			errors.addException(new ParseException(pe.getMessage(), adqlCoordSys.getPosition()));
		}
	}

@@ -1017,8 +1017,21 @@ public class DBChecker implements QueryChecker {
	 * @since 1.3
	 */
	protected void checkCoordinateSystem(final CoordSys coordSys, final ADQLOperand operand, final UnresolvedIdentifiersException errors){
		if (coordSysRegExp != null && coordSys != null && !coordSys.toFullSTCS().matches(coordSysRegExp))
			errors.addException(new ParseException("Coordinate system \"" + ((operand instanceof StringConstant) ? ((StringConstant)operand).getValue() : coordSys.toString()) + "\" (= \"" + coordSys.toFullSTCS() + "\") not allowed in this implementation."));	// TODO Missing object position! + List of accepted coordinate systems
		if (coordSysRegExp != null && coordSys != null && !coordSys.toFullSTCS().matches(coordSysRegExp)){
			StringBuffer buf = new StringBuffer();
			if (allowedCoordSys != null){
				for(String cs : allowedCoordSys){
					if (buf.length() > 0)
						buf.append(", ");
					buf.append(cs);
				}
			}
			if (buf.length() == 0)
				buf.append("No coordinate system is allowed!");
			else
				buf.insert(0, "Allowed coordinate systems are: ");
			errors.addException(new ParseException("Coordinate system \"" + ((operand instanceof StringConstant) ? ((StringConstant)operand).getValue() : coordSys.toString()) + "\" (= \"" + coordSys.toFullSTCS() + "\") not allowed in this implementation. " + buf.toString(), operand.getPosition()));
		}
	}

	/**
@@ -1060,7 +1073,7 @@ public class DBChecker implements QueryChecker {
				// check whether the regions (this one + the possible inner ones) and the coordinate systems are allowed:
				checkRegion(region, (RegionFunction)result, binSearch, errors);
			}catch(ParseException pe){
				errors.addException(new ParseException(pe.getMessage())); // TODO Missing object position!
				errors.addException(new ParseException(pe.getMessage(), result.getPosition()));
			}
		}
	}
@@ -1155,17 +1168,17 @@ public class DBChecker implements QueryChecker {
				case 'G':
				case 'g':
					if (!unknown.isGeometry())
						errors.addException(new ParseException("Type mismatch! A geometry was expected instead of \"" + unknown.toADQL() + "\"."));	// TODO Add the ADQLOperand position!
						errors.addException(new ParseException("Type mismatch! A geometry was expected instead of \"" + unknown.toADQL() + "\".", result.getPosition()));
					break;
				case 'N':
				case 'n':
					if (!unknown.isNumeric())
						errors.addException(new ParseException("Type mismatch! A numeric value was expected instead of \"" + unknown.toADQL() + "\"."));	// TODO Add the ADQLOperand position!
						errors.addException(new ParseException("Type mismatch! A numeric value was expected instead of \"" + unknown.toADQL() + "\".", result.getPosition()));
					break;
				case 'S':
				case 's':
					if (!unknown.isString())
						errors.addException(new ParseException("Type mismatch! A string value was expected instead of \"" + unknown.toADQL() + "\"."));	// TODO Add the ADQLOperand position!
						errors.addException(new ParseException("Type mismatch! A string value was expected instead of \"" + unknown.toADQL() + "\".", result.getPosition()));
					break;
			}
		}
+2 −2
Original line number Diff line number Diff line
@@ -1395,7 +1395,7 @@ public final class STCS {
			if (nextToken().matches(numericRegExp))
				return Double.parseDouble(token);
			else
				throw new ParseException("a numeric was expected!", new TextPosition(1, pos - token.length(), 1, pos));	// TODO Check the begin and end!
				throw new ParseException("a numeric was expected!", new TextPosition(1, pos - token.length(), 1, pos));
		}

		/**
@@ -1415,7 +1415,7 @@ public final class STCS {
				if (pe instanceof EOEException)
					throw pe;
				else
					throw new ParseException("a coordinates pair (2 numerics separated by one or more spaces) was expected!", new TextPosition(1, startPos, 1, pos));	// TODO Check the begin and end!
					throw new ParseException("a coordinates pair (2 numerics separated by one or more spaces) was expected!", new TextPosition(1, startPos, 1, pos));
			}
		}

+17 −4
Original line number Diff line number Diff line
@@ -20,13 +20,14 @@ package adql.db.exception;
 */

import adql.parser.ParseException;
import adql.query.TextPosition;
import adql.query.operand.function.ADQLFunction;

/**
 * Exception thrown when a function can not be resolved by the library.
 * 
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 1.3 (05/2015)
 * @version 1.4 (06/2015)
 * @since 1.3
 */
public class UnresolvedFunctionException extends ParseException {
@@ -41,7 +42,19 @@ public class UnresolvedFunctionException extends ParseException {
	 * @param message	Description of the error.
	 */
	public UnresolvedFunctionException(final String message){
		super(message);
		this(message, (TextPosition)null);
	}

	/**
	 * Build the exception with just a message.
	 * 
	 * @param message	Description of the error.
	 * @param pos		Position of the unresolved function inside the ADQL query.
	 * 
	 * @since 1.4
	 */
	public UnresolvedFunctionException(final String message, final TextPosition pos){
		super(message, pos);
		functionInError = null;
	}

@@ -52,7 +65,7 @@ public class UnresolvedFunctionException extends ParseException {
	 * @param fct	The unresolved function.
	 */
	public UnresolvedFunctionException(final ADQLFunction fct){
		super("Unresolved function: \"" + fct.toADQL() + "\"! No UDF has been defined or found with the signature: " + getFctSignature(fct) + "."); // TODO Add the position of the function in the ADQL query!
		super("Unresolved function: \"" + fct.toADQL() + "\"! No UDF has been defined or found with the signature: " + getFctSignature(fct) + ".", fct.getPosition());
		functionInError = fct;
	}

@@ -64,7 +77,7 @@ public class UnresolvedFunctionException extends ParseException {
	 * @param fct		The unresolved function.
	 */
	public UnresolvedFunctionException(final String message, final ADQLFunction fct){
		super(message); // TODO Add the position of the function in the ADQL query!
		super(message, (fct == null) ? null : fct.getPosition());
		functionInError = fct;
	}

+6 −6
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import adql.parser.ParseException;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 1.3 (04/2015)
 * @version 1.4 (06/2015)
 * 
 * @see DBChecker
 */
@@ -75,7 +75,7 @@ public class UnresolvedIdentifiersException extends ParseException implements It
			}else if (pe instanceof UnresolvedFunctionException){
				String fctName = (((UnresolvedFunctionException)pe).getFunction() == null) ? null : ((UnresolvedFunctionException)pe).getFunction().getName() + "(...)";
				if (fctName != null && fctName.trim().length() > 0)
					addIdentifierName(fctName /*+ " " + pe.getPosition()*/);	// TODO Add the position of the function in the ADQL query!
					addIdentifierName(fctName + " " + pe.getPosition());
			}else if (pe instanceof UnresolvedIdentifiersException)
				addIdentifierName(((UnresolvedIdentifiersException)pe).unresolvedIdentifiers);
		}
+13 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ import adql.query.TextPosition;
 * This exception is thrown when a table between 2 tables can not be resolved,
 * and particularly because of the join condition (i.e. column names not found, ...).
 * 
 * @author Gr&eacute;gory Mantelet (ARI) - gmantele@ari.uni-heidelberg.de
 * @version 1.3 (05/2015)
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 1.4 (06/2015)
 * @since 1.2
 */
public class UnresolvedJoinException extends ParseException {
@@ -53,4 +53,15 @@ public class UnresolvedJoinException extends ParseException {
		super(message, errorPosition);
	}

	/**
	 * Set the position of the invalid JOIN.
	 * 
	 * @param pos	Position of the concerned JOIN inside the ADQL query.
	 * 
	 * @since 1.4
	 */
	public void setPosition(final TextPosition pos){
		this.position = pos;
	}

}
Loading