Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at Contributors: IBM Corporation - initial API and implementation /
 package org.eclipse.jdt.internal.core.jdom;
An abstract DOM builder that contains shared functionality of DOMBuilder and SimpleDOMBuilder.

The JDOM was made obsolete by the addition in 2.0 of the more powerful, fine-grained DOM/AST API found in the org.eclipse.jdt.core.dom package.
 public class AbstractDOMBuilder extends ReferenceInfoAdapter implements ILineStartFinder {
Set to true when an error is encounterd while fuzzy parsing
 	protected boolean fAbort;

True when a compilation unit is being constructed. False when any other type of document fragment is being constructed.
 	protected boolean fBuildingCU = false;

True when a compilation unit or type is being constructed. False when any other type of document fragment is being constructed.
 	protected boolean fBuildingTypefalse;

The String on which the JDOM is being created.
 	protected char[] fDocumentnull;

The source positions of all of the line separators in the document.
 	protected int[] fLineStartPositions = new int[] { 0 };

A stack of enclosing scopes used when constructing a compilation unit or type. The top of the stack is the document fragment that children are added to.
 	protected Stack fStack = null;

The number of fields constructed in the current document. This is used when building a single field document fragment, since the DOMBuilder only accepts documents with one field declaration.
 	protected int fFieldCount;

The current node being constructed.
 	protected DOMNode fNode;
AbstractDOMBuilder constructor.
 public AbstractDOMBuilder() {
Accepts the line separator table and converts it into a line start table.

A line separator might corresponds to several characters in the source.

 public void acceptLineSeparatorPositions(int[] positions) {
 	if (positions != null) {
 		int length = positions.length;
 		if (length > 0) {
 			this. = new int[length + 1];
 			this.[0] = 0;
 			int documentLength = this..length;
 			for (int i = 0; i < lengthi++) {
 				int iPlusOne = i + 1;
 				int positionPlusOne = positions[i] + 1;
 				if (positionPlusOne < documentLength) {
 					if (iPlusOne < length) {
						// more separators
						this.[iPlusOne] = positionPlusOne;
else {
						// no more separators
						if (this.[positionPlusOne] == '\n') {
							this.[iPlusOne] = positionPlusOne + 1;
else {
							this.[iPlusOne] = positionPlusOne;
else {
					this.[iPlusOne] = positionPlusOne;
Adds the given node to the current enclosing scope, building the JDOM tree. Nodes are only added to an enclosing scope when a compilation unit or type is being built (since those are the only nodes that have children).

NOTE: nodes are added to the JDOM via the method #basicAddChild such that the nodes in the newly created JDOM are not fragmented.

protected void addChild(IDOMNode child) {
	if (this..size() > 0) {
		DOMNode parent = (DOMNodethis..peek();
		if (this. || this.) {
public IDOMCompilationUnit createCompilationUnit(char[] contentschar[] name) {
	return createCompilationUnit(new CompilationUnit(contentsname));
	if (this.) {
		return null;
public void enterCompilationUnit() {
 	if (this.) {
 		IDOMCompilationUnit cunew DOMCompilationUnit( int[] {0, this..length - 1});
Finishes the configuration of the compilation unit DOM object which was created by a previous enterCompilationUnit call.

public void exitCompilationUnit(int declarationEnd) {
	this. = cu;
Finishes the configuration of the class and interface DOM objects.

bodyEnd - a source position corresponding to the closing bracket of the class
declarationEnd - a source position corresponding to the end of the class declaration. This can include whitespace and comments following the closing bracket.
protected void exitType(int bodyEndint declarationEnd) {
	DOMType type = (DOMType)this..pop();
	this. = type;
public int getLineStart(int position) {
	int lineSeparatorCount = this..length;
	// reverse traversal intentional.
	for(int i = lineSeparatorCount - 1; i >= 0; i--) {
		if (this.[i] <= position)
			return this.[i];
	return 0;
Initializes the builder to create a document fragment.

sourceCode - the document containing the source code to be analyzed
buildingCompilationUnit - true if a the document is being analyzed to create a compilation unit, otherwise false
buildingType - true if the document is being analyzed to create a type or compilation unit
protected void initializeBuild(char[] sourceCodeboolean buildingCompilationUnitboolean buildingType) {
	this. = buildingCompilationUnit;
	this. = buildingType;
	this. = new Stack();
	this. = sourceCode;
	this. = 0;
	this. = false;
New to GrepCode? Check out our FAQ X