Search in sources :

Example 1 with Definition_Statement

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;
    }
}
Also used : Connect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement) Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ComponentCreateExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Identifier(org.eclipse.titan.designer.AST.Identifier) Unknown_Stop_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement) Return_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Disconnect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement) Unknown_Start_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement) Map_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 2 with Definition_Statement

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");
    }
}
Also used : Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Unknown_Start_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Example 3 with Definition_Statement

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);
        }
    }
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 4 with Definition_Statement

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;
}
Also used : Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) MultiDeclaration(org.eclipse.titanium.refactoring.scope.nodes.MultiDeclaration) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) StatementNode(org.eclipse.titanium.refactoring.scope.nodes.StatementNode) Location(org.eclipse.titan.designer.AST.Location)

Example 5 with Definition_Statement

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);
}
Also used : Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) MultiDeclaration(org.eclipse.titanium.refactoring.scope.nodes.MultiDeclaration) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) StatementNode(org.eclipse.titanium.refactoring.scope.nodes.StatementNode) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Definition_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement)5 Location (org.eclipse.titan.designer.AST.Location)3 Assignment_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement)3 Send_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement)3 Unknown_Start_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement)3 Def_Timer (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer)2 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)2 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)2 Connect_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement)2 Disconnect_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement)2 DoWhile_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement)2 Map_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement)2 Receive_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement)2 Setverdict_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)2 Unknown_Stop_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement)2 MultiDeclaration (org.eclipse.titanium.refactoring.scope.nodes.MultiDeclaration)2 StatementNode (org.eclipse.titanium.refactoring.scope.nodes.StatementNode)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)1