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;
}
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);
}
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());
}
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);
}
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);
}
Aggregations