use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType method addProposal.
/**
* Searches and adds a completion proposal to the provided collector if
* a valid one is found.
* <p>
* In case of structural types, the member fields are checked if they
* could complete the proposal.
*
* @param propCollector
* the proposal collector to add the proposal to, and
* used to get more information
* @param i
* index, used to identify which element of the reference
* (used by the proposal collector) should be checked for
* completions.
*/
@Override
public /**
* {@inheritDoc}
*/
void addProposal(final ProposalCollector propCollector, final int i) {
final List<ISubReference> subreferences = propCollector.getReference().getSubreferences();
if (subreferences.size() <= i || components == null) {
return;
}
final ISubReference subreference = subreferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
if (subreferences.size() > i + 1) {
// the reference might go on
final CompField compField = components.getCompByName(subreference.getId());
if (compField == null) {
return;
}
final IType type = compField.getType();
if (type != null) {
type.addProposal(propCollector, i + 1);
}
} else {
// final part of the reference
final List<CompField> compFields = components.getComponentsWithPrefix(subreference.getId().getName());
for (final CompField compField : compFields) {
final String proposalKind = compField.getType().getProposalDescription(new StringBuilder()).toString();
propCollector.addProposal(compField.getIdentifier(), " - " + proposalKind, ImageCache.getImage(getOutlineIcon()), proposalKind);
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType method addDeclaration.
/**
* Searches and adds a declaration proposal to the provided collector if
* a valid one is found.
* <p>
* In case of structural types, the member fields are checked if they
* could be the declaration searched for.
*
* @param declarationCollector
* the declaration collector to add the declaration to,
* and used to get more information.
* @param i
* index, used to identify which element of the reference
* (used by the declaration collector) should be checked.
*/
@Override
public /**
* {@inheritDoc}
*/
void addDeclaration(final DeclarationCollector declarationCollector, final int i) {
final List<ISubReference> subreferences = declarationCollector.getReference().getSubreferences();
if (subreferences.size() <= i) {
return;
}
final ISubReference subreference = subreferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
if (subreferences.size() > i + 1) {
// the reference might go on
final CompField compField = components.getCompByName(subreference.getId());
if (compField == null) {
return;
}
final IType type = compField.getType();
if (type != null) {
type.addDeclaration(declarationCollector, i + 1);
}
} else {
// final part of the reference
final List<CompField> compFields = components.getComponentsWithPrefix(subreference.getId().getName());
for (final CompField compField : compFields) {
declarationCollector.addDeclaration(compField.getIdentifier().getDisplayName(), compField.getIdentifier().getLocation(), this);
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType method generateCodeIsPresentBoundChosen.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, String field) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return;
}
if (subReferenceIndex >= subreferences.size()) {
return;
}
final StringBuilder closingBrackets = new StringBuilder();
if (isTemplate) {
boolean anyvalueReturnValue = true;
if (optype == Operation_type.ISPRESENT_OPERATION) {
anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
anyvalueReturnValue = false;
}
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("case ANY_VALUE:\n");
expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
expression.expression.append("break;\n");
expression.expression.append("case SPECIFIC_VALUE:{\n");
closingBrackets.append("break;}\n");
closingBrackets.append("default:\n");
closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
closingBrackets.append("break;\n");
closingBrackets.append("}\n");
closingBrackets.append("}\n");
}
final ISubReference subReference = subreferences.get(subReferenceIndex);
if (!(subReference instanceof FieldSubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return;
}
final Identifier fieldId = ((FieldSubReference) subReference).getId();
final CompField compField = getComponentByName(fieldId);
final Type nextType = compField.getType();
final boolean nextOptional = !isTemplate && compField.isOptional();
if (nextOptional) {
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("Optional<{0}{1}> {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
if (subReferenceIndex == subreferences.size() - 1) {
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
expression.expression.append("case OPTIONAL_UNBOUND:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("case OPTIONAL_OMIT:\n");
expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, optype == Operation_type.ISBOUND_OPERATION ? "true" : "false"));
expression.expression.append("break;\n");
expression.expression.append("default:\n");
expression.expression.append("{\n");
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
if (optype == Operation_type.ISBOUND_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
} else if (optype == Operation_type.ISPRESENT_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isPresent({2});\n", globalId, temporalId2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
}
expression.expression.append("break;}\n");
expression.expression.append("}\n");
// at the end of the reference chain
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
} else {
// still more to go
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
expression.expression.append("case OPTIONAL_UNBOUND:\n");
expression.expression.append("case OPTIONAL_OMIT:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("default:\n");
expression.expression.append("break;\n");
expression.expression.append("}\n");
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
}
} else {
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId = aData.getTemporaryVariableName();
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = new {0}{1}({3});\n", getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId));
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
if (optype == Operation_type.ISBOUND_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
} else if (optype == Operation_type.ISPRESENT_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.{2}({3});\n", globalId, temporalId2, subReferenceIndex != subreferences.size() - 1 ? "isBound" : "isPresent", subReferenceIndex == subreferences.size() - 1 && isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
if (subReferenceIndex == subreferences.size() - 1) {
expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
expression.expression.append("}\n");
}
}
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
}
expression.expression.append(closingBrackets);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method checkCodingAttributes.
@Override
public /**
* {@inheritDoc}
*/
void checkCodingAttributes(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
if (refChain.contains(this)) {
return;
}
refChain.add(this);
refChain.markState();
for (int i = 0; i < getNofComponents(timestamp); i++) {
final CompField cf = getComponentByIndex(i);
cf.getType().checkCodingAttributes(timestamp, refChain);
}
refChain.previousState();
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method checkRecursions.
@Override
public /**
* {@inheritDoc}
*/
void checkRecursions(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
if (components == null) {
return;
}
if (referenceChain.add(this)) {
CompField field;
IType t;
for (int i = 0, size = components.getNofComps(); i < size; i++) {
field = components.getCompByIndex(i);
t = field.getType();
if (!field.isOptional() && t != null) {
referenceChain.markState();
t.checkRecursions(timestamp, referenceChain);
referenceChain.previousState();
}
}
}
}
Aggregations