org.eclipse.mtl.parser
Class MTLSourceBuffer

java.lang.Object
  extended by org.eclipse.mtl.parser.MTLSourceBuffer
All Implemented Interfaces:
IASTLogHandler, IASTProvider

public class MTLSourceBuffer
extends java.lang.Object
implements IASTProvider, IASTLogHandler

The source to parse. It can be created from a file or a buffer. The file property is null if this object has been created from a buffer. You can create an AST model with the method 'createAST'. An AST is created in a single resource. All the dependencies of this resource will be searched in the other resources of the same 'ResourceSet'. You can resolve the links between the different AST models of the current 'ResourceSet' with the method 'resolveAST'. The parsing issues are accessible by using the method 'getProblems'.

The resolution step must always be done at the end of the parsing of each file of the 'ResourceSet', like in the following example.


Resource resource1 = resourceSet.createResource(uriTarget1);

Resource resource2 = resourceSet.createResource(uriTarget2);

MTLSourceBuffer source1 = new MTLSourceBuffer(file1);

MTLSourceBuffer source2 = new MTLSourceBuffer(file1);

source1.createAST(resource1);

source2.createAST(resource2);

source1.resolveAST();

source2.resolveAST();



Field Summary
protected  java.lang.StringBuffer buffer
          The buffer to parse.
protected  java.io.File file
          The file to parse, can be null if the object is created with a buffer.
protected  MTLParserProblems problems
          Parsing problems.
 
Constructor Summary
MTLSourceBuffer(java.io.File file)
          Constructor.
MTLSourceBuffer(java.lang.StringBuffer buffer)
          Constructor.
 
Method Summary
 void createAST(org.eclipse.emf.ecore.resource.Resource resource)
          Creates the AST model.
 Module getAST()
          Gets the AST model.
 java.lang.StringBuffer getBuffer()
          Returns the string buffer to parse.
 java.io.File getFile()
          Returns the parsed file, can be null if the object is created with a buffer.
 MTLParserProblems getProblems()
          Gets parsing issues.
 void log(java.lang.String message, int posBegin, int posEnd)
          To log a new problem.
 void resolveAST()
          Resolution step of the AST creation: OCL and invocations.
 int[] trim(int posBegin, int posEnd)
          Gets the smallest range that contains all the significant characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected final java.io.File file
The file to parse, can be null if the object is created with a buffer.


buffer

protected final java.lang.StringBuffer buffer
The buffer to parse.


problems

protected final MTLParserProblems problems
Parsing problems.

Constructor Detail

MTLSourceBuffer

public MTLSourceBuffer(java.io.File file)
Constructor.

Parameters:
file - is the file to parse

MTLSourceBuffer

public MTLSourceBuffer(java.lang.StringBuffer buffer)
Constructor.

Parameters:
buffer - is the buffer to parse, the file property will be null
Method Detail

getFile

public java.io.File getFile()
Returns the parsed file, can be null if the object is created with a buffer.

Returns:
the parsed file

getProblems

public MTLParserProblems getProblems()
Gets parsing issues.

Returns:
the parsing issues

getBuffer

public java.lang.StringBuffer getBuffer()
Returns the string buffer to parse.

Returns:
the buffer

getAST

public Module getAST()
Gets the AST model. It is created when you call the 'createAST' function.

Specified by:
getAST in interface IASTProvider
Returns:
the AST model

createAST

public void createAST(org.eclipse.emf.ecore.resource.Resource resource)
Creates the AST model. This function must be called before 'resolveAST'

Specified by:
createAST in interface IASTProvider
Parameters:
resource - where the AST will be stored
See Also:
IASTProvider.createAST(org.eclipse.emf.ecore.resource.Resource)

resolveAST

public void resolveAST()
Resolution step of the AST creation: OCL and invocations. This function must be called after 'createAST'.

Specified by:
resolveAST in interface IASTProvider
See Also:
IASTProvider.resolveAST()

log

public void log(java.lang.String message,
                int posBegin,
                int posEnd)
To log a new problem.

Specified by:
log in interface IASTLogHandler
Parameters:
message - is the message
posBegin - is the beginning index of the problem
posEnd - is the ending index of the problem
See Also:
IASTLogHandler.log(java.lang.String, int, int)

trim

public int[] trim(int posBegin,
                  int posEnd)
Gets the smallest range that contains all the significant characters. Returns an array with 2 elements {trim.begin, trim.end}.

Parameters:
posBegin - is the beginning index of the range
posEnd - is the ending index of the range
Returns:
the smallest range that contains all the significant characters, the length of the array is always 2
See Also:
String.trim()

Copyright 2008 Obeo
All Rights Reserved.