use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Reference method generateCode.
// originally fieldOrArrayRefs
private void generateCode(final JavaGenData aData, final ExpressionStruct expression, final boolean isTemplate, final boolean isConst, IType type) {
for (int i = 1; i < subReferences.size(); i++) {
if (type != null) {
type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
}
final ISubReference subreference = subReferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
final Identifier id = ((FieldSubReference) subreference).getId();
expression.expression.append(".");
if (isConst) {
expression.expression.append("constGet");
} else {
expression.expression.append("get");
}
expression.expression.append(FieldSubReference.getJavaGetterName(id.getName()));
expression.expression.append("()");
if (type != null) {
CompField compField = null;
switch(type.getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
break;
case TYPE_ANYTYPE:
compField = ((Anytype_Type) type).getComponentByName(id.getName());
break;
case TYPE_OPENTYPE:
compField = ((Open_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SEQUENCE:
((ASN1_Sequence_Type) type).parseBlockSequence();
compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SET:
((ASN1_Set_Type) type).parseBlockSet();
compField = ((ASN1_Set_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_CHOICE:
((ASN1_Choice_Type) type).parseBlockChoice();
compField = ((ASN1_Choice_Type) type).getComponentByName(id);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for reference `" + getFullName() + "''");
return;
}
if (i < subReferences.size() - 1 && compField != null && compField.isOptional() && !isTemplate) {
if (isConst) {
expression.expression.append(".constGet()");
} else {
expression.expression.append(".get()");
}
type = compField.getType();
}
}
} else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
final Value value = ((ArraySubReference) subreference).getValue();
// TODO actually should get the last governor
final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
// generate "getAt" functions instead of operator[]
if (isConst) {
expression.expression.append(".constGetAt(");
} else {
expression.expression.append(".getAt(");
}
value.generateCodeExpression(aData, expression, false);
expression.expression.append(")");
if (type != null) {
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
type = ((AbstractOfType) type).getOfType();
break;
case TYPE_ARRAY:
type = ((Array_Type) type).getElementType();
break;
default:
type = null;
}
}
}
}
}
use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Array_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType temp = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
return true;
}
if (info == null || noStructuredTypeCompatibility) {
return this == temp;
}
switch(temp.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
{
final ASN1_Sequence_Type tempType = (ASN1_Sequence_Type) temp;
final int tempTypeNofComps = tempType.getNofComponents(timestamp);
if (tempTypeNofComps == 0) {
return false;
}
final long thisNofComps = getDimension().getSize();
if (thisNofComps != tempTypeNofComps) {
info.setErrorStr(MessageFormat.format(NOFFIELDSDONTMATCH, thisNofComps, tempTypeNofComps));
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < tempTypeNofComps; i++) {
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
lChain.markState();
rChain.markState();
lChain.add(tempElementType);
rChain.add(tempTypeCfType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeCfType, false);
if (!tempElementType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_TTCN3_SEQUENCE:
{
final TTCN3_Sequence_Type tempType = (TTCN3_Sequence_Type) temp;
final int tempTypeNofComps = tempType.getNofComponents();
if (tempTypeNofComps == 0) {
return false;
}
final long nofComps = getDimension().getSize();
if (nofComps != tempTypeNofComps) {
info.setErrorStr(MessageFormat.format(NOFFIELDSDONTMATCH, nofComps, tempTypeNofComps));
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < tempTypeNofComps; i++) {
final CompField tempTypeCf = tempType.getComponentByIndex(i);
final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
lChain.markState();
rChain.markState();
lChain.add(tempElementType);
rChain.add(tempTypeCfType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeCfType, false);
if (!tempElementType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_SEQUENCE_OF:
{
final SequenceOf_Type tempType = (SequenceOf_Type) temp;
if (!tempType.isSubtypeCompatible(timestamp, this)) {
info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
return false;
}
final IType tempTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
lChain.markState();
rChain.markState();
lChain.add(tempElementType);
rChain.add(tempTypeOfType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeOfType, false);
if (!tempElementType.equals(tempTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeOfType, infoTemp, lChain, rChain)) {
info.appendOp1Ref(infoTemp.getOp1RefStr());
if (infoTemp.getOp2RefStr().length() > 0) {
info.appendOp2Ref("[]");
}
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
case TYPE_ARRAY:
{
final Array_Type tempType = (Array_Type) temp;
if (this == tempType) {
return true;
}
if (dimension != null && tempType.dimension != null && !dimension.isIdentical(timestamp, tempType.dimension)) {
info.setErrorStr(BADARRAYDIMENSION);
return false;
}
final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
final IType tempTypeElementType = tempType.getElementType().getTypeRefdLast(timestamp);
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
lChain.markState();
rChain.markState();
lChain.add(tempElementType);
rChain.add(tempTypeElementType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeElementType, false);
if (!tempElementType.equals(tempTypeElementType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeElementType, infoTemp, lChain, rChain)) {
info.appendOp1Ref(infoTemp.getOp1RefStr());
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_ANYTYPE:
info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
return false;
case TYPE_ASN1_SET:
case TYPE_TTCN3_SET:
case TYPE_SET_OF:
info.setErrorStr(NOTCOMPATIBLESETSETOF);
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class RenameRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
// search
idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
// add the referred identifier to the map of found identifiers
Identifier refdIdentifier = rf.getReferredIdentifier();
Module refdModule = rf.assignment.getMyScope().getModuleScope();
if (idsMap.containsKey(refdModule)) {
idsMap.get(refdModule).add(new Hit(refdIdentifier));
} else {
ArrayList<Hit> identifierList = new ArrayList<Hit>();
identifierList.add(new Hit(refdIdentifier));
idsMap.put(refdModule, identifierList);
}
// scopes
if (rf.fieldId == null) {
// check that in all affected scopes there is no
// definition with the new name
Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
if (rf.scope.getModuleScope() instanceof ASN1Module) {
idType = Identifier_type.ID_ASN;
}
Identifier newId = new Identifier(idType, newIdentifierName);
// check for assignment with given id in all sub-scopes
// of the assignment's scope
// TODO: this does not detect runs on <-> component
// member conflicts because the RunsOnScope is not a
// sub-scope of the ComponentTypeBody scope,
// also it does not go into other modules
Scope rootScope = rf.assignment.getMyScope();
if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
rootScope = rootScope.getParentScope();
}
SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
module.accept(subScopeVisitor);
List<Scope> subScopes = subScopeVisitor.getSubScopes();
subScopes.add(rootScope);
for (Scope ss : subScopes) {
if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(newId));
Reference reference = new Reference(null, subReferences);
Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
if (assignment != null && assignment.getLocation() != null) {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
} else {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
}
// to avoid spam and multiple messages for the same conflict
return result;
}
}
} else {
boolean alreadyExists = false;
// name
if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
} else if (rf.type instanceof TTCN3_Enumerated_Type) {
alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
} else if (rf.type instanceof ASN1_Choice_Type) {
alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Enumerated_Type) {
alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Sequence_Type) {
alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Set_Type) {
alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
}
if (alreadyExists) {
result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
}
}
return result;
}
use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return null;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
return null;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
return null;
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
return null;
}
break;
default:
return null;
}
if (values.hasNamedValueWithName(fieldId)) {
return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
if (!reference.getUsedInIsbound()) {
subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound set field `{0}''", fieldId.getDisplayName()));
}
// this is an error, that was already reported
return null;
}
final CompField compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result.getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
} else if (compField.hasDefault()) {
return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class ErroneousAttributes method buildErroneousDescriptorTree.
private ErroneousDescriptor buildErroneousDescriptorTree(final CompilationTimeStamp timestamp, final List<FieldErr_Type> fldArray, final int level) {
final ErroneousDescriptor erroneousDescr = new ErroneousDescriptor();
Qualifier omitBeforeQualifier = null;
Qualifier omitAfterQualifier = null;
final Map<Integer, List<FieldErr_Type>> embeddedFieldArrayMap = new HashMap<Integer, List<FieldErr_Type>>();
for (FieldErr_Type actualFieldErr : fldArray) {
if (actualFieldErr.subrefsArray.size() <= level) {
ErrorReporter.INTERNAL_ERROR();
return erroneousDescr;
}
final int fieldIndex = actualFieldErr.subrefsArray.get(level);
final IType fieldType = actualFieldErr.typeArray.get(level);
if (omitBeforeQualifier != null && erroneousDescr.omitBefore != -1 && erroneousDescr.omitBefore > fieldIndex) {
final String message = MessageFormat.format("Field `{0}'' cannot be referenced because all fields before field `{1}'' have been omitted", actualFieldErr.qualifier.getDisplayName(), omitBeforeQualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
if (omitAfterQualifier != null && erroneousDescr.omitAfter != -1 && erroneousDescr.omitAfter < fieldIndex) {
final String message = MessageFormat.format("Field `{0}'' cannot be referenced because all fields after field `{1}'' have been omitted", actualFieldErr.qualifier.getDisplayName(), omitAfterQualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
final Indicator_Type actIndicator = actualFieldErr.errAttrSpec.getIndicator();
final boolean isOmit = actualFieldErr.errAttrSpec.isOmit();
if (actualFieldErr.subrefsArray.size() == level + 1) {
// erroneous value
if (actualFieldErr.typeArray.size() != level + 1) {
ErrorReporter.INTERNAL_ERROR();
return erroneousDescr;
}
if (fieldType.getTypetype() == Type_type.TYPE_ASN1_SET && isOmit && actIndicator != Indicator_Type.Value_Indicator) {
final String message = MessageFormat.format("Cannot omit all fields {0} `{1}'' which is a field of an ASN.1 SET type. " + "The order of fields in ASN.1 SET types changes depending on tagging (see X.690 9.3). " + "Fields can be omitted individually, independently of the field order which depends on tagging", actIndicator.getDisplayName(), actualFieldErr.qualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
switch(fieldType.getTypetypeTtcn3()) {
case TYPE_TTCN3_CHOICE:
if (actIndicator != Indicator_Type.Value_Indicator) {
final String message = MessageFormat.format("Indicator `{0}'' cannot be used with reference `{1}'' which points to a field of a union type", actIndicator.getDisplayName(), actualFieldErr.qualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
break;
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
if (isOmit && actIndicator == Indicator_Type.After_Indicator) {
int lastFieldIndex;
switch(fieldType.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
lastFieldIndex = ((ASN1_Sequence_Type) fieldType).getNofComponents(timestamp) - 1;
break;
case TYPE_ASN1_SET:
lastFieldIndex = ((ASN1_Set_Type) fieldType).getNofComponents(timestamp) - 1;
break;
default:
lastFieldIndex = ((TTCN3_Set_Seq_Choice_BaseType) fieldType).getNofComponents() - 1;
}
if (fieldIndex == lastFieldIndex) {
final String message = MessageFormat.format("There is nothing to omit after the last field ({0}) of a record/set type", actualFieldErr.qualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
}
// $FALL-THROUGH$
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
if (isOmit && actIndicator == Indicator_Type.Before_Indicator && fieldIndex == 0) {
actualFieldErr.qualifier.getLocation().reportSemanticError(MessageFormat.format("There is nothing to omit before the first field ({0})", actualFieldErr.qualifier.getDisplayName()));
continue;
}
break;
default:
break;
}
// check for duplicate value+indicator
if (erroneousDescr.valuesMap.containsKey(fieldIndex)) {
final ErroneousValues evs = erroneousDescr.valuesMap.get(fieldIndex);
if ((evs.before != null && actIndicator == Indicator_Type.Before_Indicator) || (evs.value != null && actIndicator == Indicator_Type.Value_Indicator) || (evs.after != null && actIndicator == Indicator_Type.After_Indicator)) {
actualFieldErr.qualifier.getLocation().reportSemanticError(MessageFormat.format("Duplicate reference to field `{0}'' with indicator `{1}''", actualFieldErr.qualifier.getDisplayName(), actIndicator.getDisplayName()));
continue;
}
}
// values were used
if (actIndicator == Indicator_Type.Value_Indicator && embeddedFieldArrayMap.containsKey(fieldIndex)) {
final String message = MessageFormat.format("Reference to field `{0}'' with indicator `value'' would invalidate previously specified erroneous data", actualFieldErr.qualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
// duplication of omit before/after rule
if (actIndicator == Indicator_Type.Before_Indicator && isOmit) {
if (omitBeforeQualifier != null && erroneousDescr.omitBefore != -1) {
final String message = MessageFormat.format("Duplicate rule for omitting all fields before the specified field. " + "Used on field `{0}'' but previously already used on field `{1}''", actualFieldErr.qualifier.getDisplayName(), omitBeforeQualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
boolean isInvalid = false;
for (Integer idx : erroneousDescr.valuesMap.keySet()) {
if (idx < fieldIndex) {
isInvalid = true;
break;
}
}
if (!isInvalid) {
for (Integer idx : embeddedFieldArrayMap.keySet()) {
if (idx < fieldIndex) {
isInvalid = true;
break;
}
}
}
if (isInvalid) {
final String message = MessageFormat.format("Omitting fields before field `{0}'' would invalidate previously specified erroneous data", actualFieldErr.qualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
// save valid omit before data
omitBeforeQualifier = actualFieldErr.qualifier;
erroneousDescr.omitBefore = fieldIndex;
erroneousDescr.omitBeforeName = omitBeforeQualifier.getDisplayName();
continue;
}
if (actIndicator == Indicator_Type.After_Indicator && isOmit) {
if (omitAfterQualifier != null && erroneousDescr.omitAfter != -1) {
final String message = MessageFormat.format("Duplicate rule for omitting all fields after the specified field. " + "Used on field `{0}'' but previously already used on field `{1}''", actualFieldErr.qualifier.getDisplayName(), omitAfterQualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
boolean isInvalid = false;
for (Integer idx : erroneousDescr.valuesMap.keySet()) {
if (idx > fieldIndex) {
isInvalid = true;
break;
}
}
if (!isInvalid) {
for (Integer idx : embeddedFieldArrayMap.keySet()) {
if (idx > fieldIndex) {
isInvalid = true;
break;
}
}
}
if (isInvalid) {
final String message = MessageFormat.format("Omitting fields after field `{0}'' would invalidate previously specified erroneous data", actualFieldErr.qualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
// save valid omit after data
omitAfterQualifier = actualFieldErr.qualifier;
erroneousDescr.omitAfter = fieldIndex;
erroneousDescr.omitAfterName = omitAfterQualifier.getDisplayName();
continue;
}
// if not before/after omit then save this into
// values_m
final boolean hasKey = erroneousDescr.valuesMap.containsKey(fieldIndex);
final ErroneousValues evs = hasKey ? erroneousDescr.valuesMap.get(fieldIndex) : new ErroneousValues(actualFieldErr.qualifier.getDisplayName());
switch(actIndicator) {
case Before_Indicator:
evs.before = actualFieldErr.errAttrSpec;
break;
case Value_Indicator:
evs.value = actualFieldErr.errAttrSpec;
break;
case After_Indicator:
evs.after = actualFieldErr.errAttrSpec;
break;
default:
ErrorReporter.INTERNAL_ERROR();
}
if (!hasKey) {
erroneousDescr.valuesMap.put(fieldIndex, evs);
}
} else {
// embedded err.value
if (erroneousDescr.valuesMap.containsKey(fieldIndex) && erroneousDescr.valuesMap.get(fieldIndex).value != null) {
final String message = MessageFormat.format("Field `{0}'' is embedded into a field which was previously overwritten or omitted", actualFieldErr.qualifier.getDisplayName());
actualFieldErr.qualifier.getLocation().reportSemanticError(message);
continue;
}
// add the embedded field to the map
final boolean hasIndex = embeddedFieldArrayMap.containsKey(fieldIndex);
final List<FieldErr_Type> embeddedFieldArray = hasIndex ? embeddedFieldArrayMap.get(fieldIndex) : new ArrayList<FieldErr_Type>(1);
embeddedFieldArray.add(actualFieldErr);
if (!hasIndex) {
embeddedFieldArrayMap.put(fieldIndex, embeddedFieldArray);
}
}
}
// recursive calls to create embedded descriptors
for (Integer idx : embeddedFieldArrayMap.keySet()) {
erroneousDescr.descriptorMap.put(idx, buildErroneousDescriptorTree(timestamp, embeddedFieldArrayMap.get(idx), level + 1));
}
return erroneousDescr;
}
Aggregations