use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class ContentAssistProcessor method computeCompletionProposals.
// FIXME add semantic check guard on project level.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
if (editor == null) {
return new ICompletionProposal[] {};
}
IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
return new ICompletionProposal[] {};
}
IDocument doc = viewer.getDocument();
TTCN3ReferenceParser refParser = new TTCN3ReferenceParser(true);
Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
if (ref == null || ref.getSubreferences().isEmpty()) {
return new ICompletionProposal[] {};
}
Scope scope = null;
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
Module tempModule = projectSourceParser.containedModule(file);
String moduleName = null;
if (tempModule != null) {
moduleName = tempModule.getName();
scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
ref.setMyScope(scope);
ref.detectModid();
}
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
TITANDebugConsole.println("parsed the reference: " + ref);
}
TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
propCollector.setProjectParser(projectSourceParser);
if (moduleName == null) {
// rootless behavior
if (ref.getModuleIdentifier() == null) {
Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
Module module;
for (String name : moduleNames) {
module = projectSourceParser.getModuleByName(name);
if (module != null) {
propCollector.addProposal(name, name, ImageCache.getImage("ttcn.gif"), TTCN3Module.MODULE);
module.getAssignments().addProposal(propCollector);
}
}
} else {
Module module = projectSourceParser.getModuleByName(ref.getModuleIdentifier().getName());
if (module != null) {
module.getAssignments().addProposal(propCollector);
}
}
} else {
/*
* search for the best scope in the module's scope
* hierarchy and call proposal adding function on the
* found scope instead of what can be found here
*/
if (scope != null) {
scope.addProposal(propCollector);
}
}
propCollector.sortTillMarked();
propCollector.markPosition();
if (ref.getSubreferences().size() != 1) {
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
for (String knownModuleName : knownModuleNames) {
Identifier tempIdentifier = new Identifier(Identifier_type.ID_NAME, knownModuleName);
Module tempModule2 = projectSourceParser.getModuleByName(knownModuleName);
propCollector.addProposal(tempIdentifier, ImageCache.getImage(tempModule2.getOutlineIcon()), "module");
}
propCollector.sortTillMarked();
propCollector.markPosition();
if (ref.getModuleIdentifier() == null) {
if (scope == null) {
TTCN3CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
} else {
scope.addSkeletonProposal(propCollector);
}
propCollector.addTemplateProposal("refers", new Template("refers( function/altstep/testcase name )", "", propCollector.getContextIdentifier(), "refers( ${fatName} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("derefers", new Template("derefers( function/altstep/testcase name )(parameters)", "", propCollector.getContextIdentifier(), "derefers( ${fatName} ) ( ${parameters} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.sortTillMarked();
propCollector.markPosition();
TTCN3CodeSkeletons.addPredefinedSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
if (scope == null) {
TTCN3Keywords.addKeywordProposals(propCollector);
} else {
scope.addKeywordProposal(propCollector);
}
propCollector.sortTillMarked();
propCollector.markPosition();
} else {
if (scope == null || !(scope instanceof StatementBlock)) {
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
String fakeModule = ref.getModuleIdentifier().getName();
if ("any component".equals(fakeModule) || "all component".equals(fakeModule)) {
Component_Type.addAnyorAllProposal(propCollector, 0);
} else if ("any port".equals(fakeModule) || "all port".equals(fakeModule)) {
PortTypeBody.addAnyorAllProposal(propCollector, 0);
} else if ("any timer".equals(fakeModule) || "all timer".equals(fakeModule)) {
Timer.addAnyorAllProposal(propCollector, 0);
}
}
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST method run.
@Override
public void run(IAction action) {
if (targetEditor == null)
return;
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
Module module = parser.containedModule(file);
if (module == null) {
TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
}
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
}
} else if (node instanceof ComponentTypeBody) {
ComponentTypeBody body = (ComponentTypeBody) node;
Map<String, Definition> map = body.getDefinitionMap();
printInfoln(padding + 1, " contains definitions:");
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
}
}
if (node instanceof StatementBlock || node instanceof Definition) {
padding++;
}
return super.visit(node);
}
@Override
public int leave(IVisitableNode node) {
if (node instanceof StatementBlock || node instanceof Definition) {
padding--;
}
return super.leave(node);
}
});
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class DoWhile_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
isInfiniteLoop = false;
if (statementblock != null) {
statementblock.setMyLaicStmt(null, this);
statementblock.check(timestamp);
}
if (expression != null) {
final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (!last.getIsErroneous(timestamp)) {
if (!Type_type.TYPE_BOOL.equals(temporalType)) {
last.getLocation().reportSemanticError(BOOLEANEXPECTED);
expression.setIsErroneous(true);
} else if (!expression.isUnfoldable(timestamp)) {
if (!((Boolean_Value) last).getValue()) {
final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null);
expression.getLocation().reportConfigurableSemanticProblem(severity, UNNECESSARYCONTROL);
} else if (ReturnStatus_type.RS_NO.equals(hasReturn(timestamp))) {
isInfiniteLoop = true;
final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINFINITELOOPS, GeneralConstants.WARNING, null);
location.reportConfigurableSemanticProblem(severity, INFINITELOOP);
}
}
if (expression.getMyGovernor() == null) {
expression.setMyGovernor(new Boolean_Type());
}
}
}
lastTimeChecked = timestamp;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class If_Clause method check.
/**
* Does the semantic checking of this branch.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param unreachable
* boolean parameter telling if this if statement was
* already found unreachable by previous clauses or not
*
* @return true if following clauses are unreachable
*/
public boolean check(final CompilationTimeStamp timestamp, final boolean unreachable) {
if (unreachable) {
location.reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), NEVERREACH1);
}
boolean unreachable2 = unreachable;
if (expression != null) {
final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_UNDEFINED.equals(temporalType)) {
if (!Type_type.TYPE_BOOL.equals(temporalType)) {
last.getLocation().reportSemanticError(BOOLEANEXPECTED);
expression.setIsErroneous(true);
} else if (!expression.isUnfoldable(timestamp)) {
if (((Boolean_Value) last).getValue()) {
expression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), UNNECESSARYCONTROL1);
unreachable2 = true;
} else {
expression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), UNNECESSARYCONTROL2);
statementblock.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), NEVERREACH2);
}
}
if (expression.getMyGovernor() == null) {
expression.setMyGovernor(new Boolean_Type());
}
}
}
if (statementblock != null) {
statementblock.check(timestamp);
}
return unreachable2;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Altguard method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
if (expression != null) {
final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_BOOL.equals(temporalType)) {
last.getLocation().reportSemanticError(BOOLEANEXPECTED);
expression.setIsErroneous(true);
}
if (expression.getMyGovernor() == null) {
expression.setMyGovernor(new Boolean_Type());
}
}
IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type == null) {
lastTimeChecked = timestamp;
return;
}
type = type.getTypeRefdLast(timestamp);
if (type == null || type.getIsErroneous(timestamp)) {
lastTimeChecked = timestamp;
return;
}
if (!Type_type.TYPE_ALTSTEP.equals(type.getTypetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("A value of type altstep was expected instead of `{0}''", type.getTypename()));
lastTimeChecked = timestamp;
return;
}
value.getMyScope().checkRunsOnScope(timestamp, type, this, "call");
final FormalParameterList formalParmaterList = ((Altstep_Type) type).getFormalParameters();
actualParameterList = new ActualParameterList();
formalParmaterList.checkActualParameterList(timestamp, parsedParameters, actualParameterList);
if (statementblock != null) {
statementblock.check(timestamp);
}
lastTimeChecked = timestamp;
}
Aggregations