Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jun 1, 2024
2 parents 02841bf + 8d5edcc commit 4c29bb9
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Set;
import java.util.TreeMap;

import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlException;
import org.apache.commons.jexl3.JexlFeatures;
Expand Down Expand Up @@ -632,8 +631,9 @@ private boolean isNamespace(String name) {
/**
* Default implementation does nothing but is overridden by generated code.
* @param top whether the identifier is beginning an l/r value
* @throws ParseException subclasses may throw this
* @throws ParseException subclasses may throw ParseException
*/
@SuppressWarnings("unused") // subclasses may throw ParseException
protected void Identifier(final boolean top) throws ParseException {
// Overridden by generated code
}
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ public void jjtSetParent(final Node n) {

/**
* Gets this node's parent.
*
* @return the parent node
*/
@Override
public JexlNode jjtGetParent() {
return parent;
}

/** Adds a child node.
/**
* Adds a child node.
*
* @param n the child node
* @param i the child offset
*/
Expand All @@ -113,6 +116,7 @@ void jjtSetChildren(final JexlNode[] jexlNodes) {

/**
* Gets a child of this node.
*
* @param i the child offset
* @return the child node
*/
Expand All @@ -123,29 +127,35 @@ public JexlNode jjtGetChild(final int i) {

/**
* Gets this node number of children.
*
* @return the number of children
*/
@Override
public int jjtGetNumChildren() {
return children == null ? 0 : children.length;
}

/** Sets this node value.
* @param value
/**
* Sets this node value.
*
* @param value this node value.
*/
public void jjtSetValue(final Object value) {
this.value = value;
}

/** Gets this node value.
/**
* Gets this node value.
*
* @return value
*/
public Object jjtGetValue() {
return value;
}

/**
* Accept the visitor.
* Accepts the visitor.
*
* @param visitor the visitor
* @param data contextual data
* @return result of visit
Expand All @@ -156,7 +166,8 @@ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
}

/**
* Accept the visitor on all this node's children.
* Accepts the visitor on all this node's children.
*
* @param visitor the visitor
* @param data contextual data
* @return result of visit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public String getAfter() {
return after;
}

/***
/**
* Replaces unprintable characters by their espaced (or unicode escaped)
* equivalents in the given string
*/
Expand Down
41 changes: 20 additions & 21 deletions src/test/java/org/apache/commons/jexl3/ClassCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,31 @@ Class<?> compile() throws Exception {
final String source = packageDir.getPath() + "/" + sourceName;
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
final DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>();
final StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, null, null);
final Iterable<? extends JavaFileObject> compilationUnits = fileManager
.getJavaFileObjectsFromStrings(Collections.singletonList(source));

final List<String> options = new ArrayList<>();
options.add("-classpath");
// only add hbase classes to classpath. This is a little bit tricky: assume
// the classpath is {hbaseSrc}/target/classes.
final String currentDir = new File(".").getAbsolutePath();
final String classpath = currentDir + File.separator + "target" + File.separator + "classes"
//+ File.pathSeparator + System.getProperty("java.class.path")
+ File.pathSeparator + System.getProperty("surefire.test.class.path");

options.add(classpath);
//LOG.debug("Setting classpath to: " + classpath);

final JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnosticsCollector, options,
null, compilationUnits);
final boolean success = task.call();
fileManager.close();
final boolean success;
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, null, null)) {
final Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromStrings(Collections.singletonList(source));

final List<String> options = new ArrayList<>();
options.add("-classpath");
// only add hbase classes to classpath. This is a little bit tricky: assume
// the classpath is {hbaseSrc}/target/classes.
final String currentDir = new File(".").getAbsolutePath();
final String classpath = currentDir + File.separator + "target" + File.separator + "classes"
// + File.pathSeparator + System.getProperty("java.class.path")
+ File.pathSeparator + System.getProperty("surefire.test.class.path");

options.add(classpath);
// LOG.debug("Setting classpath to: " + classpath);

final JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnosticsCollector, options, null, compilationUnits);
success = task.call();
}
if (success) {
return getClassLoader().loadClass(GEN_CLASS + className);
}
final List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticsCollector.getDiagnostics();
for (final Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
// read error dertails from the diagnostic object
// read error details from the diagnostic object
System.out.println(diagnostic.getMessage(null));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public int hangs(final Object t) {
return 1;
}

public int interrupt() throws InterruptedException {
public int interrupt() {
Thread.currentThread().interrupt();
return 42;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/commons/jexl3/SideEffectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Object selfAdd(final Appendable c, final String item) throws IOException
return c;
}

public Object selfAdd(final Collection<String> c, final String item) throws IOException {
public Object selfAdd(final Collection<String> c, final String item) {
c.add(item);
return c;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/example/SomeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public JexlEngine create() {
*/
@Test
public void testCustomFunctionPermissions() {
Map<String, Object> funcs = new HashMap<String, Object>();
Map<String, Object> funcs = new HashMap<>();
funcs.put("math", new MyMath());
JexlPermissions permissions = JexlPermissions.parse("org.example.*");
JexlEngine jexl = new JexlBuilder().permissions(permissions).namespaces(funcs).create();
Expand Down

0 comments on commit 4c29bb9

Please sign in to comment.