use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_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.TTCN3.types.TTCN3_Enumerated_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.types.TTCN3_Enumerated_Type in project titan.EclipsePlug-ins by eclipse.
the class LessThanOrEqualExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
if (value1 == null || value2 == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last1.getValuetype()) {
case INTEGER_VALUE:
{
lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) <= 0);
lastValue.copyGeneralProperties(this);
break;
}
case REAL_VALUE:
{
final double float1 = ((Real_Value) last1).getValue();
final double float2 = ((Real_Value) last2).getValue();
lastValue = new Boolean_Value(Double.compare(float1, float2) <= 0);
lastValue.copyGeneralProperties(this);
break;
}
case ENUMERATED_VALUE:
{
IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
governor1 = governor1.getTypeRefdLast(timestamp);
IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
governor2 = governor2.getTypeRefdLast(timestamp);
if (governor1 instanceof TTCN3_Enumerated_Type) {
final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() <= ((Integer_Value) item2.getValue()).intValue());
lastValue.copyGeneralProperties(this);
} else {
final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() <= ((Integer_Value) item2.getValue()).intValue());
lastValue.copyGeneralProperties(this);
}
break;
}
default:
setIsErroneous(true);
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type in project titan.EclipsePlug-ins by eclipse.
the class GreaterThanExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
if (value1 == null || value2 == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last1.getValuetype()) {
case INTEGER_VALUE:
{
lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) > 0);
lastValue.copyGeneralProperties(this);
break;
}
case REAL_VALUE:
{
final double float1 = ((Real_Value) last1).getValue();
final double float2 = ((Real_Value) last2).getValue();
lastValue = new Boolean_Value(Double.compare(float1, float2) > 0);
lastValue.copyGeneralProperties(this);
break;
}
case ENUMERATED_VALUE:
{
IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
governor1 = governor1.getTypeRefdLast(timestamp);
IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
governor2 = governor2.getTypeRefdLast(timestamp);
if (governor1 instanceof TTCN3_Enumerated_Type) {
final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() > ((Integer_Value) item2.getValue()).intValue());
lastValue.copyGeneralProperties(this);
} else {
final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() > ((Integer_Value) item2.getValue()).intValue());
lastValue.copyGeneralProperties(this);
}
break;
}
default:
setIsErroneous(true);
}
return lastValue;
}
Aggregations