use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class TestCase_Function_Visit_Handler method leave.
public void leave(IVisitableNode node) {
if (waitForTC || waitForFunction) {
if (node instanceof Definition_Statement) {
if (!waitForRecord) {
nodeVarIsRecord.add(false);
}
waitForRecord = false;
waitForValue = false;
evaluateExpression();
}
if (node instanceof Undefined_LowerIdentifier_Value) {
blockReferenceListing = false;
}
if ((node instanceof Assignment_Statement) || ((node instanceof If_Clause))) {
waitForValue = false;
// if assignment is a createExpression
if (node instanceof Assignment_Statement) {
if (((Assignment_Statement) node).getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) ((Assignment_Statement) node).getTemplate();
if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
isCreate = true;
}
}
}
evaluateExpression();
}
if (node instanceof SequenceOf_Value) {
evaluateExpression();
}
if ((waitForFunction && (node instanceof Return_Statement)) || (waitForTC && (node instanceof ComponentCreateExpression)) || (node instanceof Send_Statement) || (node instanceof Receive_Port_Statement)) {
evaluateExpression();
}
if (waitForTcStartValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
myASTVisitor.blockIdListing = false;
}
if (waitForTcStopValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
myASTVisitor.blockIdListing = false;
}
if (node instanceof Connect_Statement) {
waitForTcConnectValues = false;
}
if (node instanceof Disconnect_Statement) {
waitForTcDisconnectValues = false;
}
if (node instanceof Unknown_Start_Statement) {
waitForTcStartValues = false;
}
if (node instanceof Unknown_Stop_Statement) {
waitForTcStopValues = false;
}
if (node instanceof Definition_Statement) {
waitForDefStatement = false;
if (waitForValue) {
nodeVarValues.add(null);
nodeVarIsAValueReference.add(false);
waitForValue = false;
}
}
if (node instanceof Map_Statement) {
waitForMapIdentifiers = false;
}
if (node instanceof ComponentCreateExpression) {
// switch first two values
testCaseCreateValues.add(testCaseCreateCharValues.get(0));
testCaseCreateValues.add(testCaseCreateRefValues.get(0));
for (int i = 1; i < testCaseCreateCharValues.size(); i++) {
testCaseCreateValues.add(testCaseCreateCharValues.get(i));
}
testCaseCreateCharValues.clear();
testCaseCreateRefValues.clear();
waitForTcCreateValues = false;
}
if (node instanceof Assignment_Statement) {
waitForAssignmentIdentifiers = false;
waitForValue = true;
}
if (waitForTcIfCondition && (node instanceof If_Clause)) {
waitForTcIfCondition = false;
}
if (waitForTcStartParameter && (node instanceof Unknown_Start_Statement)) {
testCaseStartValueParameters.add(null);
}
if (waitForTcStopParameter && (node instanceof Unknown_Stop_Statement)) {
testCaseStopValueParameters.add(null);
}
if (isAltGuards && (node instanceof Operation_Altguard)) {
altGuardConditions.add(null);
}
if (node instanceof Operation_Altguard) {
waitForAltStatements = false;
isAltGuards = false;
isReceiveValue = false;
}
handleAltCases(node);
if (node instanceof Unknown_Start_Statement) {
waitForUnknownStartStatement = false;
}
if (node instanceof Unknown_Stop_Statement) {
waitForUnknownStopStatement = false;
}
if (node instanceof Receive_Port_Statement) {
if (waitForReceiveParameter) {
altGuardReceiveType.add("noparam");
}
// TODO checkAnyport = true;
}
}
if (node instanceof Def_Testcase) {
handleTestcase(node);
waitForTC = false;
}
if (node instanceof Def_Function) {
handleFunction(node);
waitForTC = false;
}
if (waitForAssignmentIdentifiers && (node instanceof ArraySubReference)) {
waitForAssignmentIdentifiers = false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class Def_Function_Writer method writeFunction.
public void writeFunction(StatementBlock statementBlock) {
for (int i = 0; i < statementBlock.getSize(); i++) {
if (statementBlock.getStatementByIndex(i) instanceof Definition_Statement) {
writeDefinitionStatement((Definition_Statement) statementBlock.getStatementByIndex(i));
} else if (statementBlock.getStatementByIndex(i) instanceof Assignment_Statement) {
assignCounter++;
functionString.append(writeAssignmentStatement((Assignment_Statement) statementBlock.getStatementByIndex(i)));
} else if (statementBlock.getStatementByIndex(i) instanceof Assignment_Statement) {
Assignment_Statement tc_assignStatement = (Assignment_Statement) statementBlock.getStatementByIndex(i);
assignCounter++;
functionString.append(writeAssignmentStatement(tc_assignStatement));
} else if (statementBlock.getStatementByIndex(i) instanceof Send_Statement) {
sendCounter++;
functionString.append(writeSendStatement((Send_Statement) statementBlock.getStatementByIndex(i)));
} else if (statementBlock.getStatementByIndex(i) instanceof Unknown_Start_Statement) {
startCounter++;
writeUnknownStartStatement((Unknown_Start_Statement) statementBlock.getStatementByIndex(i));
} else if (statementBlock.getStatementByIndex(i) instanceof Alt_Statement) {
altStatementCounter++;
altStatements.get(altStatementCounter).setTimerInfo(isThereAStartedTimer, currentTimerName);
functionString.append(altStatements.get(altStatementCounter).getJavaSource());
} else if (statementBlock.getStatementByIndex(i) instanceof Setverdict_Statement) {
writeSetVerdictStatement((Setverdict_Statement) statementBlock.getStatementByIndex(i));
} else if (statementBlock.getStatementByIndex(i) instanceof DoWhile_Statement) {
doWhileCounter++;
DoWhile_Statement doWhileStatement = (DoWhile_Statement) statementBlock.getStatementByIndex(i);
String test = doWhileStatement.getExpression().toString();
functionString.append("do{" + "\r\n");
this.writeFunction(doWhileStatement.getStatementBlock());
functionString.append("}while(" + doWhileExpressions.get(doWhileCounter) + ".getValue());\r\n");
}
}
if (returnStatementValue != null) {
functionString.append("return " + returnStatementValue + ";\r\n");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class StatementBlock method updateSyntax.
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (!isDamaged) {
// handle the simple case quickly
for (int i = 0, size = statements.size(); i < size; i++) {
final Statement statement = statements.get(i);
statement.updateSyntax(reparser, false);
reparser.updateLocation(statement.getLocation());
}
return;
}
returnStatus = null;
lastTimeChecked = null;
boolean enveloped = false;
int nofDamaged = 0;
int leftBoundary = location.getOffset();
int rightBoundary = location.getEndOffset();
final int damageOffset = reparser.getDamageStart();
IAppendableSyntax lastAppendableBeforeChange = null;
IAppendableSyntax lastPrependableBeforeChange = null;
for (int i = 0, size = statements.size(); i < size && !enveloped; i++) {
final Statement statement = statements.get(i);
final Location temporalLocation = statement.getLocation();
Location cumulativeLocation;
if (statement instanceof Definition_Statement) {
cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
} else {
cumulativeLocation = temporalLocation;
}
if (temporalLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
enveloped = true;
leftBoundary = cumulativeLocation.getOffset();
rightBoundary = cumulativeLocation.getEndOffset();
} else if (reparser.isDamaged(cumulativeLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
lastAppendableBeforeChange = statement;
} else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
lastPrependableBeforeChange = statement;
}
} else {
if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = cumulativeLocation.getEndOffset();
lastAppendableBeforeChange = statement;
}
if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
rightBoundary = cumulativeLocation.getOffset();
lastPrependableBeforeChange = statement;
}
}
}
// was not enveloped
if (!enveloped) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
// extension might be correct
if (lastAppendableBeforeChange != null) {
final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
if (isBeingExtended) {
leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (lastPrependableBeforeChange != null) {
final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
if (temp != null && reparser.endsWithToken(temp)) {
rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (nofDamaged != 0) {
removeStuffInRange(reparser);
}
for (final Iterator<Statement> iterator = statements.iterator(); iterator.hasNext(); ) {
final Statement statement = iterator.next();
final Location temporalLocation = statement.getLocation();
Location cumulativeLocation;
if (statement instanceof Definition_Statement) {
cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
} else {
cumulativeLocation = temporalLocation;
}
if (reparser.isAffectedAppended(cumulativeLocation)) {
try {
statement.updateSyntax(reparser, enveloped && reparser.envelopsDamage(cumulativeLocation));
reparser.updateLocation(statement.getLocation());
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
iterator.remove();
reparser.extendDamagedRegion(cumulativeLocation);
} else {
e.decreaseDepth();
throw e;
}
}
}
}
if (!enveloped) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
final int result = reparse(reparser);
if (result > 1) {
throw new ReParseException(result - 1);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method calculateMultiDeclarationMoveContent.
/**
* Returns the content of an {@InsertEdit} to move a variable from a declaration list
*/
private String calculateMultiDeclarationMoveContent(final String fileContent, final StatementNode declStNode) {
final MultiDeclaration md = declStNode.getMultiDeclaration();
final StatementNode firstDeclPart = md.getFirstStatement();
final Definition firstDefInStmt = firstDeclPart.getDeclaredVar().getDefinition();
final Definition defVarToMove = declStNode.getDeclaredVar().getDefinition();
final Definition_Statement declStmt = (Definition_Statement) declStNode.getAstNode();
final Location declStmtLoc = declStmt.getLocation();
final String stmtContent = fileContent.substring(declStmtLoc.getOffset(), declStmtLoc.getEndOffset());
if (!stmtContent.contains(",")) {
ErrorReporter.logError("ChangeCreator.calculateMultiDeclarationMoveContent(): Given statement" + " is not a multi-declaration statement; loc: " + declStmtLoc.getOffset() + "-" + declStmtLoc.getEndOffset() + " in file " + declStmtLoc.getFile());
return null;
}
int prefixOffset;
int prefixEndOffset;
if (firstDefInStmt.equals(defVarToMove)) {
// first var to move
prefixOffset = findLineBeginningOffset(fileContent, declStmtLoc.getOffset());
prefixEndOffset = declStmtLoc.getOffset();
} else {
// not first var to move
prefixOffset = findLineBeginningOffset(fileContent, declStmtLoc.getOffset());
prefixEndOffset = firstDefInStmt.getIdentifier().getLocation().getOffset();
}
String prefixContent = fileContent.substring(prefixOffset, prefixEndOffset);
//
final int varOffset = defVarToMove.getLocation().getOffset();
final int varEndOffset = defVarToMove.getLocation().getEndOffset();
String varContent = fileContent.substring(varOffset, varEndOffset);
String suffixContent = "\n";
if (varContent.charAt(varContent.length() - 1) != ';') {
suffixContent = ";" + suffixContent;
}
// remove newlines from varContent
prefixContent = prefixContent.replaceAll("[\n\r]", " ");
varContent = varContent.replaceAll("[\n\r]", " ");
// System.err.println("mdcopyloc -->>>" + prefixContent + "<>" + varContent + "<>" + suffixContent + "<<<");
return prefixContent + varContent + suffixContent;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method calculateMultiDeclarationCutLoc.
/**
* Returns the {@link Location} of the {@DeleteEdit} to remove a variable from a declaration list
*/
private Location calculateMultiDeclarationCutLoc(final String fileContent, final StatementNode declStNode) {
/*
* rules for removing multideclaration parts:
* if part is only one left: remove statement
* if part is first: remove trailing comma
* if part is last: remove leading comma
* if part is intermediate: remove trailing comma
* */
final MultiDeclaration md = declStNode.getMultiDeclaration();
final StatementNode firstDeclPart = md.getFirstStatement();
final Definition defVarToMove = declStNode.getDeclaredVar().getDefinition();
final Definition_Statement declStmt = (Definition_Statement) declStNode.getAstNode();
final boolean firstDefInMdMoved = firstDeclPart.isMoved();
final Location declStmtLoc = declStmt.getLocation();
final String stmtContent = fileContent.substring(declStmtLoc.getOffset(), declStmtLoc.getEndOffset());
if (!stmtContent.contains(",")) {
ErrorReporter.logError("ChangeCreator.calculateMultiDeclarationCutLoc(): Given statement" + " is not a multi-declaration statement; loc: " + declStmtLoc.getOffset() + "-" + declStmtLoc.getEndOffset() + " in file " + declStmtLoc.getFile());
return null;
}
//
if (md.getSize() <= 1) {
final Location cutLoc = findStatementLocation(fileContent, declStmt.getLocation(), true);
// System.err.println("mdcutloc <= 1 -->>>" + fileContent.substring(cutLoc.getOffset(), cutLoc.getEndOffset()) + "<<<");
return cutLoc;
}
//
int cutOffset = defVarToMove.getLocation().getOffset();
int cutEndOffset = defVarToMove.getLocation().getEndOffset();
if (md.isFirstStatement(declStNode)) {
// fist var
if (!md.isAllStatementsMoved()) {
cutOffset = defVarToMove.getIdentifier().getLocation().getOffset();
}
cutEndOffset = calculateEndOffsetIncludingTrailingComma(fileContent, cutEndOffset, declStmtLoc.getEndOffset());
} else if (md.isLastStatement(declStNode)) {
// last var
cutOffset = calculateOffsetIncludingLeadingComma(fileContent, cutOffset, declStmtLoc.getOffset());
} else {
// intermediate var
cutEndOffset = calculateEndOffsetIncludingTrailingComma(fileContent, cutEndOffset, declStmtLoc.getEndOffset());
}
// System.err.println("mdcutloc -->>>" + fileContent.substring(cutOffset, cutEndOffset) + "<<<");
return new Location(declStmtLoc.getFile(), declStmtLoc.getLine(), cutOffset, cutEndOffset);
}
Aggregations