mirror of
https://github.com/peterdell/wudsn-ide.git
synced 2025-02-07 16:30:48 +00:00
Refactor towards ILanguageEditor
This commit is contained in:
parent
4a5bb29da4
commit
29116e8160
@ -95,7 +95,7 @@
|
||||
contributorClass="org.eclipse.ui.part.EditorActionBarContributor"
|
||||
default="true"
|
||||
extensions="bmp, ico, gif, jpg, png, cnv"
|
||||
icon="icons/graphics-editor.png"
|
||||
icon="icons/graphics-editor-16x16.png"
|
||||
id="com.wudsn.ide.gfx.editor.GraphicsConversionEditor"
|
||||
name="%com.wudsn.ide.gfx.editor.GraphicsConversionEditor.name">
|
||||
<contentTypeBinding
|
||||
|
@ -112,7 +112,7 @@
|
||||
<with
|
||||
variable="activeEditor">
|
||||
<instanceof
|
||||
value="com.wudsn.ide.lng.editor.LanguageEditor">
|
||||
value="com.wudsn.ide.lng.editor.ILanguageEditor">
|
||||
</instanceof>
|
||||
</with></activeWhen>
|
||||
</handler>
|
||||
@ -123,63 +123,11 @@
|
||||
<with
|
||||
variable="activeEditor">
|
||||
<instanceof
|
||||
value="com.wudsn.ide.lng.editor.LanguageEditor">
|
||||
value="com.wudsn.ide.lng.editor.ILanguageEditor">
|
||||
</instanceof>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.wudsn.ide.lng.editor.LanguageEditorCompileCommandHandler"
|
||||
commandId="com.wudsn.ide.lng.editor.LanguageEditorAssembleCommand">
|
||||
<activeWhen>
|
||||
<with
|
||||
variable="activeEditor">
|
||||
<test
|
||||
property="com.wudsn.ide.lng.IsLanguageEditor"
|
||||
value="true">
|
||||
</test>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.wudsn.ide.lng.editor.LanguageEditorCompileCommandHandler"
|
||||
commandId="com.wudsn.ide.lng.editor.LanguageEditorAssembleAndRunCommand">
|
||||
<activeWhen>
|
||||
<with
|
||||
variable="activeEditor">
|
||||
<test
|
||||
property="com.wudsn.ide.lng.IsLanguageEditor"
|
||||
value="true">
|
||||
</test>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.wudsn.ide.lng.editor.LanguageEditorCompileCommandHandler"
|
||||
commandId="com.wudsn.ide.lng.editor.LanguageEditorAssembleAndRunWithCommand">
|
||||
<activeWhen>
|
||||
<with
|
||||
variable="activeEditor">
|
||||
<test
|
||||
property="com.wudsn.ide.lng.IsLanguageEditor"
|
||||
value="true">
|
||||
</test>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.wudsn.ide.lng.editor.LanguageEditorCompilerHelpCommandHandler"
|
||||
commandId="com.wudsn.ide.lng.editor.LanguageEditorAssemblerHelpCommand">
|
||||
<activeWhen>
|
||||
<with
|
||||
variable="activeEditor">
|
||||
<test
|
||||
property="com.wudsn.ide.lng.IsLanguageEditor"
|
||||
value="true">
|
||||
</test>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.wudsn.ide.lng.editor.LanguageEditorCompileCommandHandler"
|
||||
commandId="com.wudsn.ide.lng.editor.LanguageEditorCompileCommand">
|
||||
@ -239,7 +187,7 @@
|
||||
<with
|
||||
variable="activeEditor">
|
||||
<instanceof
|
||||
value="com.wudsn.ide.lng.editor.LanguageEditor">
|
||||
value="com.wudsn.ide.lng.editor.ILanguageEditor">
|
||||
</instanceof>
|
||||
</with>
|
||||
</activeWhen>
|
||||
|
@ -32,10 +32,8 @@ import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import com.wudsn.ide.base.common.MarkerUtility;
|
||||
import com.wudsn.ide.base.common.StringUtility;
|
||||
import com.wudsn.ide.base.common.TextUtility;
|
||||
import com.wudsn.ide.lng.compiler.CompilerFiles.SourceFile;
|
||||
|
||||
public final class LanguageAnnotationValues {
|
||||
|
||||
|
@ -32,7 +32,7 @@ import com.wudsn.ide.base.common.TextUtility;
|
||||
import com.wudsn.ide.lng.Language;
|
||||
import com.wudsn.ide.lng.LanguageUtility;
|
||||
import com.wudsn.ide.lng.Texts;
|
||||
import com.wudsn.ide.lng.editor.LanguageEditor;
|
||||
import com.wudsn.ide.lng.editor.ILanguageEditor;
|
||||
|
||||
/**
|
||||
* Factory for {@LanguageBreakpointsTarget} instances. Used by extension
|
||||
@ -51,7 +51,7 @@ public final class LanguageBreakpointAdapterFactory implements IToggleBreakpoint
|
||||
|
||||
@Override
|
||||
public Set<String> getToggleTargets(IWorkbenchPart part, ISelection selection) {
|
||||
if (part instanceof LanguageEditor) {
|
||||
if (part instanceof ILanguageEditor) {
|
||||
Set<String> defaultSet = new HashSet<String>();
|
||||
defaultSet.add(getDefaultToggleTarget(part, selection));
|
||||
return defaultSet;
|
||||
@ -61,8 +61,8 @@ public final class LanguageBreakpointAdapterFactory implements IToggleBreakpoint
|
||||
|
||||
@Override
|
||||
public String getDefaultToggleTarget(IWorkbenchPart part, ISelection selection) {
|
||||
if (part instanceof LanguageEditor) {
|
||||
LanguageEditor languageEditor = (LanguageEditor) part;
|
||||
if (part instanceof ILanguageEditor) {
|
||||
var languageEditor = (ILanguageEditor) part;
|
||||
return TARGET_ID_PREFIX + languageEditor.getLanguage().name();
|
||||
}
|
||||
return null;
|
||||
|
@ -26,15 +26,13 @@ import org.eclipse.debug.core.model.IBreakpoint;
|
||||
import org.eclipse.debug.core.model.ILineBreakpoint;
|
||||
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
|
||||
import com.wudsn.ide.base.common.StringUtility;
|
||||
import com.wudsn.ide.lng.editor.LanguageEditor;
|
||||
import com.wudsn.ide.lng.editor.ILanguageEditor;
|
||||
|
||||
/**
|
||||
* Target which creates {@link LanguageBreakpoint} instances. Used by
|
||||
@ -50,7 +48,7 @@ public final class LanguageBreakpointsTarget implements IToggleBreakpointsTarget
|
||||
*/
|
||||
@Override
|
||||
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
|
||||
LanguageEditor languageEditor = getEditor(part);
|
||||
var languageEditor = getEditor(part);
|
||||
if (languageEditor != null) {
|
||||
IBreakpointManager breakPointManager = DebugPlugin.getDefault().getBreakpointManager();
|
||||
String editorId = languageEditor.getClass().getName();
|
||||
@ -71,8 +69,7 @@ public final class LanguageBreakpointsTarget implements IToggleBreakpointsTarget
|
||||
}
|
||||
// Create line breakpoint (doc line numbers start at 0)
|
||||
String description;
|
||||
IDocumentProvider provider = languageEditor.getDocumentProvider();
|
||||
IDocument document = provider.getDocument(languageEditor.getEditorInput());
|
||||
var document = languageEditor.getDocument();
|
||||
try {
|
||||
int startOffset = document.getLineOffset(lineNumber);
|
||||
int lineLength = document.getLineLength(lineNumber);
|
||||
@ -156,9 +153,9 @@ public final class LanguageBreakpointsTarget implements IToggleBreakpointsTarget
|
||||
* @param part The editor part or <code>null</code>.
|
||||
* @return The language editor or <code>null</code>.
|
||||
*/
|
||||
private LanguageEditor getEditor(IWorkbenchPart part) {
|
||||
if (part instanceof LanguageEditor) {
|
||||
LanguageEditor languageEditor = (LanguageEditor) part;
|
||||
private ILanguageEditor getEditor(IWorkbenchPart part) {
|
||||
if (part instanceof ILanguageEditor) {
|
||||
var languageEditor = (ILanguageEditor) part;
|
||||
if (languageEditor.getCurrentFile() != null) {
|
||||
return languageEditor;
|
||||
}
|
||||
|
@ -34,9 +34,8 @@ import org.eclipse.jface.text.IRegion;
|
||||
import com.wudsn.ide.base.BasePlugin;
|
||||
import com.wudsn.ide.base.common.FileUtility;
|
||||
import com.wudsn.ide.base.common.StringUtility;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.LanguageAnnotation;
|
||||
import com.wudsn.ide.lng.LanguageAnnotationValues;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.compiler.Compiler;
|
||||
import com.wudsn.ide.lng.compiler.syntax.CompilerSyntax;
|
||||
import com.wudsn.ide.lng.compiler.syntax.Instruction;
|
||||
|
@ -32,6 +32,7 @@ import org.eclipse.jface.text.rules.MultiLineRule;
|
||||
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
|
||||
import org.eclipse.jface.text.rules.SingleLineRule;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
|
||||
import com.wudsn.ide.lng.compiler.syntax.CompilerSyntax;
|
||||
import com.wudsn.ide.lng.editor.LanguageEditor;
|
||||
@ -63,7 +64,7 @@ public final class CompilerSourcePartitionScanner extends RuleBasedPartitionScan
|
||||
* Creates a new instance.
|
||||
*
|
||||
* Called by
|
||||
* {@link LanguageEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)}
|
||||
* {@link LanguageEditor#doSetInput(IEditorInput input)
|
||||
* .
|
||||
*
|
||||
* @param compilerSyntax The compiler syntax, not <code>null</code>.
|
||||
|
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WUDSN IDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.lng.editor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
||||
import com.wudsn.ide.lng.Language;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.compiler.Compiler;
|
||||
import com.wudsn.ide.lng.compiler.CompilerDefinition;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParser;
|
||||
import com.wudsn.ide.lng.preferences.LanguageHardwareCompilerDefinitionPreferences;
|
||||
import com.wudsn.ide.lng.preferences.LanguagePreferences;
|
||||
|
||||
/**
|
||||
* The language editor interface.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public interface ILanguageEditor extends IEditorPart {
|
||||
|
||||
/**
|
||||
* Gets the plugin this compiler instance belongs to.
|
||||
*
|
||||
* @return The plugin this compiler instance belongs to, not <code>null</code>.
|
||||
*/
|
||||
public LanguagePlugin getPlugin();
|
||||
|
||||
/**
|
||||
* Gets the language.
|
||||
*
|
||||
* @return The language, not <code>null</code>.
|
||||
*/
|
||||
public Language getLanguage();
|
||||
|
||||
/**
|
||||
* Gets the language preferences.
|
||||
*
|
||||
* @return The language preferences, not <code>null</code>.
|
||||
*/
|
||||
public LanguagePreferences getLanguagePreferences();
|
||||
|
||||
/**
|
||||
* Gets the compiler preferences.
|
||||
*
|
||||
* @return The compiler preferences, not <code>null</code>.
|
||||
*/
|
||||
public LanguageHardwareCompilerDefinitionPreferences getLanguageHardwareCompilerPreferences();
|
||||
|
||||
/**
|
||||
* Gets the compiler for this editor.
|
||||
*
|
||||
* @return The compiler for this editor, not <code>null</code>.
|
||||
*/
|
||||
public Compiler getCompiler();
|
||||
|
||||
/**
|
||||
* Gets the compiler definition for this editor.
|
||||
*
|
||||
* @return The compiler definition for this editor, not <code>null</code>.
|
||||
*
|
||||
* @sine 1.6.1
|
||||
*/
|
||||
public CompilerDefinition getCompilerDefinition();
|
||||
|
||||
/**
|
||||
* Gets the the current file.
|
||||
*
|
||||
* @return The current file or <code>null</code>.
|
||||
*/
|
||||
public IFile getCurrentIFile();
|
||||
|
||||
/**
|
||||
* Gets the the current file.
|
||||
*
|
||||
* @return The current file or <code>null</code>.
|
||||
*/
|
||||
public File getCurrentFile();
|
||||
|
||||
/**
|
||||
* Gets the directory of the current file.
|
||||
*
|
||||
* @return The directory of the current file or <code>null</code>.
|
||||
*/
|
||||
public File getCurrentDirectory();
|
||||
|
||||
/**
|
||||
* Returns this text editor's document.
|
||||
*
|
||||
* @return the document or <code>null</code> if none, e.g. after closing the
|
||||
* editor
|
||||
*/
|
||||
IDocument getDocument();
|
||||
|
||||
/**
|
||||
* Creates a compiler source parser for this editor and the currently selected
|
||||
* instruction set.
|
||||
*
|
||||
* @return The compiler source parser for this editor, not <code>null</code> .
|
||||
*/
|
||||
public CompilerSourceParser createCompilerSourceParser();
|
||||
}
|
@ -39,7 +39,6 @@ import org.eclipse.swt.graphics.TextStyle;
|
||||
|
||||
import com.wudsn.ide.base.common.StringUtility;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.compiler.CompilerFiles;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceFile;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParser;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParserLineCallback;
|
||||
@ -146,7 +145,7 @@ final class LanguageContentAssistProcessor implements IContentAssistProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private LanguageEditor editor;
|
||||
private ILanguageEditor editor;
|
||||
|
||||
private Image directiveImage;
|
||||
private Image legalOpcodeImage;
|
||||
@ -165,7 +164,7 @@ final class LanguageContentAssistProcessor implements IContentAssistProcessor {
|
||||
* @param editor The language editor for which this instance is created, not
|
||||
* <code>null</code>.
|
||||
*/
|
||||
LanguageContentAssistProcessor(LanguageEditor editor) {
|
||||
LanguageContentAssistProcessor(ILanguageEditor editor) {
|
||||
if (editor == null) {
|
||||
throw new IllegalArgumentException("Parameter 'editor' must not be null.");
|
||||
}
|
||||
@ -189,7 +188,7 @@ final class LanguageContentAssistProcessor implements IContentAssistProcessor {
|
||||
if (viewer == null) {
|
||||
throw new IllegalArgumentException("Parameter 'viewer' must not be null.");
|
||||
}
|
||||
ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
|
||||
var selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
|
||||
|
||||
int selectionOffset = offset;
|
||||
|
||||
@ -212,13 +211,13 @@ final class LanguageContentAssistProcessor implements IContentAssistProcessor {
|
||||
|
||||
// Parse the current compiler file and try to find the line in the
|
||||
// correct source file.
|
||||
CompilerFiles files = LanguageEditorFilesLogic.createInstance(editor).createCompilerFiles();
|
||||
var files = LanguageEditorFilesLogic.createInstance(editor).createCompilerFiles();
|
||||
if (files == null) {
|
||||
return null;
|
||||
}
|
||||
SourceParserCallback compilerSourceCallback = new SourceParserCallback(files.sourceFile.filePath, lineNumber);
|
||||
CompilerSourceParser compilerSourceParser = editor.createCompilerSourceParser();
|
||||
CompilerSourceFile compilerSourceFile = compilerSourceParser.createCompilerSourceFile(files.sourceFile.file,
|
||||
var compilerSourceCallback = new SourceParserCallback(files.sourceFile.filePath, lineNumber);
|
||||
var compilerSourceParser = editor.createCompilerSourceParser();
|
||||
var compilerSourceFile = compilerSourceParser.createCompilerSourceFile(files.sourceFile.file,
|
||||
viewer.getDocument());
|
||||
compilerSourceParser.parse(compilerSourceFile, compilerSourceCallback);
|
||||
|
||||
|
@ -47,7 +47,6 @@ import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.editors.text.TextEditor;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
import org.eclipse.ui.part.FileEditorInput;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
import org.eclipse.ui.texteditor.TextOperationAction;
|
||||
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||
|
||||
@ -57,7 +56,6 @@ import com.wudsn.ide.base.hardware.Hardware;
|
||||
import com.wudsn.ide.lng.Language;
|
||||
import com.wudsn.ide.lng.LanguageAnnotationValues.InvalidLanguageAnnotationException;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.Target;
|
||||
import com.wudsn.ide.lng.compiler.Compiler;
|
||||
import com.wudsn.ide.lng.compiler.CompilerDefinition;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceFile;
|
||||
@ -74,7 +72,7 @@ import com.wudsn.ide.lng.preferences.LanguagePreferences;
|
||||
* @author Peter Dell
|
||||
* @author Andy Reek
|
||||
*/
|
||||
public abstract class LanguageEditor extends TextEditor {
|
||||
public abstract class LanguageEditor extends TextEditor implements ILanguageEditor {
|
||||
|
||||
private static final class Actions {
|
||||
|
||||
@ -102,13 +100,46 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
filesLogic = LanguageEditorFilesLogic.createInstance(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the files logic associated with this editor.
|
||||
*
|
||||
* @return The files logic, not <code>null</code>.
|
||||
*/
|
||||
public LanguageEditorFilesLogic getFilesLogic() {
|
||||
return filesLogic;
|
||||
@Override
|
||||
protected final void initializeEditor() {
|
||||
super.initializeEditor();
|
||||
|
||||
plugin = LanguagePlugin.getInstance();
|
||||
compiler = plugin.getCompilerRegistry().getCompilerByEditorClassName(getClass().getName());
|
||||
|
||||
setSourceViewerConfiguration(new LanguageSourceViewerConfiguration(this, getPreferenceStore()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public final LanguagePlugin getPlugin() {
|
||||
if (plugin == null) {
|
||||
throw new IllegalStateException("Field 'plugin' must not be null.");
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Language getLanguage() {
|
||||
return getCompilerDefinition().getLanguage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final LanguagePreferences getLanguagePreferences() {
|
||||
return getPlugin().getLanguagePreferences(getLanguage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Compiler getCompiler() {
|
||||
if (compiler == null) {
|
||||
throw new IllegalStateException("Field 'compiler' must not be null.");
|
||||
}
|
||||
return compiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompilerDefinition getCompilerDefinition() {
|
||||
return getCompiler().getDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,125 +153,46 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
if (hardware != null) {
|
||||
return hardware;
|
||||
}
|
||||
return compiler.getDefinition().getDefaultHardware();
|
||||
return getCompilerDefinition().getDefaultHardware();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiler id for this editor.
|
||||
*
|
||||
* @return The compiler id for this editor, not empty and not <code>null</code>.
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected final void initializeEditor() {
|
||||
super.initializeEditor();
|
||||
|
||||
plugin = LanguagePlugin.getInstance();
|
||||
compiler = plugin.getCompilerRegistry().getCompilerByEditorClassName(getClass().getName());
|
||||
|
||||
setSourceViewerConfiguration(new LanguageSourceViewerConfiguration(this, getPreferenceStore()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin this compiler instance belongs to.
|
||||
*
|
||||
* @return The plugin this compiler instance belongs to, not <code>null</code>.
|
||||
*/
|
||||
public final LanguagePlugin getPlugin() {
|
||||
if (plugin == null) {
|
||||
throw new IllegalStateException("Field 'plugin' must not be null.");
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the language.
|
||||
*
|
||||
* @return The language, not <code>null</code>.
|
||||
*/
|
||||
public final Language getLanguage() {
|
||||
return getCompilerDefinition().getLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the language preferences.
|
||||
*
|
||||
* @return The language preferences, not <code>null</code>.
|
||||
*/
|
||||
public final LanguagePreferences getLanguagePreferences() {
|
||||
return plugin.getLanguagePreferences(getLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiler preferences.
|
||||
*
|
||||
* @return The compiler preferences, not <code>null</code>.
|
||||
*/
|
||||
public final LanguageHardwareCompilerDefinitionPreferences getLanguageHardwareCompilerPreferences() {
|
||||
return getLanguagePreferences().getLanguageHardwareCompilerDefinitionPreferences(getHardware(), getCompilerDefinition());
|
||||
return getLanguagePreferences().getLanguageHardwareCompilerDefinitionPreferences(getHardware(),
|
||||
getCompilerDefinition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiler for this editor.
|
||||
*
|
||||
* @return The compiler for this editor, not <code>null</code>.
|
||||
*/
|
||||
public final Compiler getCompiler() {
|
||||
if (compiler == null) {
|
||||
throw new IllegalStateException("Field 'compiler' must not be null.");
|
||||
}
|
||||
return compiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiler definition for this editor.
|
||||
*
|
||||
* @return The compiler definition for this editor, not <code>null</code>.
|
||||
*
|
||||
* @sine 1.6.1
|
||||
*/
|
||||
public final CompilerDefinition getCompilerDefinition() {
|
||||
if (compiler == null) {
|
||||
throw new IllegalStateException("Field 'compiler' must not be null.");
|
||||
}
|
||||
return compiler.getDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiler source parser for this editor and the currently selected
|
||||
* Creates a compiler source parser for this editor and the currently selected
|
||||
* instruction set.
|
||||
*
|
||||
* @return The compiler source parser for this editor, not <code>null</code> .
|
||||
*/
|
||||
public final CompilerSourceParser createCompilerSourceParser() {
|
||||
Target target;
|
||||
CompilerSourceParser result;
|
||||
if (compiler == null) {
|
||||
throw new IllegalStateException("Field 'compiler' must not be null.");
|
||||
public static CompilerSourceParser createCompilerSourceParser(ILanguageEditor languageEditor) {
|
||||
if (languageEditor == null) {
|
||||
throw new IllegalArgumentException("Parameter 'languageEditor' must not be null.");
|
||||
}
|
||||
target = getLanguageHardwareCompilerPreferences().getTarget();
|
||||
result = compiler.createSourceParser();
|
||||
var compiler = languageEditor.getCompiler();
|
||||
var target = languageEditor.getLanguageHardwareCompilerPreferences().getTarget();
|
||||
var result = compiler.createSourceParser();
|
||||
result.init(compiler.getDefinition().getSyntax().getInstructionSet(target));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called whenever the input changes, i.e. after loading and
|
||||
* after saving as new file.
|
||||
*
|
||||
* @param input The new input, may be <code>null</code>
|
||||
*/
|
||||
@Override
|
||||
public final CompilerSourceParser createCompilerSourceParser() {
|
||||
return createCompilerSourceParser(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void doSetInput(IEditorInput input) throws CoreException {
|
||||
super.doSetInput(input);
|
||||
|
||||
hardware = null;
|
||||
if (input != null) {
|
||||
IDocument document = getDocumentProvider().getDocument(getEditorInput());
|
||||
var document = getDocument();
|
||||
|
||||
CompilerSourcePartitionScanner partitionScanner = new CompilerSourcePartitionScanner(
|
||||
compiler.getDefinition().getSyntax());
|
||||
var partitionScanner = new CompilerSourcePartitionScanner(getCompilerDefinition().getSyntax());
|
||||
partitionScanner.createDocumentPartitioner(document);
|
||||
|
||||
var iFile = getCurrentIFile();
|
||||
@ -258,6 +210,11 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDocument getDocument() {
|
||||
return getDocumentProvider().getDocument(getEditorInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void createActions() {
|
||||
super.createActions();
|
||||
@ -286,8 +243,7 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
actionDefintionId = LanguageEditorActionDefinitionIds.ToggleBreakpoint;
|
||||
actionId = Actions.RulerDoubleClick;
|
||||
action.setActionDefinitionId(actionId);
|
||||
toggleBreakpointAction = new ToggleBreakpointAction(this, getDocumentProvider().getDocument(getEditorInput()),
|
||||
getVerticalRuler());
|
||||
toggleBreakpointAction = new ToggleBreakpointAction(this, getDocument(), getVerticalRuler());
|
||||
toggleBreakpointAction.setId(actionId);
|
||||
setAction(actionId, toggleBreakpointAction);
|
||||
markAsStateDependentAction(actionId, true);
|
||||
@ -392,16 +348,16 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
if (ruler == null) {
|
||||
throw new IllegalArgumentException("Parameter 'ruler' must not be null.");
|
||||
}
|
||||
ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(),
|
||||
var viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(),
|
||||
styles);
|
||||
|
||||
// Ensure decoration support has been created and configured.
|
||||
getSourceViewerDecorationSupport(viewer);
|
||||
|
||||
// The first single line comment delimiter is used as the default.
|
||||
List<String> singleLineCommentDelimiters = compiler.getDefinition().getSyntax()
|
||||
List<String> singleLineCommentDelimiters = getCompilerDefinition().getSyntax()
|
||||
.getSingleLineCommentDelimiters();
|
||||
String[] array = singleLineCommentDelimiters.toArray(new String[singleLineCommentDelimiters.size()]);
|
||||
var array = singleLineCommentDelimiters.toArray(new String[singleLineCommentDelimiters.size()]);
|
||||
viewer.setDefaultPrefixes(array, IDocument.DEFAULT_CONTENT_TYPE);
|
||||
viewer.setDefaultPrefixes(array, CompilerSourcePartitionScanner.PARTITION_COMMENT_SINGLE);
|
||||
|
||||
@ -479,11 +435,11 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
|
||||
}
|
||||
|
||||
Annotation[] removeAnnotations = deletions.toArray(new Annotation[deletions.size()]);
|
||||
var removeAnnotations = deletions.toArray(new Annotation[deletions.size()]);
|
||||
|
||||
// This will hold the new annotations along
|
||||
// with their corresponding folding positions.
|
||||
HashMap<ProjectionAnnotation, Position> newAnnotations = new HashMap<ProjectionAnnotation, Position>();
|
||||
var newAnnotations = new HashMap<ProjectionAnnotation, Position>();
|
||||
|
||||
for (int i = 0; i < foldingPositions.size(); i++) {
|
||||
annotation = new ProjectionAnnotation();
|
||||
@ -499,30 +455,26 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
annotationModel.modifyAnnotations(removeAnnotations, newAnnotations, new Annotation[] {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the directory of the current file.
|
||||
*
|
||||
* @return The directory of the current file or <code>null</code>.
|
||||
*/
|
||||
public final File getCurrentDirectory() {
|
||||
File result;
|
||||
result = getCurrentFile();
|
||||
if (result != null) {
|
||||
result = result.getParentFile();
|
||||
@Override
|
||||
public final IFile getCurrentIFile() {
|
||||
IFile result;
|
||||
var editorInput = getEditorInput();
|
||||
if (editorInput instanceof FileEditorInput) {
|
||||
var fileEditorInput = (FileEditorInput) editorInput;
|
||||
result = fileEditorInput.getFile();
|
||||
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the the current file.
|
||||
*
|
||||
* @return The current file or <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public final File getCurrentFile() {
|
||||
File result;
|
||||
IEditorInput editorInput = getEditorInput();
|
||||
var editorInput = getEditorInput();
|
||||
if (editorInput instanceof FileEditorInput) {
|
||||
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
|
||||
var fileEditorInput = (FileEditorInput) editorInput;
|
||||
result = new File(fileEditorInput.getPath().toOSString());
|
||||
} else {
|
||||
result = null;
|
||||
@ -530,20 +482,11 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the the current file.
|
||||
*
|
||||
* @return The current file or <code>null</code>.
|
||||
*/
|
||||
public final IFile getCurrentIFile() {
|
||||
IFile result;
|
||||
IEditorInput editorInput = getEditorInput();
|
||||
if (editorInput instanceof FileEditorInput) {
|
||||
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
|
||||
result = fileEditorInput.getFile();
|
||||
|
||||
} else {
|
||||
result = null;
|
||||
@Override
|
||||
public final File getCurrentDirectory() {
|
||||
var result = getCurrentFile();
|
||||
if (result != null) {
|
||||
result = result.getParentFile();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -559,8 +502,7 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
if (line < 1) {
|
||||
throw new IllegalArgumentException("Parameter 'line' must be positive. Specified value is " + line + ".");
|
||||
}
|
||||
IDocumentProvider provider = getDocumentProvider();
|
||||
IDocument document = provider.getDocument(getEditorInput());
|
||||
var document = getDocument();
|
||||
boolean result = false;
|
||||
try {
|
||||
int startOffset = document.getLineOffset(line - 1);
|
||||
@ -571,7 +513,7 @@ public abstract class LanguageEditor extends TextEditor {
|
||||
selectAndReveal(startOffset, lineLength);
|
||||
result = true;
|
||||
} catch (BadLocationException ex) {
|
||||
plugin.logError("Cannot position to line {0}.", new Object[] { String.valueOf(line) }, ex);
|
||||
getPlugin().logError("Cannot position to line {0}.", new Object[] { String.valueOf(line) }, ex);
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
|
@ -57,10 +57,8 @@ import com.wudsn.ide.base.common.MarkerUtility;
|
||||
import com.wudsn.ide.base.common.NumberUtility;
|
||||
import com.wudsn.ide.base.common.ProcessWithLogs;
|
||||
import com.wudsn.ide.base.common.StringUtility;
|
||||
import com.wudsn.ide.base.common.TextUtility;
|
||||
import com.wudsn.ide.base.hardware.Hardware;
|
||||
import com.wudsn.ide.lng.HardwareUtility;
|
||||
import com.wudsn.ide.lng.LanguageAnnotation;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.LanguageUtility;
|
||||
import com.wudsn.ide.lng.Texts;
|
||||
@ -137,7 +135,7 @@ final class LanguageEditorCompileCommand {
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static void execute(LanguageEditor languageEditor, CompilerFiles files, String commandId, String runnerId)
|
||||
public static void execute(ILanguageEditor languageEditor, CompilerFiles files, String commandId, String runnerId)
|
||||
throws RuntimeException {
|
||||
|
||||
if (languageEditor == null) {
|
||||
@ -188,7 +186,7 @@ final class LanguageEditorCompileCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean executeInternal(LanguageEditor languageEditor, CompilerFiles files, String commandId,
|
||||
private boolean executeInternal(ILanguageEditor languageEditor, CompilerFiles files, String commandId,
|
||||
String runnerId) {
|
||||
|
||||
if (languageEditor == null) {
|
||||
@ -461,7 +459,7 @@ final class LanguageEditorCompileCommand {
|
||||
*
|
||||
* @since 1.6.1
|
||||
*/
|
||||
private void createBreakpointsFile(LanguageEditor languageEditor, CompilerFiles files, Runner runner) {
|
||||
private void createBreakpointsFile(ILanguageEditor languageEditor, CompilerFiles files, Runner runner) {
|
||||
if (languageEditor == null) {
|
||||
throw new IllegalArgumentException("Parameter 'languageEditor' must not be null.");
|
||||
}
|
||||
@ -520,7 +518,7 @@ final class LanguageEditorCompileCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void openOutputFile(LanguageEditor languageEditor, CompilerFiles files,
|
||||
private void openOutputFile(ILanguageEditor languageEditor, CompilerFiles files,
|
||||
CompilerRunPreferences compilerRunPreferences, CompilerConsole compilerConsole, String runnerId) {
|
||||
|
||||
if (languageEditor == null) {
|
||||
@ -678,7 +676,7 @@ final class LanguageEditorCompileCommand {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
private boolean parseLogs(LanguageEditor languageEditor, CompilerFiles files, ProcessWithLogs compileProcess) {
|
||||
private boolean parseLogs(ILanguageEditor languageEditor, CompilerFiles files, ProcessWithLogs compileProcess) {
|
||||
|
||||
if (languageEditor == null) {
|
||||
throw new IllegalArgumentException("Parameter 'languageEditor' must not be null.");
|
||||
@ -738,7 +736,7 @@ final class LanguageEditorCompileCommand {
|
||||
* <code>null</code>.
|
||||
* @return <code>true</code> if an error was found.
|
||||
*/
|
||||
private boolean positionToFirstErrorOrWarning(LanguageEditor languageEditor, List<IMarker> markers) {
|
||||
private boolean positionToFirstErrorOrWarning(ILanguageEditor languageEditor, List<IMarker> markers) {
|
||||
|
||||
if (languageEditor == null) {
|
||||
throw new IllegalArgumentException("Parameter 'languageEditor' must not be null.");
|
||||
@ -796,7 +794,7 @@ final class LanguageEditorCompileCommand {
|
||||
return firstErrorMarker != null;
|
||||
}
|
||||
|
||||
private void parseCompilerSymbols(LanguageEditor languageEditor, CompilerFiles files,
|
||||
private void parseCompilerSymbols(ILanguageEditor languageEditor, CompilerFiles files,
|
||||
CompilerProcessLogParser logParser) {
|
||||
|
||||
if (languageEditor == null)
|
||||
|
@ -40,7 +40,7 @@ public final class LanguageEditorCompileCommandHandler extends LanguageEditorFil
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(ExecutionEvent event, LanguageEditor languageEditor, CompilerFiles files)
|
||||
protected void execute(ExecutionEvent event, ILanguageEditor languageEditor, CompilerFiles files)
|
||||
throws ExecutionException {
|
||||
if (event == null) {
|
||||
throw new IllegalArgumentException("Parameter 'event' must not be null.");
|
||||
|
@ -23,7 +23,6 @@ import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.common.NotDefinedException;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
@ -45,17 +44,121 @@ public abstract class LanguageEditorFilesCommandHandler extends AbstractHandler
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart editor;
|
||||
editor = HandlerUtil.getActiveEditorChecked(event);
|
||||
if (!(editor instanceof LanguageEditor)) {
|
||||
return null;
|
||||
var editor = HandlerUtil.getActiveEditorChecked(event);
|
||||
if (!(editor instanceof ILanguageEditor)) {
|
||||
if (!LanguageEditorPropertyTester.isPascalEditor(editor)) {
|
||||
return null;
|
||||
|
||||
}
|
||||
// editor=new ILanguageEditor() {
|
||||
//
|
||||
// /**
|
||||
// * Gets the compiler id for this editor.
|
||||
// *
|
||||
// * @return The compiler id for this editor, not empty and not <code>null</code>.
|
||||
// */
|
||||
//
|
||||
// @Override
|
||||
// protected final void initializeEditor() {
|
||||
// super.initializeEditor();
|
||||
//
|
||||
// plugin = LanguagePlugin.getInstance();
|
||||
// compiler = plugin.getCompilerRegistry().getCompilerByEditorClassName(getEditorClassName());
|
||||
//
|
||||
// setSourceViewerConfiguration(new LanguageSourceViewerConfiguration(this, getPreferenceStore()));
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // TODO
|
||||
// protected String getEditorClassName() {
|
||||
// return getClass().getName();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the plugin this compiler instance belongs to.
|
||||
// *
|
||||
// * @return The plugin this compiler instance belongs to, not <code>null</code>.
|
||||
// */
|
||||
// public final LanguagePlugin getPlugin() {
|
||||
// if (plugin == null) {
|
||||
// throw new IllegalStateException("Field 'plugin' must not be null.");
|
||||
// }
|
||||
// return plugin;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the language.
|
||||
// *
|
||||
// * @return The language, not <code>null</code>.
|
||||
// */
|
||||
// public final Language getLanguage() {
|
||||
// return getCompilerDefinition().getLanguage();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the language preferences.
|
||||
// *
|
||||
// * @return The language preferences, not <code>null</code>.
|
||||
// */
|
||||
// public final LanguagePreferences getLanguagePreferences() {
|
||||
// return getPlugin().getLanguagePreferences(getLanguage());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the compiler for this editor.
|
||||
// *
|
||||
// * @return The compiler for this editor, not <code>null</code>.
|
||||
// */
|
||||
// public final Compiler getCompiler() {
|
||||
// if (compiler == null) {
|
||||
// throw new IllegalStateException("Field 'compiler' must not be null.");
|
||||
// }
|
||||
// return compiler;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the compiler definition for this editor.
|
||||
// *
|
||||
// * @return The compiler definition for this editor, not <code>null</code>.
|
||||
// *
|
||||
// * @sine 1.6.1
|
||||
// */
|
||||
// public final CompilerDefinition getCompilerDefinition() {
|
||||
// if (compiler == null) {
|
||||
// throw new IllegalStateException("Field 'compiler' must not be null.");
|
||||
// }
|
||||
// return compiler.getDefinition();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the default hardware for this editor.
|
||||
// *
|
||||
// * @return The hardware for this editor, not <code>null</code>.
|
||||
// *
|
||||
// * @since 1.6.1
|
||||
// */
|
||||
// protected final Hardware getHardware() {
|
||||
// if (hardware != null) {
|
||||
// return hardware;
|
||||
// }
|
||||
// return getCompilerDefinition().getDefaultHardware();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Gets the compiler preferences.
|
||||
// *
|
||||
// * @return The compiler preferences, not <code>null</code>.
|
||||
// */
|
||||
// public final LanguageHardwareCompilerDefinitionPreferences getLanguageHardwareCompilerPreferences() {
|
||||
// return getLanguagePreferences().getLanguageHardwareCompilerDefinitionPreferences(getHardware(),
|
||||
// getCompilerDefinition());
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
LanguageEditor languageEditor;
|
||||
languageEditor = (LanguageEditor) editor;
|
||||
|
||||
CompilerFiles files;
|
||||
files = LanguageEditorFilesLogic.createInstance(languageEditor).createCompilerFiles();
|
||||
var languageEditor = (ILanguageEditor) editor;
|
||||
var files = LanguageEditorFilesLogic.createInstance(languageEditor).createCompilerFiles();
|
||||
|
||||
if (files != null) {
|
||||
execute(event, languageEditor, files);
|
||||
@ -68,8 +171,10 @@ public abstract class LanguageEditorFilesCommandHandler extends AbstractHandler
|
||||
} catch (NotDefinedException ignore) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +187,7 @@ public abstract class LanguageEditorFilesCommandHandler extends AbstractHandler
|
||||
* <code>null</code> .
|
||||
* @throws ExecutionException if an exception occurred during execution.
|
||||
*/
|
||||
protected abstract void execute(ExecutionEvent event, LanguageEditor languageEditor, CompilerFiles files)
|
||||
protected abstract void execute(ExecutionEvent event, ILanguageEditor languageEditor, CompilerFiles files)
|
||||
throws ExecutionException;
|
||||
|
||||
}
|
@ -30,17 +30,16 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import com.wudsn.ide.base.common.FileUtility;
|
||||
import com.wudsn.ide.base.common.MarkerUtility;
|
||||
import com.wudsn.ide.base.common.StringUtility;
|
||||
import com.wudsn.ide.base.hardware.Hardware;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.LanguageAnnotation;
|
||||
import com.wudsn.ide.lng.LanguageAnnotationValues;
|
||||
import com.wudsn.ide.lng.LanguageAnnotationValues.InvalidLanguageAnnotationException;
|
||||
import com.wudsn.ide.lng.LanguageAnnotationValues.LanguageAnnotationValue;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.Texts;
|
||||
import com.wudsn.ide.lng.compiler.CompilerDefinition;
|
||||
import com.wudsn.ide.lng.compiler.CompilerFiles;
|
||||
@ -56,7 +55,7 @@ import com.wudsn.ide.lng.compiler.parser.CompilerSourceParser;
|
||||
*/
|
||||
public final class LanguageEditorFilesLogic {
|
||||
|
||||
private LanguageEditor languageEditor;
|
||||
private ILanguageEditor languageEditor;
|
||||
|
||||
/**
|
||||
* Create a new instance of the logic.
|
||||
@ -65,7 +64,7 @@ public final class LanguageEditorFilesLogic {
|
||||
*
|
||||
* @return The new instance, not <code>null</code>.
|
||||
*/
|
||||
static LanguageEditorFilesLogic createInstance(LanguageEditor languageEditor) {
|
||||
static LanguageEditorFilesLogic createInstance(ILanguageEditor languageEditor) {
|
||||
if (languageEditor == null) {
|
||||
throw new IllegalArgumentException("Parameter 'languageEditor' must not be null.");
|
||||
}
|
||||
@ -87,7 +86,7 @@ public final class LanguageEditorFilesLogic {
|
||||
sourceIFile = languageEditor.getCurrentIFile();
|
||||
if (sourceIFile != null) {
|
||||
|
||||
IDocument document = languageEditor.getDocumentProvider().getDocument(languageEditor.getEditorInput());
|
||||
var document = languageEditor.getDocument();
|
||||
LanguageAnnotationValues annotationValues = CompilerSourceParser.getAnnotationValues(document);
|
||||
|
||||
IFile mainSourceIFile;
|
||||
|
@ -25,9 +25,7 @@ import java.util.List;
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
/**
|
||||
@ -41,18 +39,16 @@ public final class LanguageEditorOpenDeclarationCommandHandler extends AbstractH
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart editor;
|
||||
editor = HandlerUtil.getActiveEditorChecked(event);
|
||||
if (!(editor instanceof LanguageEditor)) {
|
||||
var editor = HandlerUtil.getActiveEditorChecked(event);
|
||||
if (!(editor instanceof ILanguageEditor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LanguageEditor languageEditor;
|
||||
languageEditor = (LanguageEditor) editor;
|
||||
var languageEditor = (ILanguageEditor) editor;
|
||||
ITextSelection textSelection = (ITextSelection) languageEditor.getSite().getSelectionProvider().getSelection();
|
||||
if (textSelection != null) {
|
||||
IDocument document = languageEditor.getDocumentProvider().getDocument(languageEditor.getEditorInput());
|
||||
int offset = textSelection.getOffset();
|
||||
var document = languageEditor.getDocument();
|
||||
var offset = textSelection.getOffset();
|
||||
List<LanguageHyperlink> hyperlinks = new ArrayList<LanguageHyperlink>();
|
||||
LanguageHyperlinkDetector.detectHyperlinks(languageEditor, document, offset, false, hyperlinks);
|
||||
if (!hyperlinks.isEmpty()) {
|
||||
|
@ -36,7 +36,7 @@ public final class LanguageEditorOpenFolderCommandHandler extends LanguageEditor
|
||||
public static final String OPEN_OUTPUT_FOLDER = "com.wudsn.ide.lng.editor.LanguageEditorOpenOutputFolderCommand";
|
||||
|
||||
@Override
|
||||
protected void execute(ExecutionEvent event, LanguageEditor languageEditor, CompilerFiles files)
|
||||
protected void execute(ExecutionEvent event, ILanguageEditor languageEditor, CompilerFiles files)
|
||||
throws ExecutionException {
|
||||
|
||||
if (event == null) {
|
||||
|
@ -23,10 +23,22 @@ import org.eclipse.core.expressions.PropertyTester;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ui.editors.text.TextEditor;
|
||||
|
||||
import com.wudsn.ide.lng.Language;
|
||||
|
||||
public class LanguageEditorPropertyTester extends PropertyTester {
|
||||
|
||||
static boolean isPascalEditor(Object receiver) {
|
||||
if (receiver instanceof TextEditor) {
|
||||
|
||||
var editor = (TextEditor) receiver;
|
||||
var input = editor.getEditorInput();
|
||||
var file = input.getAdapter(IFile.class);
|
||||
if (file != null && file.getName().toLowerCase().endsWith(".pas")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public LanguageEditorPropertyTester() {
|
||||
}
|
||||
|
||||
@ -35,18 +47,11 @@ public class LanguageEditorPropertyTester extends PropertyTester {
|
||||
|
||||
if (property.equals("IsLanguageEditor")) {
|
||||
|
||||
if (receiver instanceof LanguageEditor) {
|
||||
if (receiver instanceof ILanguageEditor) {
|
||||
return true;
|
||||
}
|
||||
if (receiver instanceof TextEditor) {
|
||||
|
||||
var editor = (TextEditor) receiver;
|
||||
var input = editor.getEditorInput();
|
||||
var file = input.getAdapter(IFile.class);
|
||||
if (file != null && file.getName().toLowerCase().endsWith(".pas")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isPascalEditor(receiver)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -43,7 +43,7 @@ final class LanguageEditorToggleCommentAction extends TextEditorAction {
|
||||
/**
|
||||
* The owning editor.
|
||||
*/
|
||||
private final LanguageEditor editor;
|
||||
private final ILanguageEditor editor;
|
||||
|
||||
/**
|
||||
* The editor's source viewer.
|
||||
|
@ -170,8 +170,7 @@ final class LanguageHyperlink implements IHyperlink {
|
||||
return;
|
||||
}
|
||||
}
|
||||
IEditorPart editorPart;
|
||||
editorPart = null;
|
||||
IEditorPart editorPart = null;
|
||||
if (editorId.equals(DEFAULT_EDITOR)) {
|
||||
|
||||
if (fileToOpen.exists() && fileToOpen.isFile()) {
|
||||
|
@ -41,7 +41,6 @@ import com.wudsn.ide.gfx.editor.GraphicsConversionEditor;
|
||||
import com.wudsn.ide.hex.HexEditor;
|
||||
import com.wudsn.ide.lng.LanguageUtility;
|
||||
import com.wudsn.ide.lng.Texts;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceFile;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParser;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParserFileReference;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParserFileReferenceType;
|
||||
@ -124,7 +123,7 @@ public final class LanguageHyperlinkDetector extends AbstractHyperlinkDetector {
|
||||
|
||||
}
|
||||
|
||||
final static void detectHyperlinks(LanguageEditor languageEditor, IDocument document, int offset,
|
||||
final static void detectHyperlinks(ILanguageEditor languageEditor, IDocument document, int offset,
|
||||
boolean canShowMultipleHyperlinks, List<LanguageHyperlink> hyperlinks) {
|
||||
IRegion lineInfo;
|
||||
int lineNumber;
|
||||
@ -149,7 +148,7 @@ public final class LanguageHyperlinkDetector extends AbstractHyperlinkDetector {
|
||||
}
|
||||
}
|
||||
|
||||
private static void detectInclude(LanguageEditor languageEditor, IRegion lineInfo, int lineNumber, String line,
|
||||
private static void detectInclude(ILanguageEditor languageEditor, IRegion lineInfo, int lineNumber, String line,
|
||||
int offsetInLine, boolean canShowMultipleHyperlinks, List<LanguageHyperlink> hyperlinks) {
|
||||
// Try to detect binary or source includes
|
||||
CompilerSourceParser compilerSourceParser = languageEditor.createCompilerSourceParser();
|
||||
@ -185,15 +184,14 @@ public final class LanguageHyperlinkDetector extends AbstractHyperlinkDetector {
|
||||
|
||||
// Perform resolution of relative paths and compiler specific
|
||||
// default extension.
|
||||
File currentDirectory = languageEditor.getCurrentDirectory();
|
||||
var currentDirectory = languageEditor.getCurrentDirectory();
|
||||
String absoluteFilePath = compilerSourceParser.getIncludeAbsoluteFilePath(fileReference.getType(),
|
||||
currentDirectory, filePath);
|
||||
if (absoluteFilePath == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
URI uri;
|
||||
uri = new File(absoluteFilePath).toURI();
|
||||
var uri = new File(absoluteFilePath).toURI();
|
||||
|
||||
IRegion linkRegion = new Region(lineInfo.getOffset() + startQuoteOffset + 1, filePath.length());
|
||||
|
||||
@ -233,10 +231,10 @@ public final class LanguageHyperlinkDetector extends AbstractHyperlinkDetector {
|
||||
}
|
||||
}
|
||||
|
||||
private static void detectIdentifier(LanguageEditor languageEditor, IRegion lineInfo, int lineNumber, String line,
|
||||
private static void detectIdentifier(ILanguageEditor languageEditor, IRegion lineInfo, int lineNumber, String line,
|
||||
int offsetInLine, boolean canShowMultipleHyperlinks, List<LanguageHyperlink> hyperlinks) {
|
||||
|
||||
CompilerSyntax compilerSyntax = languageEditor.createCompilerSourceParser().getCompilerSyntax();
|
||||
var compilerSyntax = languageEditor.createCompilerSourceParser().getCompilerSyntax();
|
||||
|
||||
int startIdentifierOffset = offsetInLine;
|
||||
int endIdentifierOffset = offsetInLine;
|
||||
@ -260,7 +258,8 @@ public final class LanguageHyperlinkDetector extends AbstractHyperlinkDetector {
|
||||
endIdentifierOffset++;
|
||||
}
|
||||
String identifier = line.substring(startIdentifierOffset, endIdentifierOffset);
|
||||
CompilerSourceFile compilerSourceFile = languageEditor.getCompilerSourceFile();
|
||||
// TODO: Hard cast to LanguageEditor
|
||||
var compilerSourceFile = ((LanguageEditor) languageEditor).getCompilerSourceFile();
|
||||
if (compilerSourceFile == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ import com.wudsn.ide.lng.compiler.syntax.InstructionType;
|
||||
import com.wudsn.ide.lng.compiler.syntax.Opcode;
|
||||
import com.wudsn.ide.lng.preferences.LanguageHardwareCompilerDefinitionPreferencesConstants;
|
||||
import com.wudsn.ide.lng.preferences.LanguagePreferences;
|
||||
import com.wudsn.ide.lng.preferences.LanguagePreferencesConstants;
|
||||
import com.wudsn.ide.lng.preferences.LanguagePreferencesConstants.EditorConstants;
|
||||
import com.wudsn.ide.lng.preferences.TextAttributeConverter;
|
||||
|
||||
|
@ -57,6 +57,7 @@ import com.wudsn.ide.lng.compiler.parser.CompilerSourceFile;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParserTreeObject;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParserTreeObjectLabelProvider;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParserTreeObjectType;
|
||||
import com.wudsn.ide.lng.editor.ILanguageEditor;
|
||||
import com.wudsn.ide.lng.editor.LanguageEditor;
|
||||
|
||||
/**
|
||||
@ -76,7 +77,7 @@ public final class LanguageOutlinePage extends ContentOutlinePage {
|
||||
private static final class OutlineViewerSortAction extends Action {
|
||||
private static final QualifiedName CHECKED = new QualifiedName("OutlineViewerSortAction", "Checked");
|
||||
|
||||
final LanguageEditor editor;
|
||||
final ILanguageEditor editor;
|
||||
final TreeViewer treeViewer;
|
||||
|
||||
/**
|
||||
@ -86,7 +87,7 @@ public final class LanguageOutlinePage extends ContentOutlinePage {
|
||||
* <code>null</code>.
|
||||
* @param treeViewer The tree viewer which displays the outline.
|
||||
*/
|
||||
public OutlineViewerSortAction(LanguageEditor editor, TreeViewer treeViewer) {
|
||||
public OutlineViewerSortAction(ILanguageEditor editor, TreeViewer treeViewer) {
|
||||
super("", AS_CHECK_BOX);
|
||||
if (editor == null) {
|
||||
throw new IllegalArgumentException("Parameter 'editor' must not be null.");
|
||||
@ -131,7 +132,7 @@ public final class LanguageOutlinePage extends ContentOutlinePage {
|
||||
// Store the value.
|
||||
String checkedProperty = Boolean.toString(checked);
|
||||
try {
|
||||
IFile iFile = editor.getCurrentIFile();
|
||||
var iFile = editor.getCurrentIFile();
|
||||
if (iFile != null) {
|
||||
iFile.setPersistentProperty(CHECKED, checkedProperty);
|
||||
}
|
||||
@ -550,9 +551,8 @@ public final class LanguageOutlinePage extends ContentOutlinePage {
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public final CompilerSourceFile getCompilerSourceFile() {
|
||||
LanguageOutlineTreeContentProvider contentProvider;
|
||||
contentProvider = (LanguageOutlineTreeContentProvider) getTreeViewer().getContentProvider();
|
||||
CompilerSourceFile compilerSourceFile = contentProvider.getCompilerSourceFile();
|
||||
var contentProvider = (LanguageOutlineTreeContentProvider) getTreeViewer().getContentProvider();
|
||||
var compilerSourceFile = contentProvider.getCompilerSourceFile();
|
||||
return compilerSourceFile;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ package com.wudsn.ide.lng.outline;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
@ -30,7 +29,6 @@ import com.wudsn.ide.base.common.Profiler;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceFile;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParser;
|
||||
import com.wudsn.ide.lng.compiler.parser.CompilerSourceParserTreeObject;
|
||||
import com.wudsn.ide.lng.editor.LanguageEditor;
|
||||
|
||||
/**
|
||||
* Tree content provider to {@link LanguageOutlinePage}.
|
||||
@ -159,8 +157,8 @@ final class LanguageOutlineTreeContentProvider implements ITreeContentProvider {
|
||||
*/
|
||||
private void parse() {
|
||||
|
||||
LanguageEditor editor = this.languageOutlinePage.editor;
|
||||
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
|
||||
var editor = this.languageOutlinePage.editor;
|
||||
var document = editor.getDocument();
|
||||
|
||||
if (document != null) {
|
||||
CompilerSourceParser parser = editor.createCompilerSourceParser();
|
||||
|
@ -68,8 +68,8 @@ import com.wudsn.ide.lng.compiler.CompilerDefinition;
|
||||
import com.wudsn.ide.lng.compiler.CompilerPaths;
|
||||
import com.wudsn.ide.lng.compiler.CompilerPaths.CompilerPath;
|
||||
import com.wudsn.ide.lng.compiler.CompilerRegistry;
|
||||
import com.wudsn.ide.lng.editor.ILanguageEditor;
|
||||
import com.wudsn.ide.lng.editor.LanguageContentAssistProcessorDefaultCase;
|
||||
import com.wudsn.ide.lng.editor.LanguageEditor;
|
||||
import com.wudsn.ide.lng.editor.LanguageEditorCompileCommandPositioningMode;
|
||||
import com.wudsn.ide.lng.preferences.LanguagePreferencesConstants.EditorConstants;
|
||||
|
||||
@ -169,9 +169,8 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
||||
@Override
|
||||
public void init(IWorkbench workbench) {
|
||||
IEditorPart editor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||
if (editor instanceof LanguageEditor) {
|
||||
LanguageEditor languageEditor;
|
||||
languageEditor = (LanguageEditor) editor;
|
||||
if (editor instanceof ILanguageEditor) {
|
||||
var languageEditor = (ILanguageEditor) editor;
|
||||
activeCompilerId = languageEditor.getCompilerDefinition().getId();
|
||||
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ package com.wudsn.ide.lng.preferences;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.TextAttribute;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
|
||||
import com.wudsn.ide.base.common.AbstractIDEPlugin;
|
||||
|
Loading…
x
Reference in New Issue
Block a user