use of org.eclipse.jface.text.TextSelection 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.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
targetEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (targetEditor instanceof ConfigEditor) {
targetEditor = ((ConfigEditor) targetEditor).getEditor();
}
if (targetEditor == null || !(targetEditor instanceof ConfigTextEditor)) {
return null;
}
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTIDENTIFIABLEFILE);
return null;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return null;
}
int offset;
if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
TITANDebugConsole.println("Selected: " + ((TextSelection) selection).getText());
}
TextSelection textSelection = (TextSelection) selection;
offset = textSelection.getOffset() + textSelection.getLength();
} else {
offset = ((ConfigTextEditor) targetEditor).getCarretOffset();
}
IDocument document = ((ConfigTextEditor) targetEditor).getDocument();
section_type section = getSection(document, offset);
if (section_type.UNKNOWN.equals(section)) {
if (handleModuleParameters(file, offset, document)) {
return null;
}
return null;
} else if (section_type.INCLUDE.equals(section)) {
handleIncludes(file, offset, document);
return null;
} else if (section_type.MODULE_PARAMETERS.equals(section)) {
// identifiable as a module parameter.
if (handleModuleParameters(file, offset, document)) {
return null;
}
}
// Fall back.
handleDefinitions(file, offset, document);
return null;
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method run.
@Override
public void run(final IAction action) {
if (targetEditor instanceof ConfigEditor) {
targetEditor = ((ConfigEditor) targetEditor).getEditor();
}
if (targetEditor == null || !(targetEditor instanceof ConfigTextEditor)) {
return;
}
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTIDENTIFIABLEFILE);
return;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return;
}
int offset;
if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
TITANDebugConsole.println("Selected: " + ((TextSelection) selection).getText());
}
TextSelection textSelection = (TextSelection) selection;
offset = textSelection.getOffset() + textSelection.getLength();
} else {
offset = ((ConfigTextEditor) targetEditor).getCarretOffset();
}
IDocument document = ((ConfigTextEditor) targetEditor).getDocument();
section_type section = getSection(document, offset);
if (section_type.UNKNOWN.equals(section)) {
return;
} else if (section_type.INCLUDE.equals(section)) {
handleIncludes(file, offset, document);
return;
} else if (section_type.MODULE_PARAMETERS.equals(section)) {
// identifiable as a module parameter.
if (handleModuleParameters(file, offset, document)) {
return;
}
}
// Fall back.
handleDefinitions(file, offset, document);
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class GotoMatchingBracketAction method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor instanceof ASN1Editor) {
this.targetEditor = (ASN1Editor) activeEditor;
} else {
this.targetEditor = null;
}
if (activeEditor == null) {
return null;
}
if (!selection.isEmpty()) {
if (selection instanceof TextSelection) {
TextSelection tSelection = (TextSelection) selection;
if (tSelection.getLength() != 0) {
return null;
}
}
}
IDocument document = this.targetEditor.getDocument();
int carretOffset = this.targetEditor.getCarretOffset();
PairMatcher pairMatcher = new PairMatcher();
IRegion region = pairMatcher.match(document, carretOffset);
if (region == null) {
return null;
}
int targetOffset;
if (region.getOffset() + 1 == carretOffset) {
targetOffset = region.getOffset() + region.getLength();
} else {
targetOffset = region.getOffset() + 1;
}
this.targetEditor.setCarretOffset(targetOffset);
this.targetEditor.selectAndReveal(targetOffset, 0);
return null;
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method doOpenDeclaration.
private final void doOpenDeclaration() {
if (targetEditor == null || !(targetEditor instanceof ASN1Editor)) {
return;
}
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
return;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return;
}
if (ResourceExclusionHelper.isExcluded(file)) {
MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
return;
}
IPreferencesService prefs = Platform.getPreferencesService();
boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
int offset;
if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
offset = ((ASN1Editor) targetEditor).getCarretOffset();
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
// TODO: How could this happen??? (NPE occured)
return;
}
IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
module.accept(visitor);
final Declaration decl = visitor.getReferencedDeclaration();
if (decl == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("No visible elements found");
}
return;
}
selectAndRevealDeclaration(decl.getIdentifier().getLocation());
}
Aggregations