This section shows how to load sources into a repository.
package com.hammurapi.test; import java.io.File; import com.hammurapi.lang.java.JavaFactory; import com.hammurapi.lang.java.LoadException; import com.hammurapi.lang.java.Package; import com.hammurapi.lang.java.Repository; public class JavaLanguageModuleTest { /** * @param args */ public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); Repository repository = JavaFactory.eINSTANCE.createRepository(); load(new File("C:\\jdk-5-src"), repository); repository.seal(); for (Package pkg: repository.getPackages()) { System.out.println(pkg); } } private static void load(File file, Repository repository) throws LoadException { if (file.isDirectory()) { for (File child: file.listFiles()) { load(child, repository); } } else if (file.isFile() && file.getName().endsWith(".java")) { repository.load(file); } } }
Node class has List<Node> select(String path) and Node selectSingleNode(String path) methods. These methods take path expression. The expression is defined in AstPath language which is similar to XPath. This section describes AstPath language grammar and provides several examples.
AstPath has the following grammar rules:
OBJBLOCK. AstPath verifies validity of token names.* matches any token... evaluates to node parent.! followed by a token name or by a list of pipe-separated token names in parenthesis. Exclamation mark means negation.Examples:
!ANNOTATIONS - selects children of the current node which type is not ANNOTATIONS.MODIFIERS/* - finds child node(s) of type MODIFIERS and then selects all its children regardless of their type.