Search in sources :

Example 36 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.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 37 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.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)

Example 38 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createTextEdit.

private TextEdit createTextEdit(final Log_Statement toEdit, final Context toAdd) {
    // get insert location
    final LogInsertLocationFinder vis = new LogInsertLocationFinder();
    toEdit.accept(vis);
    int insertOffset = vis.calculateEndOffset();
    if (insertOffset < 0) {
        ErrorReporter.logError("ChangeCreator.createTextEdit(): Warning! No arguments in log statement! ");
        insertOffset = toEdit.getLocation().getEndOffset() - 1;
    }
    // find variable names that are already present in the log statement
    final Set<String> varsAlreadyPresent;
    final Context bottomContext = toAdd.getBottom();
    if (bottomContext.getNode() instanceof Log_Statement) {
        final LoggedVariableFinder vis2 = new LoggedVariableFinder();
        final Log_Statement logst = (Log_Statement) bottomContext.getNode();
        logst.accept(vis2);
        varsAlreadyPresent = vis2.getVarsAlreadyPresent();
    } else {
        varsAlreadyPresent = new HashSet<String>();
    }
    // create inserted text
    toAdd.process();
    final List<String> contextInfos = toAdd.createLogParts(varsAlreadyPresent);
    final int len = Math.min(contextInfos.size(), toAdd.getVarCountLimitOption());
    if (len == 0) {
        return null;
    }
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < len; i++) {
        sb.append(contextInfos.get(i));
    }
    // create edit from location and text
    return new InsertEdit(insertOffset, sb.toString());
}
Also used : Context(org.eclipse.titanium.refactoring.logging.context.Context) InsertEdit(org.eclipse.text.edits.InsertEdit) Log_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement)

Example 39 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class MatchExpression 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) {
    if (value == null || templateInstance == null) {
        setIsErroneous(true);
        return;
    }
    if (value.getIsErroneous(timestamp) || templateInstance.getTemplateBody().getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    // Start
    IType localGovernor = value.getExpressionGovernor(timestamp, expectedValue);
    if (localGovernor == null) {
        localGovernor = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (localGovernor == null) {
        template = template.setLoweridToReference(timestamp);
        localGovernor = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (localGovernor == null) {
        // Start again:
        value.setLoweridToReference(timestamp);
        localGovernor = value.getExpressionGovernor(timestamp, expectedValue);
    }
    if (localGovernor == null) {
        if (!template.getIsErroneous(timestamp)) {
            getLocation().reportSemanticError("Cannot determine the type of arguments in `match()' operation");
        }
        setIsErroneous(true);
        return;
    }
    value.setMyGovernor(localGovernor);
    final IValue temporalValue = localGovernor.checkThisValueRef(timestamp, value);
    localGovernor.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
    // FIXME check value against governor
    template.checkThisTemplateGeneric(timestamp, localGovernor, templateInstance.getDerivedReference() != null, false, false, true, false, null);
    try {
        ExpressionUtilities.checkExpressionOperatorCompatibility(timestamp, this, referenceChain, Expected_Value_type.EXPECTED_TEMPLATE, value, templateInstance);
    } catch (StackOverflowError e) {
        ErrorReporter.logExceptionStackTrace("Stack overflow was detected while analysing `" + getFullName() + "'", e.getCause());
        getLocation().reportSemanticError("Titan was unable to analyse this statement");
        setIsErroneous(true);
    }
    if (getIsErroneous(timestamp)) {
        return;
    }
    value.getValueRefdLast(timestamp, expectedValue, referenceChain);
    templateInstance.getTemplateBody().getTemplateReferencedLast(timestamp, referenceChain);
    templateInstance.check(timestamp, localGovernor);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 40 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class Shorthand method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Timeout_Statement) {
        typename = NAME_TIMEOUT;
    } else if (node instanceof Receive_Port_Statement) {
        typename = NAME_RECEIVE;
    } else if (node instanceof Trigger_Port_Statement) {
        typename = NAME_TRIGGER;
    } else if (node instanceof Getcall_Statement) {
        typename = NAME_GETCALL;
    } else if (node instanceof Catch_Statement) {
        typename = NAME_CATCH;
    } else if (node instanceof Check_Port_Statement) {
        typename = NAME_CHECK;
    } else if (node instanceof Check_Receive_Port_Statement) {
        typename = NAME_CHECK_RECEIVE;
    } else if (node instanceof Check_Getcall_Statement) {
        typename = NAME_CHECK_GETCALL;
    } else if (node instanceof Check_Catch_Statement) {
        typename = NAME_CHECK_CATCH;
    } else if (node instanceof Check_Getreply_Statement) {
        typename = NAME_CHECK_GETREPLY;
    } else if (node instanceof Getreply_Statement) {
        typename = NAME_GETREPLY;
    } else if (node instanceof Done_Statement) {
        typename = NAME_DONE;
    } else if (node instanceof Killed_Statement) {
        typename = NAME_KILLED;
    } else {
        return;
    }
    final Statement s = (Statement) node;
    check(s, problems);
}
Also used : Done_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement) Check_Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getcall_Statement) Killed_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Killed_Statement) Call_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Call_Statement) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Check_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Port_Statement) Check_Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Catch_Statement) Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement) Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getreply_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) Check_Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getreply_Statement) Trigger_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Trigger_Port_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getcall_Statement) Killed_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Killed_Statement) Done_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement) Check_Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Receive_Port_Statement) Check_Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getcall_Statement) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Check_Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Receive_Port_Statement) Check_Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Catch_Statement) Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement) Trigger_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Trigger_Port_Statement) Check_Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Catch_Statement) Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getcall_Statement) Check_Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getcall_Statement) Check_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Port_Statement) Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getreply_Statement) Check_Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getreply_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) Check_Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getreply_Statement) Check_Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Receive_Port_Statement)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)13 Assignment (org.eclipse.titan.designer.AST.Assignment)11 IValue (org.eclipse.titan.designer.AST.IValue)11 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)11 Reference (org.eclipse.titan.designer.AST.Reference)10 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)7 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Location (org.eclipse.titan.designer.AST.Location)6 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Module (org.eclipse.titan.designer.AST.Module)5 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)4 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)4 Receive_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement)4 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)4 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)4 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3