use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method calculateEditLocations.
private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final MultiTextEdit rootEdit) throws CoreException {
final WorkspaceJob job = new WorkspaceJob("InsertFieldRefactoring: calculate edit locations") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
for (ILocateableNode node : nodes) {
int vmLen = settings.getType().length() + settings.getId().getTtcnName().length();
if (node instanceof Def_Type) {
Def_Type df = (Def_Type) node;
Type type = df.getType(CompilationTimeStamp.getBaseTimestamp());
if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
vmLen = insertField((TTCN3_Set_Seq_Choice_BaseType) type, node, rootEdit, vmLen);
}
} else if (node instanceof Sequence_Value) {
Sequence_Value sv = (Sequence_Value) node;
vmLen += 6;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < sv.getNofComponents()) {
final Location valueLocation = sv.getSeqValueByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = sv.getNofComponents();
final Location valueLocation = sv.getSeqValueByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getEndOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (node instanceof TTCN3Template) {
TTCN3Template template = (TTCN3Template) node;
vmLen += 6;
if (template instanceof Named_Template_List) {
Named_Template_List ntl = (Named_Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < ntl.getNofTemplates()) {
final Location templateLocation = ntl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = ntl.getNofTemplates();
final Location templateLocation = ntl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (template instanceof Template_List) {
Template_List tl = (Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < tl.getNofTemplates()) {
final Location templateLocation = tl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getValue() + ","));
} else {
int max = tl.getNofTemplates();
final Location templateLocation = tl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), "," + settings.getValue()));
}
}
}
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class Def_Type_Visit_Handler method handleDefTypeNodes.
public void handleDefTypeNodes(IVisitableNode node) {
Def_Type typeNode = (Def_Type) node;
CompilationTimeStamp compilationCounter = CompilationTimeStamp.getNewCompilationCounter();
myASTVisitor.currentFileName = typeNode.getIdentifier().toString();
Type type = typeNode.getType(compilationCounter);
if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {
// record
Def_Type_Record_Writer recordNode = new Def_Type_Record_Writer(typeNode);
// add component fields
recordNode.add(compFieldTypes, compFieldNames);
String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]);
String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]);
myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
compFieldTypes.clear();
compFieldNames.clear();
myASTVisitor.visualizeNodeToJava(recordNode.getJavaSource());
} else if (type.getTypetype().equals(TYPE_TTCN3_SET)) {
// set
Def_Type_Set_Writer setNode = new Def_Type_Set_Writer(typeNode);
// add component fields
setNode.add(compFieldTypes, compFieldNames);
String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]);
String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]);
myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
compFieldTypes.clear();
compFieldNames.clear();
myASTVisitor.visualizeNodeToJava(setNode.getJavaSource());
} else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) {
// union
Def_Type_Union_Writer union_writer = new Def_Type_Union_Writer(typeNode);
// add component fields
union_writer.add(compFieldTypes, compFieldNames);
String[] typeArray = compFieldTypes.toArray(new String[compFieldTypes.size()]);
String[] nameArray = compFieldNames.toArray(new String[compFieldNames.size()]);
myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
compFieldTypes.clear();
compFieldNames.clear();
myASTVisitor.visualizeNodeToJava(union_writer.getJavaSource());
} else if (type instanceof Integer_Type) {
Def_Type_Integer_Writer integerNode = Def_Type_Integer_Writer.getInstance(typeNode);
integerNode.clearLists();
myASTVisitor.visualizeNodeToJava(integerNode.getJavaSource());
} else if (type instanceof CharString_Type) {
Def_Type_Charstring_Writer charstringNode = Def_Type_Charstring_Writer.getInstance(typeNode);
charstringNode.clearLists();
charstringNode.addCharStringValue(charstringValue);
charstringValue = null;
myASTVisitor.visualizeNodeToJava(charstringNode.getJavaSource());
} else if (type instanceof TTCN3_Enumerated_Type) {
Def_Type_Enum_Writer enumTypeNode = Def_Type_Enum_Writer.getInstance(typeNode);
enumTypeNode.clearLists();
enumTypeNode.enumItems.addAll(enumItems);
enumTypeNode.enumItemValues.addAll(enumItemValues);
enumItemValues.clear();
enumItems.clear();
myASTVisitor.visualizeNodeToJava(enumTypeNode.getJavaSource());
} else if (type.getTypetype().equals(TYPE_SET_OF)) {
Def_Type_Set_Of_Writer setOfNode = new Def_Type_Set_Of_Writer(typeNode);
setOfNode.setFieldType(setOfFieldType);
setOfFieldType = null;
myASTVisitor.visualizeNodeToJava(setOfNode.getJavaSource());
} else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) {
Def_Type_Record_Of_Writer writer = new Def_Type_Record_Of_Writer(typeNode);
writer.setFieldType(recordOfFieldType);
myASTVisitor.visualizeNodeToJava(writer.getJavaSource());
} else if (type.getTypetype().equals(TYPE_PORT)) {
Def_Type_Port_Writer portNode = Def_Type_Port_Writer.getInstance(typeNode);
portNode.clearLists();
portNode.inMessageName.addAll(inMessageName);
portNode.outMessageName.addAll(outMessageName);
portNode.inOutMessageName.addAll(inOutMessageName);
portNode.setPortTypeAReferencedType(isPortTypeAReferencedType);
waitingForPortAttriburtes = false;
isPortTypeAReferencedType = false;
inMessageName.clear();
outMessageName.clear();
inOutMessageName.clear();
myASTVisitor.visualizeNodeToJava(portNode.getJavaSource());
} else if (type.getTypetype().equals(TYPE_COMPONENT)) {
Def_Type_Component_Writer compNode = Def_Type_Component_Writer.getInstance(typeNode);
compNode.clearLists();
// add component fields
compNode.compFieldPortTypes.addAll(componentPortTypes);
compNode.compFieldPortNames.addAll(componentPortNames);
compNode.compFieldVarTypes.addAll(componentVarTypes);
compNode.compFieldVarNames.addAll(componentVarNames);
componentPortTypes.clear();
componentPortNames.clear();
componentVarTypes.clear();
componentVarNames.clear();
waitForCompReference = false;
myASTVisitor.visualizeNodeToJava(compNode.getJavaSource());
}
parentName = null;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class Type method checkEncode.
/**
* Checks the encodings supported by the type (when using new codec handling).
* TTCN-3 types need to have an 'encode' attribute to support an encoding.
* ASN.1 types automatically support BER, PER and JSON encodings, and XER
* encoding, if set by the compiler option.
*/
public void checkEncode(final CompilationTimeStamp timestamp) {
switch(getTypeRefdLast(timestamp).getTypetypeTtcn3()) {
case TYPE_NULL:
case TYPE_BOOL:
case TYPE_INTEGER:
case TYPE_REAL:
case TYPE_TTCN3_ENUMERATED:
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_OBJECTID:
case TYPE_TTCN3_CHOICE:
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_VERDICT:
case TYPE_ARRAY:
case TYPE_ANYTYPE:
if (!isAsn()) {
final WithAttributesPath attributePath = getAttributePath();
if (attributePath != null) {
final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
if (multipleWithAttributes != null) {
for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
final Attribute_Modifier_type mod = singleWithAttribute.getModifier();
final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
}
final Reference reference = new Reference(null, fieldsOrArrays);
final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
if (type != null) {
if (type.getMyScope() != myScope) {
qualifier.getLocation().reportSemanticWarning("Encode attribute is ignored, because it refers to a type from a different type definition");
} else {
type.addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
}
}
}
} else {
addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
}
}
}
}
if (ownerType != TypeOwner_type.OT_TYPE_DEF) {
return;
}
WithAttributesPath globalAttributesPath;
final Def_Type def = (Def_Type) owner;
final Group nearest_group = def.getParentGroup();
if (nearest_group == null) {
// no group, use the module
Module myModule = myScope.getModuleScope();
globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
} else {
globalAttributesPath = nearest_group.getAttributePath();
}
if (globalAttributesPath != null) {
boolean hasGlobalOverride = false;
boolean modifierConflict = false;
Attribute_Modifier_type firstModifier = Attribute_Modifier_type.MOD_NONE;
final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
Attribute_Modifier_type modifier = singleWithAttribute.getModifier();
if (i == 0) {
firstModifier = modifier;
} else if (!modifierConflict && modifier != firstModifier) {
modifierConflict = true;
singleWithAttribute.getLocation().reportSemanticError("All 'encode' attributes of a group or module must have the same modifier ('override', '@local' or none)");
}
if (modifier == Attribute_Modifier_type.MOD_OVERRIDE) {
hasGlobalOverride = true;
}
if (hasGlobalOverride && modifierConflict) {
break;
}
}
}
// make a list of the type and its field and element types that inherit
// the global 'encode' attributes
// overriding global attributes are inherited by types with no coding
// table (no 'encode' attributes) of their own
// non-overriding global attributes are inherited by types that have
// no coding table of their own and cannot use the coding table of any
// other type
final ArrayList<IType> typeList = new ArrayList<IType>();
getTypesWithNoCodingTable(timestamp, typeList, hasGlobalOverride);
if (!typeList.isEmpty()) {
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
for (int j = typeList.size() - 1; j >= 0; j--) {
typeList.get(j).addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), Attribute_Modifier_type.MOD_NONE, true);
}
}
}
typeList.clear();
}
}
}
} else {
// ASN.1 types automatically have BER, PER, XER, OER and JSON encoding
switch(ownerType) {
case OT_TYPE_ASS:
case OT_RECORD_OF:
case OT_COMP_FIELD:
case OT_SELTYPE:
case OT_FIELDSETTING:
// FIXME implement once PER, JSON, OER or XER gets supported
break;
default:
break;
}
}
break;
default:
// the rest of the types can't have 'encode' attributes
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class ReadOnlyInOutPar method process.
@Override
public void process(final IVisitableNode node, final Problems problems) {
if (node instanceof FormalParameter) {
final FormalParameter s = (FormalParameter) node;
if (s.getMyParameterList().getMyDefinition() instanceof Def_Type) {
return;
}
if (!s.getWritten() && !(s.getMyParameterList().getMyDefinition() instanceof Def_Extfunction)) {
switch(s.getAssignmentType()) {
case A_PAR_VAL_INOUT:
case A_PAR_TEMP_INOUT:
final String msg = MessageFormat.format(READONLY, s.getDescription());
problems.report(s.getLocation(), msg);
break;
default:
break;
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class ReadOnlyOutPar method process.
@Override
public void process(final IVisitableNode node, final Problems problems) {
if (node instanceof FormalParameter) {
final FormalParameter s = (FormalParameter) node;
if (s.getMyParameterList().getMyDefinition() instanceof Def_Type) {
return;
}
if (!s.getWritten() && !(s.getMyParameterList().getMyDefinition() instanceof Def_Extfunction)) {
switch(s.getAssignmentType()) {
case A_PAR_VAL_OUT:
case A_PAR_TEMP_OUT:
final String msg = MessageFormat.format(READONLY, s.getDescription());
problems.report(s.getLocation(), msg);
break;
default:
break;
}
}
}
}
Aggregations