use of org.eclipse.titan.designer.editors.asn1editor.ASN1Editor 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.titan.designer.editors.asn1editor.ASN1Editor 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