use of org.eclipse.titan.designer.AST.TTCN3.templates.Template_List 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.templates.Template_List in project titan.EclipsePlug-ins by eclipse.
the class ReplaceExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
Type_type tempType1 = null;
IValue value1 = null;
if (templateInstance1 != null) {
final ITTCN3Template temp = templateInstance1.getTemplateBody();
switch(temp.getTemplatetype()) {
case SPECIFIC_VALUE:
break;
case TEMPLATE_LIST:
case NAMED_TEMPLATE_LIST:
case INDEXED_TEMPLATE_LIST:
templateInstance1.getLocation().reportSemanticError(OPERANDERROR13);
setIsErroneous(true);
return;
default:
templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
setIsErroneous(true);
return;
}
// temp is specific value:
value1 = ((SpecificValue_Template) temp).getSpecificValue();
value1.setLoweridToReference(timestamp);
tempType1 = value1.getExpressionReturntype(timestamp, internalExpectation);
switch(tempType1) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_SET_OF:
case TYPE_SEQUENCE_OF:
value1.getValueRefdLast(timestamp, internalExpectation, referenceChain);
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
setIsErroneous(true);
break;
}
}
if (value2 != null) {
value2.setLoweridToReference(timestamp);
final Type_type tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
switch(tempType2) {
case TYPE_INTEGER:
final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last2.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last2.getValuetype())) {
if (((Integer_Value) last2).isNative()) {
final long i = ((Integer_Value) last2).getValue();
if (i < 0) {
value2.getLocation().reportSemanticError(OPERANDERROR3);
setIsErroneous(true);
}
} else {
value2.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR11, ((Integer_Value) last2).getValueValue()));
setIsErroneous(true);
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
value2.getLocation().reportSemanticError(OPERANDERROR1);
setIsErroneous(true);
break;
}
}
if (value3 != null) {
value3.setLoweridToReference(timestamp);
final Type_type tempType3 = value3.getExpressionReturntype(timestamp, expectedValue);
switch(tempType3) {
case TYPE_INTEGER:
final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last3.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last3.getValuetype())) {
if (((Integer_Value) last3).isNative()) {
final long i = ((Integer_Value) last3).getValue();
if (i < 0) {
value3.getLocation().reportSemanticError(OPERANDERROR4);
setIsErroneous(true);
}
} else {
value3.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR12, ((Integer_Value) last3).getValueValue()));
setIsErroneous(true);
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
value3.getLocation().reportSemanticError(OPERANDERROR2);
setIsErroneous(true);
break;
}
}
Type_type tempType4 = null;
IValue value4 = null;
if (templateInstance4 != null) {
final ITTCN3Template temp = templateInstance4.getTemplateBody();
switch(temp.getTemplatetype()) {
case SPECIFIC_VALUE:
value4 = ((SpecificValue_Template) temp).getSpecificValue();
break;
case TEMPLATE_LIST:
if (!((Template_List) temp).isValue(timestamp)) {
templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
setIsErroneous(true);
return;
}
case NAMED_TEMPLATE_LIST:
case INDEXED_TEMPLATE_LIST:
tempType4 = templateInstance4.getExpressionReturntype(timestamp, expectedValue);
if (Type_type.TYPE_UNDEFINED.equals(tempType4)) {
templateInstance4.getLocation().reportSemanticError(OPERANDERROR13);
}
return;
default:
templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
setIsErroneous(true);
return;
}
value4.setLoweridToReference(timestamp);
tempType4 = value4.getExpressionReturntype(timestamp, internalExpectation);
switch(tempType4) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_SET_OF:
case TYPE_SEQUENCE_OF:
value4.getValueRefdLast(timestamp, internalExpectation, referenceChain);
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(OPERANDERROR6);
setIsErroneous(true);
break;
}
}
if (tempType1 != null && tempType4 != null && !tempType1.equals(tempType4) && !getIsErroneous(timestamp)) {
location.reportSemanticError(OPERANDERROR7);
setIsErroneous(true);
}
checkExpressionOperandsHelper(timestamp, value1, expectedValue, referenceChain);
}
Aggregations