org.vishia.java2C
Class LocalIdents

java.lang.Object
  extended by org.vishia.java2C.LocalIdents

public class LocalIdents
extends java.lang.Object

This class contains all identifiers visible at class level or visible at a local position of code. It means, visible at class level by generating the class members, visible at level of a block statement including stack variable etc.


Field Summary
private  java.lang.String debugPath
          Only for toString in debugging/reporting.
private  ClassData declaringClassData
          The ClassData for which is this member of, or null if it isn't classLevelIdents of ClassData. }
(package private)  java.util.TreeMap<java.lang.String,FieldData> fieldIdents
          List of known fields of this context.
private static java.lang.String newLineIndent
           
private  LocalIdents parent
          The parent idents.
private  java.util.TreeMap<java.lang.String,JavaSources.ClassDataOrJavaSrcFile> typeIdents
          List of known types of this context.
 
Constructor Summary
LocalIdents(ClassData declaringClass)
          constructs a new instance for a class level.
LocalIdents(LocalIdents parent, ClassData declaringClassData, boolean hasFields, java.lang.String sPkgName)
          constructs a new instance copying all parent identifier.
LocalIdents(LocalIdents parent, java.lang.String sPkgName)
          constructs a new instance with copy all parent identifier as base.
LocalIdents(java.lang.String sPkgName)
          constructs a new Instance for primary types.
 
Method Summary
(package private)  void copyFieldsTo(ClassData innerClassData)
          Copies all field idents from the current level (called for the outer class) to the named inner class and all methods bodies (its main statement block).
(package private)  void copyTypesTo(ClassData innerClass)
           
 FieldData get(java.lang.String sIdent)
          searches the infos to the given identifier.
 java.lang.String getAllTypeIdents()
          Returns a String with all available type idents comma separated.
 FieldData getField(java.lang.String name)
          Test whether the field is known and returns it data.
 ClassData getType(java.lang.String sIdent, LocalIdents fileLevelIdents)
          searches the ClassData to the given type identifier.
 JavaSources.ClassDataOrJavaSrcFile getTypeInfo(java.lang.String sIdentP, LocalIdents fileLevelIdents)
          searches the infos to the given type identifier.
 java.util.Set<java.util.Map.Entry<java.lang.String,JavaSources.ClassDataOrJavaSrcFile>> getTypeSet()
          Returns an iterable list with all typeIdents.
(package private)  java.lang.String indent(int recursion)
           
 void putClassElement(java.lang.String sIdent, FieldData identInfo)
          puts a new class element (field, attribute, reference) in the container.
 void putClassElement(java.lang.String sIdent, java.lang.String sType, ClassData typeClazz, char staticMode, char modeAccess, java.lang.String sModifier, int dimensionArray, java.lang.String[] fixArraySizes, char modeArrayElement, ClassData clazz)
          puts a new class element (field, attribute, reference) in the container.
 void putClassType(ClassData typeClazz)
           
 void putClassType(java.lang.String sTypeIdent, JavaSources.ClassDataOrJavaSrcFile typeClazz)
           
 void putClassType(java.lang.String sTypeIdent, java.lang.String sTypeNameC, ClassData typeClazz, java.lang.String sModifier, ClassData clazz)
          Deprecated. use #putClassType(String, ClassData)
 void putClassTypesAll(LocalIdents parent)
           
 void putClassTypeStandard(ClassData typeClazz)
          Puts the class into the typeIdents, with key with and without package.
(package private)  void putElement(java.lang.String sIdent, FieldData identInfo)
          puts a new stack-local element in the container.
 void putLocalElement(java.lang.String sIdent, FieldData identInfo)
          puts a new stack-local element in the container.
(package private)  void stop()
          It's a debug helper.
 java.lang.String toString()
           
(package private)  void xxxcompleteFieldIdentsForInnerClasses()
          Adds all fields known here to the non-static inner classes and their methods.
 java.lang.String xxxwriteStructOwnClassFields(int recursion)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fieldIdents

final java.util.TreeMap<java.lang.String,FieldData> fieldIdents
List of known fields of this context.


typeIdents

private final java.util.TreeMap<java.lang.String,JavaSources.ClassDataOrJavaSrcFile> typeIdents
List of known types of this context.


parent

private final LocalIdents parent
The parent idents. They contained the visible types of super levels, for example the class types, if this is a LocalIdents of a statement block.


debugPath

private final java.lang.String debugPath
Only for toString in debugging/reporting.


declaringClassData

private final ClassData declaringClassData
The ClassData for which is this member of, or null if it isn't classLevelIdents of ClassData. }


newLineIndent

private static final java.lang.String newLineIndent
See Also:
Constant Field Values
Constructor Detail

LocalIdents

public LocalIdents(LocalIdents parent,
                   ClassData declaringClassData,
                   boolean hasFields,
                   java.lang.String sPkgName)
constructs a new instance copying all parent identifier. This method is called especially if the identifier infos of a class is built.

Parameters:
parent - The identifier infos of the parent scope are copied, the parent scope is not touched (changed). This parameter should be null while the LocalIdents of a non-inner class is created because there aren't any identifiers to copy outside of a top-level class. It should be given, if the LocalIdents of a method or statement blocks or of an inner class is created.
declaringClassData - All identifier infos of all super and outer classes of this class are copied. This parameter should be null while the LocalIdents of methods or statement blocks are created.
fileLevelIdents - LocalIdents of the package.

LocalIdents

public LocalIdents(LocalIdents parent,
                   java.lang.String sPkgName)
constructs a new instance with copy all parent identifier as base. This constructor is called especially if the identifier infos of a local scope (method, statement block) are built.

Parameters:
parent - The identifier infos of the parent scope is copied, but the parent scope should be not touched (changed).

LocalIdents

public LocalIdents(java.lang.String sPkgName)
constructs a new Instance for primary types. Field Identifier are not planned.


LocalIdents

public LocalIdents(ClassData declaringClass)
constructs a new instance for a class level. All identifiers of outer and super classes of the declaring class are copied too. They are visible as super identifiers or outer identifiers.

Parameters:
declaringClass - The class where the LocalIdents are assigned to.
fileLevelIdents - The LocalIdents of the package containing all package visible and commonly types.
Method Detail

get

public FieldData get(java.lang.String sIdent)
searches the infos to the given identifier.

Parameters:
sIdent - The identifier.
Returns:
null if not found.

getType

public ClassData getType(java.lang.String sIdent,
                         LocalIdents fileLevelIdents)
                  throws java.text.ParseException
searches the ClassData to the given type identifier. If the type is found as a JavaSrcTreeFile, which isn't translated, its first pass is run now. The first pass translates the file either, or it reads its structure (stc-)file.

If the type isn't found, neither as JavaSrcTreeFile nor as ClassData, this method returns null. It may be possible that the type should be exists as a unknown type, than it is created, outside of this routine see GenerateClass.getType(org.vishia.zbnf.ZbnfParseResultItem, LocalIdents). It may be possible too, that the identifier may be either a type or an association. If it isn't found as type, it may be found as association. Therefore this routine have to be returned null at unknown identifiers.

Parameters:
sIdent - The identifier.
Returns:
null if the identifier is not found, elsewhere the found instance.
Throws:
java.lang.IllegalArgumentException - if any problem while running first pass occurs.
java.text.ParseException

getTypeInfo

public JavaSources.ClassDataOrJavaSrcFile getTypeInfo(java.lang.String sIdentP,
                                                      LocalIdents fileLevelIdents)
searches the infos to the given type identifier. A translation process isn't activated from here, see getType(String, LocalIdents).

The identifier respectively the first package is searched in this LocalIdents and all its parents firstly. That are local visible idents. The parent of this are the outer blocks of statement, the class and the outer classes. and super classes.

If the type isn't found there, it is searched in the given fileLevelIdents. The fileLevelIdents are the idents of the package, where the to-translate-class is member of (not the declaring class of this!). The fileLevelIdents contains the types too, which are given with the import-statements of the to-translate-class.

If the type isn't found neither in the local context nor in the fileLevelIdents, they are searched as top-level-package. Consider, that this routine is called recursively to dissolve a given package path. Therefore the top-level package should be found. If a local package exists with the same name like a top level, it is found first and used therefore.

If the identifier isn't found, than it is searched in the global visible types. That are the standard types like int etc. and the java.lang.Types. It are referred by CRuntimeJavalikeClassData.stdTypes.

At least the type is searched in Java2C_Main.externalTypes.

It may be possible in the users Java-code, that the identifier may be either a type or an association. That isn't able to different by the syntax, because both cases are written as "Type.element" or "association.element". The usual distinction using an upper case letter to start for types can't be us for a decision really. Therefore this routine returns null at unknown identifiers. An exception or error message mustn't create here.

Parameters:
sIdent - The identifier. It is possible it is a package path, at example java.lang.Object. The separator between package idents can be a slash or a dot.
fileLevelIdents - Contains all types which are known as environment for translation of this file. They are all package level types and all types, which are known because import-statements.
Returns:
null if not found. Than the type isn't known. If not null, than it may be an instance of ClassData for simple types, or it is an instance of JavaSrcTreeFile. If the file is translated already, calling JavaSources.ClassDataOrJavaSrcFile.getClassData() supplies the ClassData, if it isn't translated yet but only known as Java-File, getClassData() returns null.
Throws:
java.text.ParseException

putClassElement

public void putClassElement(java.lang.String sIdent,
                            java.lang.String sType,
                            ClassData typeClazz,
                            char staticMode,
                            char modeAccess,
                            java.lang.String sModifier,
                            int dimensionArray,
                            java.lang.String[] fixArraySizes,
                            char modeArrayElement,
                            ClassData clazz)
puts a new class element (field, attribute, reference) in the container.

Parameters:
sIdent - The textual representation of the identifier in java code context.
sType - The associated type string if it is a field or method. null if it is a type.
typeClazz - The associated type class
sModifier - Kind of the identifier. See table in the description of the class ClassData.
clazz - The associated class data

putClassElement

public void putClassElement(java.lang.String sIdent,
                            FieldData identInfo)
puts a new class element (field, attribute, reference) in the container.

Parameters:
sIdent - name
identInfo - all infos to the field

putClassType

public void putClassType(java.lang.String sTypeIdent,
                         java.lang.String sTypeNameC,
                         ClassData typeClazz,
                         java.lang.String sModifier,
                         ClassData clazz)
Deprecated. use #putClassType(String, ClassData)

puts a new inner class as a Type of the class in the container.

Parameters:
sTypeIdent - The textual representation of the identifier in java code context.
sTypeNameC - The type name in C, with outerclass__sTypeIdent.
typeClazz - The associated type class
sModifier - Kind of the identifier. See table in the description of the class ClassData.
clazz - The associated class data

putClassType

public void putClassType(java.lang.String sTypeIdent,
                         JavaSources.ClassDataOrJavaSrcFile typeClazz)

putClassType

public void putClassType(ClassData typeClazz)

putClassTypeStandard

public void putClassTypeStandard(ClassData typeClazz)
Puts the class into the typeIdents, with key with and without package. The class is able to found with its name only, but with its package too.

Parameters:
typeClazz - The class.

putClassTypesAll

public void putClassTypesAll(LocalIdents parent)

putLocalElement

public void putLocalElement(java.lang.String sIdent,
                            FieldData identInfo)
puts a new stack-local element in the container.

Parameters:
sIdent -
identInfo -

putElement

void putElement(java.lang.String sIdent,
                FieldData identInfo)
puts a new stack-local element in the container.

Parameters:
sIdent -
identInfo -

getField

public FieldData getField(java.lang.String name)
Test whether the field is known and returns it data.

Parameters:
name - The name of the field. The field can be local or in super scopes.
Returns:
null if the field isn't existing.

xxxcompleteFieldIdentsForInnerClasses

void xxxcompleteFieldIdentsForInnerClasses()
Adds all fields known here to the non-static inner classes and their methods. This routine is called for ClassData.classLevelIdents for all classes.

The fields were not be added before because the inner class was built first, after them the outer class was processed in first pass. But the non-static inner class should know all idents from the outer too.


copyFieldsTo

void copyFieldsTo(ClassData innerClassData)
Copies all field idents from the current level (called for the outer class) to the named inner class and all methods bodies (its main statement block). That is necessary because all idents are known only at the end of the first pass of the outer class, but the first pass of the inner class is finished already, without knowledge of all outer idents. All idents should be known while running the second pass only.

The method ClassData#completeFieldIdentsFromOuterClass(LocalIdents) is called unlike if a class is generated in the second pass inside a block statement. In this case the first pass of this class is running only in the second pass of the environment.

The situation of same identifier in the outer and inner class is detected in that complete-methods. The inner identifier covers the outer one.

Parameters:
innerClassData -

copyTypesTo

void copyTypesTo(ClassData innerClass)

indent

java.lang.String indent(int recursion)

xxxwriteStructOwnClassFields

public java.lang.String xxxwriteStructOwnClassFields(int recursion)

getAllTypeIdents

public java.lang.String getAllTypeIdents()
Returns a String with all available type idents comma separated. This String is usefull for help on error unknown type.


getTypeSet

public java.util.Set<java.util.Map.Entry<java.lang.String,JavaSources.ClassDataOrJavaSrcFile>> getTypeSet()
Returns an iterable list with all typeIdents.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

stop

void stop()
It's a debug helper. The method is empty, but it is a mark to set a breakpoint.