Skip to content

Commit

Permalink
MONDRIAN: Rename 'CAST' operator to 'Cast'.
Browse files Browse the repository at this point in the history
	Allow DiffRepository to look elsewhere than testsrc/main.

[git-p4: depot-paths = "//open/mondrian/": change = 7577]
  • Loading branch information
julianhyde committed Sep 6, 2006
1 parent aa6a5b6 commit 0ee708e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/mondrian/olap/fun/CastFunDef.java
Expand Up @@ -113,8 +113,8 @@ private RuntimeException cannotConvert(Object o) {
private static class ResolverImpl extends ResolverBase {

public ResolverImpl() {
super("CAST", "CAST(<Expression> AS <Type>)",
"Converts values to another type", Syntax.Cast);
super("Cast", "Cast(<Expression> AS <Type>)",
"Converts values to another type.", Syntax.Cast);
}

public FunDef resolve(
Expand Down
51 changes: 41 additions & 10 deletions testsrc/main/mondrian/test/DiffRepository.java
Expand Up @@ -134,13 +134,23 @@ public class DiffRepository
*/
private static final Map mapClassToRepos = new HashMap();

/**
* Directories to look for log file in.
*/
private final String[] prefixes;

/**
* Default prefix directories.
*/
public static final String[] DefaultPrefixes = {"testsrc", "main"};

private static File findFile(Class clazz, final String suffix)
private static File findFile(
Class clazz, String[] prefixes, final String suffix)
{
// The reference file for class "com.foo.Bar" is "com/foo/Bar.ref.xml"
String rest =
clazz.getName().replace('.', File.separatorChar) + suffix;
File fileBase = getFileBase(clazz);
File fileBase = getFileBase(clazz, prefixes);
return new File(fileBase, rest);
}

Expand All @@ -151,13 +161,17 @@ private static File findFile(Class clazz, final String suffix)
* If the current directory is "/home/jhyde/open/mondrian/intellij",
* returns "/home/jhyde/open/mondrian/testsrc".
*/
private static File getFileBase(Class clazz)
private static File getFileBase(Class clazz, String[] prefixes)
{
String javaFileName =
clazz.getName().replace('.', File.separatorChar) + ".java";
File file = new File(System.getProperty("user.dir"));
while (true) {
File file2 = new File(new File(file, "testsrc"), "main");
File file2 = file;
for (int i = 0; i < prefixes.length; i++) {
String prefix = prefixes[i];
file2 = new File(file2, prefix);
}
if (file2.isDirectory() &&
new File(file2, javaFileName).exists()) {
return file2;
Expand All @@ -170,8 +184,13 @@ private static File getFileBase(Class clazz)
}
}

public DiffRepository(File refFile, File logFile, DiffRepository baseRepos)
public DiffRepository(
File refFile, File logFile, DiffRepository baseRepos,
String[] prefixes)
{
this.prefixes =
prefixes == null ? new String[] {"testsrc", "main"} :
prefixes;
this.baseRepos = baseRepos;
if (refFile == null) {
throw new IllegalArgumentException("url must not be null");
Expand Down Expand Up @@ -604,9 +623,15 @@ private static boolean isWhitespace(String text)
return true;
}

/**
* Finds the repository instance for a given class, using the default
* prefixes, and with no parent repository.
*
* @see #lookup(Class, DiffRepository, String[])
*/
public static DiffRepository lookup(Class clazz)
{
return lookup(clazz, null);
return lookup(clazz, null, null);
}

/**
Expand All @@ -626,15 +651,21 @@ public static DiffRepository lookup(Class clazz)
*
* @param clazz Testcase class
* @param baseRepos Base class of test class
* @param prefixes Array of directory names to look in; if null, the
* default {"testsrc", "main"} is used
* @return The diff repository shared between testcases in this class.
*/
public static DiffRepository lookup(Class clazz, DiffRepository baseRepos)
public static DiffRepository lookup(
Class clazz, DiffRepository baseRepos, String[] prefixes)
{
DiffRepository diffRepos = (DiffRepository) mapClassToRepos.get(clazz);
if (diffRepos == null) {
final File refFile = findFile(clazz, ".ref.xml");
final File logFile = findFile(clazz, ".log.xml");
diffRepos = new DiffRepository(refFile, logFile, baseRepos);
if (prefixes == null) {
prefixes = DefaultPrefixes;
}
final File refFile = findFile(clazz, prefixes, ".ref.xml");
final File logFile = findFile(clazz, prefixes, ".log.xml");
diffRepos = new DiffRepository(refFile, logFile, baseRepos, null);
mapClassToRepos.put(clazz, diffRepos);
}
return diffRepos;
Expand Down

0 comments on commit 0ee708e

Please sign in to comment.