use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method calculateEditLocations.
private WorkspaceJob calculateEditLocations(final List<FormalParameter> fparamlist, final IFile file, final List<Location> locations_out) throws CoreException {
final WorkspaceJob job = new WorkspaceJob("LazyficationRefactoring: calculate edit locations") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
for (FormalParameter fparam : fparamlist) {
System.out.println("reading: " + file.getName());
Location typeloc = fparam.getType(CompilationTimeStamp.getBaseTimestamp()).getLocation();
locations_out.add(0, new Location(fparam.getLocation().getFile(), fparam.getLocation().getLine(), typeloc.getOffset(), typeloc.getOffset()));
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method performOnSelectionOnly.
private void performOnSelectionOnly(final Module module) {
final Location selLoc = new Location(file, textSelection.getStartLine(), textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength());
final SelectionVisitor vis = new SelectionVisitor(selLoc);
module.accept(vis);
final Map<Log_Statement, Context> res = vis.getResult();
final MultiTextEdit rootEdit = new MultiTextEdit();
for (Map.Entry<Log_Statement, Context> e : res.entrySet()) {
final TextEdit edit = createTextEdit(e.getKey(), e.getValue());
if (edit != null) {
rootEdit.addChild(edit);
}
}
if (rootEdit.hasChildren()) {
change = new TextFileChange("Context logging", file);
change.setEdit(rootEdit);
}
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method performHeadless.
void performHeadless(final IFile selFile, final ITextSelection textSel) {
selectedFile = selFile;
final String fileContents = readFileContents(selFile);
if (fileContents == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): selFile does not exist at: " + selFile.getFullPath());
return;
}
final IDocument doc = new Document(fileContents);
textSelection = new TextSelection(doc, textSel.getOffset(), textSel.getLength());
//
project = selFile.getProject();
sourceParser = GlobalParser.getProjectSourceParser(project);
selectedModule = sourceParser.containedModule(selectedFile);
if (selectedModule == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): The module in the file " + selectedFile.getName() + " has no name.");
return;
}
// iterating through the module for the selected statements
final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
selectedModule.accept(selectionVisitor);
selectedStatements = selectionVisitor.createStatementList(textSelection);
if (selectedStatements.isEmpty()) {
ErrorReporter.logError(ERR_MSG_NO_SELECTION);
return;
}
if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
ErrorReporter.logError(selectedStatements.createDebugInfo());
ErrorReporter.logError(createDebugInfo());
}
// finding return type & runs on clause
final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
selectedModule.accept(runsonVisitor);
runsOnRef = runsonVisitor.getRunsOnRef();
parentFunc = runsonVisitor.getFuncDef();
// finding insert location
if (parentFunc instanceof Definition) {
insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
} else if (parentFunc instanceof ControlPart) {
final ControlPart cp = (ControlPart) parentFunc;
final Location commentLoc = cp.getCommentLocation();
insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
}
//
final ReturnVisitor retVis = new ReturnVisitor();
selectedStatements.accept(retVis);
returnCertainty = retVis.getCertainty();
if (retVis.getCertainty() != ReturnCertainty.NO) {
returnType = runsonVisitor.getReturnType();
}
// checking erroneousness of selection
checkErroneousGoto();
if (containsBreakWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
}
if (containsContinueWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
}
if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
}
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method perform.
void perform() {
// getting the active editor
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor == null || !(editor instanceof TTCN3Editor)) {
return;
}
final TTCN3Editor targetEditor = (TTCN3Editor) editor;
statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
// getting current selection
final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
textSelection = extractSelection(selectionService.getSelection());
if (textSelection == null) {
ErrorReporter.logError("No valid statements were found in the selection.");
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
// getting selected module
final IResource selectedRes = extractResource(targetEditor);
if (!(selectedRes instanceof IFile)) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
return;
}
selectedFile = (IFile) selectedRes;
project = selectedFile.getProject();
sourceParser = GlobalParser.getProjectSourceParser(project);
selectedModule = sourceParser.containedModule(selectedFile);
// iterating through the module for the selected statements
final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
selectedModule.accept(selectionVisitor);
selectedStatements = selectionVisitor.createStatementList(textSelection);
if (selectedStatements.isEmpty()) {
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
ErrorReporter.logError(selectedStatements.createDebugInfo());
ErrorReporter.logError(createDebugInfo());
}
// finding return type & runs on clause
final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
selectedModule.accept(runsonVisitor);
runsOnRef = runsonVisitor.getRunsOnRef();
parentFunc = runsonVisitor.getFuncDef();
// finding insert location
if (parentFunc instanceof Definition) {
insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
} else if (parentFunc instanceof ControlPart) {
final ControlPart cp = (ControlPart) parentFunc;
final Location commentLoc = cp.getCommentLocation();
insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
}
//
final ReturnVisitor retVis = new ReturnVisitor();
selectedStatements.accept(retVis);
returnCertainty = retVis.getCertainty();
if (retVis.getCertainty() != ReturnCertainty.NO) {
returnType = runsonVisitor.getReturnType();
}
// checking erroneousness of selection
checkErroneousGoto();
if (containsBreakWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
}
if (containsContinueWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
}
if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
}
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method calculateEditLocations.
private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final MultiTextEdit rootEdit) throws CoreException {
final WorkspaceJob job = new WorkspaceJob("InsertFieldRefactoring: calculate edit locations") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
for (ILocateableNode node : nodes) {
int vmLen = settings.getType().length() + settings.getId().getTtcnName().length();
if (node instanceof Def_Type) {
Def_Type df = (Def_Type) node;
Type type = df.getType(CompilationTimeStamp.getBaseTimestamp());
if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
vmLen = insertField((TTCN3_Set_Seq_Choice_BaseType) type, node, rootEdit, vmLen);
}
} else if (node instanceof Sequence_Value) {
Sequence_Value sv = (Sequence_Value) node;
vmLen += 6;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < sv.getNofComponents()) {
final Location valueLocation = sv.getSeqValueByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = sv.getNofComponents();
final Location valueLocation = sv.getSeqValueByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getEndOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (node instanceof TTCN3Template) {
TTCN3Template template = (TTCN3Template) node;
vmLen += 6;
if (template instanceof Named_Template_List) {
Named_Template_List ntl = (Named_Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < ntl.getNofTemplates()) {
final Location templateLocation = ntl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = ntl.getNofTemplates();
final Location templateLocation = ntl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (template instanceof Template_List) {
Template_List tl = (Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < tl.getNofTemplates()) {
final Location templateLocation = tl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getValue() + ","));
} else {
int max = tl.getNofTemplates();
final Location templateLocation = tl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), "," + settings.getValue()));
}
}
}
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
Aggregations