use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createFileChange.
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null) {
return null;
}
if (selection instanceof Def_Type) {
final Def_Type df = (Def_Type) selection;
type = df.getType(CompilationTimeStamp.getBaseTimestamp());
}
final DefinitionVisitor vis = new DefinitionVisitor(type);
module.accept(vis);
final NavigableSet<ILocateableNode> nodes = vis.getLocations();
if (nodes.isEmpty()) {
return null;
}
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
try {
final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, rootEdit);
job1.join();
} catch (InterruptedException ie) {
ErrorReporter.logExceptionStackTrace(ie);
} catch (CoreException ce) {
ErrorReporter.logError("InsertFieldRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
ErrorReporter.logExceptionStackTrace(ce);
}
if (!rootEdit.hasChildren()) {
return null;
}
tfc.setEdit(rootEdit);
return tfc;
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ExtractToFunctionRefactoring method createFunction.
public WorkspaceJob createFunction() {
final WorkspaceJob job = new WorkspaceJob("ExtractToFunction: creating new function text") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
final StatementList selectedStatements = selectionFinder.getSelectedStatements();
final Module selectedModule = getSelectedModule();
final IFile selectedFile = getSelectedFile();
final Reference runsOnRef = selectionFinder.getRunsOnRef();
final Type returnType = selectionFinder.getReturnType();
final ReturnCertainty retCertainty = selectionFinder.getReturnCertainty();
parentFunc = selectionFinder.getParentFunc();
if (parentFunc == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not find the enclosing function of the selection! ");
return Status.CANCEL_STATUS;
}
if (selectionFinder.getInsertLoc() < 0) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not calculate the insert location! ");
return Status.CANCEL_STATUS;
}
if (selectedStatements == null || selectedStatements.isEmpty() || selectedModule == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): No or invalid selection! ");
return Status.CANCEL_STATUS;
}
// collect params and find runs on clause
paramCollector = new ParamCollector(project, selectedStatements, selectedModule);
paramCollector.perform();
List<Param> params = paramCollector.getParams();
//
if (params == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to collect params! ");
return Status.CANCEL_STATUS;
}
// create new function text
functionCreator = new FunctionCreator(selectedStatements, selectedFile, newFuncName, params, runsOnRef, returnType, retCertainty);
functionCreator.perform();
functionText = functionCreator.getFunctionText();
if (functionText == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function text! ");
return Status.CANCEL_STATUS;
}
functionCallText = functionCreator.getFunctionCallText();
if (functionCallText == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function call text! ");
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ExtractToFunctionWizardFuncNamePage method checkNewNameValidity.
private boolean checkNewNameValidity() {
final String newName = newFuncName.getText();
if (newName.length() == 0) {
setErrorMessage(null);
setPageComplete(false);
return false;
}
final Module mod = ((ExtractToFunctionRefactoring) getRefactoring()).getSelectedModule();
switch(mod.getModuletype()) {
case TTCN3_MODULE:
if (!Identifier.isValidInTtcn(newName)) {
setErrorMessage("Not a valid TTCN-3 identifier!");
setPageComplete(false);
return false;
}
break;
case ASN_MODULE:
if (!Identifier.isValidInAsn(newName)) {
setErrorMessage("Not a valid ASN.1 identifier!");
setPageComplete(false);
return false;
}
break;
default:
ErrorReporter.INTERNAL_ERROR();
}
final Assignments assignments = mod.getAssignments();
for (int i = 0; i < assignments.getNofAssignments(); i++) {
final Assignment asg = assignments.getAssignmentByIndex(i);
if (asg.getIdentifier().getDisplayName().equals(newName)) {
setErrorMessage("A function with the provided name already exists!");
setPageComplete(false);
return false;
}
}
setErrorMessage(null);
setPageComplete(true);
return true;
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createFileChange.
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null) {
return null;
}
final DefinitionVisitor vis = new DefinitionVisitor();
module.accept(vis);
final List<FormalParameter> nodes = vis.getLocations();
// Calculate edit locations
final List<Location> locations = new ArrayList<Location>();
try {
final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
job1.join();
} catch (InterruptedException ie) {
ErrorReporter.logExceptionStackTrace(ie);
} catch (CoreException ce) {
ErrorReporter.logError("LazyficationRefactoring: " + "CoreException while calculating edit locations in " + toVisit.getName() + ".");
ErrorReporter.logExceptionStackTrace(ce);
}
if (locations.isEmpty()) {
return null;
}
// Create a change for each edit location
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
tfc.setEdit(rootEdit);
for (Location l : locations) {
rootEdit.addChild(new InsertEdit(l.getOffset(), "@lazy "));
}
return tfc;
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class DCListener method doubleClick.
@Override
public void doubleClick(final DoubleClickEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
final Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
Location loc = null;
if (o instanceof Module) {
loc = ((Module) o).getLocation();
LocationHighlighter.jumpToLocation(loc);
}
}
}
Aggregations