Java Language Module

License

Version

0.1

Requirements

Resources and downloads

Sample code

This section shows how to load sources into a repository.

JavaLanguageModuleTest.java
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);
		}		
	}
}

AstPath query language

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:

  • indexedPath is the root rule of the grammar. It is a list of pipe-separated paths.
  • ipath - single path.
  • indexedPathElement - path element with optional index. Index shall be an integer and shall be defined in square brackets. Path element can be:
    • Token name, e.g. 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.
Last modified: 2010/03/23 23:12 by Pavel Vlasov
   
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Hammurapi Group