org.jsimpledb.parse.expr.AbstractArrayNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimpledb-parse Show documentation
Show all versions of jsimpledb-parse Show documentation
JSimpleDB classes for parsing Java expressions.
The newest version!
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package org.jsimpledb.parse.expr;
import org.jsimpledb.parse.ParseSession;
import org.jsimpledb.parse.ParseUtil;
/**
* Superclass for array instantiation nodes.
*/
abstract class AbstractArrayNode implements Node {
protected final ClassNode baseTypeNode;
protected final int numDimensions;
protected AbstractArrayNode(ClassNode baseTypeNode, int numDimensions) {
this.baseTypeNode = baseTypeNode;
this.numDimensions = numDimensions;
}
/**
* Resolve the array base type.
*
* @param session parse session
* @return resolved array base type
* @throws EvalException if base type is {@code void}
* @throws EvalException if base type cannot be resolved
*/
protected Class> getBaseType(ParseSession session) {
final Class> baseType = this.baseTypeNode.resolveClass(session);
if (baseType == void.class)
throw new EvalException("illegal instantiation of void array");
return baseType;
}
@Override
public Class> getType(ParseSession session) {
try {
return ParseUtil.getArrayClass(this.getBaseType(session), this.numDimensions);
} catch (EvalException e) {
return Object.class;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy