use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method generateCode.
/**
* Add generated java code on this level.
* @param aData only used to update imports if needed
* @param source the source code generated
*
* FIXME the implementation only serves as a minimal testing setup
*/
public void generateCode(final JavaGenData aData, final StringBuilder source) {
final String genName = myType.getGenNameOwn();
final Scope myScope = myType.getMyScope();
final PortDefinition portDefinition = new PortDefinition(genName, getFullName());
if (inMessages != null) {
for (int i = 0; i < inMessages.getNofTypes(); i++) {
final IType inType = inMessages.getTypeByIndex(i);
final messageTypeInfo info = new messageTypeInfo(inType.getGenNameValue(aData, source, myScope), inType.getGenNameTemplate(aData, source, myScope), inType.getTypename());
portDefinition.inMessages.add(info);
}
}
if (outMessages != null) {
for (int i = 0; i < outMessages.getNofTypes(); i++) {
final IType outType = outMessages.getTypeByIndex(i);
final messageTypeInfo info = new messageTypeInfo(outType.getGenNameValue(aData, source, myScope), outType.getGenNameTemplate(aData, source, myScope), outType.getTypename());
portDefinition.outMessages.add(info);
}
}
if (inSignatures != null) {
for (int i = 0; i < inSignatures.getNofTypes(); i++) {
final IType outType = inSignatures.getTypeByIndex(i);
final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, false);
portDefinition.inProcedures.add(info);
}
}
if (outSignatures != null) {
for (int i = 0; i < outSignatures.getNofTypes(); i++) {
final IType outType = outSignatures.getTypeByIndex(i);
final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, signature.getSignatureReturnType() != null);
portDefinition.outProcedures.add(info);
}
}
switch(testportType) {
case TP_REGULAR:
portDefinition.testportType = TestportType.NORMAL;
break;
case TP_INTERNAL:
portDefinition.testportType = TestportType.INTERNAL;
break;
case TP_ADDRESS:
portDefinition.testportType = TestportType.ADDRESS;
portDefinition.addressName = "TitanAddress";
break;
default:
portDefinition.testportType = TestportType.NORMAL;
}
if (vardefs != null) {
portDefinition.varDefs = new StringBuilder();
portDefinition.varInit = new StringBuilder();
for (int i = 0; i < vardefs.getNofAssignments(); i++) {
final Definition def = vardefs.getAssignmentByIndex(i);
String type = "";
switch(def.getAssignmentType()) {
case A_VAR:
type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
if (((Def_Var) def).getInitialValue() == null) {
portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
} else {
def.generateCodeInitComp(aData, portDefinition.varInit, def);
}
break;
case A_CONST:
type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
def.generateCodeInitComp(aData, portDefinition.varInit, def);
break;
case A_VAR_TEMPLATE:
type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, myScope);
if (((Def_Var_Template) def).getInitialValue() == null) {
portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
} else {
def.generateCodeInitComp(aData, portDefinition.varInit, def);
}
break;
default:
// FATAL ERROR
break;
}
portDefinition.varDefs.append(MessageFormat.format("private {0} {1} = new {0}();\n", type, def.getGenName()));
}
}
PortGenerator.generateClass(aData, source, portDefinition);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method getAssBySRef.
@Override
public /**
* {@inheritDoc}
*/
Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference, final IReferenceChain refChain) {
if (reference.getModuleIdentifier() != null) {
return getParentScope().getAssBySRef(timestamp, reference);
}
if (lastUniquenessCheck == null) {
checkUniqueness(timestamp);
}
final String name = reference.getId().getName();
Definition definition = definitions.getDefinition(name);
if (definition != null) {
return definition;
}
definition = extendsGainedDefinitions.get(name);
if (definition != null) {
if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
return definition;
}
reference.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, reference.getId().getDisplayName(), identifier.getDisplayName()));
return null;
}
definition = attributeGainedDefinitions.get(name);
if (definition != null) {
if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
return definition;
}
reference.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, reference.getId().getDisplayName(), identifier.getDisplayName()));
return null;
}
return getParentScope().getAssBySRef(timestamp, reference);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method addDeclaration.
public void addDeclaration(final DeclarationCollector declarationCollector, final int i) {
final Identifier identifier = declarationCollector.getReference().getId();
Definition definition = definitions.getDefinition(identifier.getName());
if (definition != null) {
definition.addDeclaration(declarationCollector, i);
}
definition = extendsGainedDefinitions.get(identifier.getName());
if (definition != null) {
definition.addDeclaration(declarationCollector, i);
}
definition = attributeGainedDefinitions.get(identifier.getName());
if (definition != null) {
definition.addDeclaration(declarationCollector, i);
}
if (i == 0) {
super.addDeclaration(declarationCollector);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method hasLocalAssignmentWithId.
/**
* Detects if an assignment with the provided identifier exists inside this
* component.
*
* @param identifier the identifier to be use to search for the assignment.
* @return true if an assignment with the same identifier exists, or false
* otherwise.
*/
public boolean hasLocalAssignmentWithId(final Identifier identifier) {
if (lastUniquenessCheck == null) {
checkUniqueness(CompilationTimeStamp.getBaseTimestamp());
}
final String name = identifier.getName();
Definition definition = definitions.getDefinition(name);
if (definition != null) {
return true;
}
definition = extendsGainedDefinitions.get(name);
if (definition != null) {
return true;
}
return attributeGainedDefinitions.containsKey(name);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method hasAssignmentWithId.
@Override
public /**
* {@inheritDoc}
*/
boolean hasAssignmentWithId(final CompilationTimeStamp timestamp, final Identifier identifier) {
final String name = identifier.getName();
Definition definition = definitions.getDefinition(name);
if (definition != null) {
return true;
}
definition = extendsGainedDefinitions.get(name);
if (definition != null) {
if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
return true;
}
}
definition = attributeGainedDefinitions.get(name);
if (definition != null) {
if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
return true;
}
}
return super.hasAssignmentWithId(timestamp, identifier);
}
Aggregations