org.eclipse.mtl.parser
Class MTLSourceBuffer

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

public class MTLSourceBuffer
extends java.lang.Object
implements org.eclipse.mtl.internal.parser.ast.IASTProvider, org.eclipse.mtl.internal.parser.ast.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  Module ast
          The AST model.
protected  org.eclipse.mtl.internal.parser.ast.CST2ASTConverterWithResolver astCreator
          The AST creator.
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.
 void createCST()
          Creates the CST model.
 Module getAST()
          Gets the AST model.
 java.lang.StringBuffer getBuffer()
          Returns the string buffer to parse.
 Module getCST()
          Gets the CST model.
 java.io.File getFile()
          Returns the parsed file, can be null if the object is created with a buffer.
 org.eclipse.mtl.internal.parser.ast.ocl.OCLParser getOCL()
          Gets the OCL parser (from the OCL plug-in).
 MTLParserProblems getProblems()
          Gets parsing issues.
 void log(java.lang.String message, int posBegin, int posEnd)
          To log a new problem.
 void refreshAST()
          Ensure to compute the whole AST before to use it.
 void resolveAST()
          Resolution step of the AST creation: OCL and invocations.
 void resolveAST(int posBegin, int posEnd)
          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.


ast

protected Module ast
The AST model. It is created when you call the 'createAST' function.


astCreator

protected org.eclipse.mtl.internal.parser.ast.CST2ASTConverterWithResolver astCreator
The AST creator. It is created when you call the 'createAST' function.

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 org.eclipse.mtl.internal.parser.ast.IASTProvider
Returns:
the AST model

getCST

public Module getCST()
Gets the CST model. It is created when you call the 'createCST' function.

Returns:
the CST model

getOCL

public org.eclipse.mtl.internal.parser.ast.ocl.OCLParser getOCL()
Gets the OCL parser (from the OCL plug-in).

Returns:
the OCL parser

createAST

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

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

refreshAST

public void refreshAST()
Ensure to compute the whole AST before to use it.


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 org.eclipse.mtl.internal.parser.ast.IASTProvider
See Also:
org.eclipse.mtl.parser.ast.IASTProvider#resolveAST()

resolveAST

public void resolveAST(int posBegin,
                       int posEnd)
Resolution step of the AST creation : OCL and invocations. This function must be called after 'createAST'. The resolution step can be limited to the specified region, for increasing performances. Remark : The -1 value means everywhere.

Parameters:
posBegin - is the lower bound
posEnd - is the upper bound

createCST

public void createCST()
Creates the CST model. This function must be called before 'createAST'

Specified by:
createCST in interface org.eclipse.mtl.internal.parser.ast.IASTProvider
See Also:
org.eclipse.mtl.parser.ast.IASTProvider#createCST()

log

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

Specified by:
log in interface org.eclipse.mtl.internal.parser.ast.IASTLogHandler
Parameters:
message - is the message
posBegin - is the beginning index of the problem
posEnd - is the ending index of the problem
See Also:
org.eclipse.mtl.parser.ast.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.