use of org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor in project titan.EclipsePlug-ins by eclipse.
the class GotoMatchingBracketAction method run.
@Override
public final void run(final IAction action) {
if (targetEditor == null) {
return;
}
if (targetEditor.getActiveEditor() != targetEditor.getEditor()) {
return;
}
if (!selection.isEmpty()) {
if (selection instanceof TextSelection) {
TextSelection tSelection = (TextSelection) selection;
if (tSelection.getLength() != 0) {
return;
}
}
}
ConfigTextEditor textEditor = targetEditor.getEditor();
IDocument document = textEditor.getDocument();
int carretOffset = textEditor.getCarretOffset();
PairMatcher pairMatcher = new PairMatcher();
IRegion region = pairMatcher.match(document, carretOffset);
if (region == null) {
return;
}
int targetOffset;
if (region.getOffset() + 1 == carretOffset) {
targetOffset = region.getOffset() + region.getLength();
} else {
targetOffset = region.getOffset() + 1;
}
textEditor.setCarretOffset(targetOffset);
textEditor.selectAndReveal(targetOffset, 0);
}
use of org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor 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 ConfigEditor) {
this.targetEditor = (ConfigEditor) activeEditor;
} else {
this.targetEditor = null;
}
if (activeEditor == null) {
return null;
}
if (this.targetEditor.getActiveEditor() != this.targetEditor.getEditor()) {
return null;
}
if (!selection.isEmpty()) {
if (selection instanceof TextSelection) {
TextSelection tSelection = (TextSelection) selection;
if (tSelection.getLength() != 0) {
return null;
}
}
}
ConfigTextEditor textEditor = this.targetEditor.getEditor();
IDocument document = textEditor.getDocument();
int carretOffset = textEditor.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;
}
textEditor.setCarretOffset(targetOffset);
textEditor.selectAndReveal(targetOffset, 0);
return null;
}
use of org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor 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.titan.designer.editors.configeditor.ConfigTextEditor 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.titan.designer.editors.configeditor.ConfigTextEditor in project titan.EclipsePlug-ins by eclipse.
the class ProjectConfigurationParser method fileBasedAnalysis.
/**
* Parses the provided file.
*
* @param file (in) the file to be parsed
* @param aMacros (in/out) collected macro references
* @param aFilesChecked files, which are already processed (there are no duplicates)
* @param aFilesToCheck files, which will be processed (there are no duplicates)
*/
private void fileBasedAnalysis(final IFile file, final List<Macro> aMacros, final List<IFile> aFilesToCheck, final List<IFile> aFilesChecked) {
List<TITANMarker> warnings = null;
List<SyntacticErrorStorage> errorsStored = null;
IDocument document = null;
ISemanticTITANEditor tempEditor = null;
List<ISemanticTITANEditor> editors = null;
if (EditorTracker.containsKey(file)) {
editors = EditorTracker.getEditor(file);
tempEditor = editors.get(0);
document = tempEditor.getDocument();
}
ConfigTextEditor editor = null;
if (tempEditor instanceof ConfigTextEditor) {
editor = (ConfigTextEditor) tempEditor;
}
String oldConfigFilePath = fileMap.get(file);
if (oldConfigFilePath != null) {
fileMap.remove(file);
}
CfgAnalyzer cfgAnalyzer = new CfgAnalyzer();
cfgAnalyzer.parse(file, document == null ? null : document.get());
errorsStored = cfgAnalyzer.getErrorStorage();
final CfgParseResult cfgParseResult = cfgAnalyzer.getCfgParseResult();
if (cfgParseResult != null) {
warnings = cfgParseResult.getWarnings();
aMacros.addAll(cfgParseResult.getMacros());
definitions.putAll(cfgParseResult.getDefinitions());
// add included files to the aFilesToCheck list
final List<String> includeFilenames = cfgParseResult.getIncludeFiles();
for (final String includeFilename : includeFilenames) {
// example value: includeFilename == MyExample2.cfg
// example value: file == L/hw/src/MyExample.cfg
final IPath includeFilePath = PathConverter.getProjectRelativePath(file, includeFilename);
// example value: includeFilePath == src/MyExample2.cfg
if (includeFilePath != null) {
final IFile includeFile = project.getFile(includeFilePath);
// includeFile is null if the file does not exist in the project
if (includeFile != null && !uptodateFiles.containsKey(includeFile) && !aFilesChecked.contains(includeFile) && !aFilesToCheck.contains(includeFile)) {
removeMarkersAndDefinitions(includeFile);
aFilesToCheck.add(includeFile);
}
}
}
if (editor != null && editor.getDocument() != null) {
ConfigEditor parentEditor = editor.getParentEditor();
if (errorsStored == null || errorsStored.isEmpty()) {
parentEditor.setParseTreeRoot(cfgParseResult.getParseTreeRoot());
parentEditor.setTokens(cfgParseResult.getTokens());
parentEditor.refresh(cfgAnalyzer);
parentEditor.setErrorMessage(null);
} else {
if (errorsStored.size() > 1) {
parentEditor.setErrorMessage("There were " + errorsStored.size() + " problems found while parsing");
} else {
parentEditor.setErrorMessage("There was 1 problem found while parsing");
}
}
}
}
fileMap.put(file, file.getFullPath().toOSString());
uptodateFiles.put(file, file.getFullPath().toOSString());
if (document != null) {
GlobalIntervalHandler.putInterval(document, cfgAnalyzer.getRootInterval());
}
if (warnings != null) {
for (TITANMarker marker : warnings) {
if (file.isAccessible()) {
Location location = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
location.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
}
}
}
if (errorsStored != null && !errorsStored.isEmpty()) {
String reportLevel = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTERRORSINEXTENSIONSYNTAX, GeneralConstants.WARNING, null);
int errorLevel;
if (GeneralConstants.ERROR.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_ERROR;
} else if (GeneralConstants.WARNING.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_WARNING;
} else {
return;
}
for (int i = 0; i < errorsStored.size(); i++) {
ParserMarkerSupport.createOnTheFlySyntacticMarker(file, errorsStored.get(i), errorLevel);
}
}
if (document != null && editors != null) {
ConfigFoldingSupport foldingSupport = new ConfigFoldingSupport();
final IDocument tempDocument = document;
final List<ISemanticTITANEditor> editors2 = editors;
final List<Position> positions = foldingSupport.calculatePositions(tempDocument);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
for (ISemanticTITANEditor editor : editors2) {
editor.updateFoldingStructure(positions);
editor.invalidateTextPresentation();
}
}
});
}
}
Aggregations