diff --git a/com.wudsn.ide.gfx/plugin.xml b/com.wudsn.ide.gfx/plugin.xml index 6b15d2e9..9a79f8b2 100644 --- a/com.wudsn.ide.gfx/plugin.xml +++ b/com.wudsn.ide.gfx/plugin.xml @@ -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"> + value="com.wudsn.ide.lng.editor.ILanguageEditor"> @@ -123,63 +123,11 @@ + value="com.wudsn.ide.lng.editor.ILanguageEditor"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -239,7 +187,7 @@ + value="com.wudsn.ide.lng.editor.ILanguageEditor"> diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguageAnnotationValues.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguageAnnotationValues.java index 6ca99e6f..e84aa249 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguageAnnotationValues.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguageAnnotationValues.java @@ -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 { diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointAdapterFactory.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointAdapterFactory.java index 90e74d9e..fdc73c8d 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointAdapterFactory.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointAdapterFactory.java @@ -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 getToggleTargets(IWorkbenchPart part, ISelection selection) { - if (part instanceof LanguageEditor) { + if (part instanceof ILanguageEditor) { Set defaultSet = new HashSet(); 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; diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointsTarget.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointsTarget.java index 0c019222..70556bc5 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointsTarget.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/breakpoint/LanguageBreakpointsTarget.java @@ -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 null. * @return The language editor or null. */ - 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; } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourceParser.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourceParser.java index 8bf128f5..f750afdb 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourceParser.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourceParser.java @@ -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; diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourcePartitionScanner.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourcePartitionScanner.java index b43aee26..893c8434 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourcePartitionScanner.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/compiler/parser/CompilerSourcePartitionScanner.java @@ -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 null. diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/ILanguageEditor.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/ILanguageEditor.java new file mode 100644 index 00000000..ca3a5827 --- /dev/null +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/ILanguageEditor.java @@ -0,0 +1,123 @@ +/** + * Copyright (C) 2009 - 2021 Peter Dell + * + * 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 . + */ + +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 null. + */ + public LanguagePlugin getPlugin(); + + /** + * Gets the language. + * + * @return The language, not null. + */ + public Language getLanguage(); + + /** + * Gets the language preferences. + * + * @return The language preferences, not null. + */ + public LanguagePreferences getLanguagePreferences(); + + /** + * Gets the compiler preferences. + * + * @return The compiler preferences, not null. + */ + public LanguageHardwareCompilerDefinitionPreferences getLanguageHardwareCompilerPreferences(); + + /** + * Gets the compiler for this editor. + * + * @return The compiler for this editor, not null. + */ + public Compiler getCompiler(); + + /** + * Gets the compiler definition for this editor. + * + * @return The compiler definition for this editor, not null. + * + * @sine 1.6.1 + */ + public CompilerDefinition getCompilerDefinition(); + + /** + * Gets the the current file. + * + * @return The current file or null. + */ + public IFile getCurrentIFile(); + + /** + * Gets the the current file. + * + * @return The current file or null. + */ + public File getCurrentFile(); + + /** + * Gets the directory of the current file. + * + * @return The directory of the current file or null. + */ + public File getCurrentDirectory(); + + /** + * Returns this text editor's document. + * + * @return the document or null 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 null . + */ + public CompilerSourceParser createCompilerSourceParser(); +} diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageContentAssistProcessor.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageContentAssistProcessor.java index 389694a5..e5acf7b4 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageContentAssistProcessor.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageContentAssistProcessor.java @@ -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 * null. */ - 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); diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java index c4adde4f..2d403577 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java @@ -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 null. - */ - 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 null. - */ - @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 null. - */ - 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 null. - */ - public final Language getLanguage() { - return getCompilerDefinition().getLanguage(); - } - - /** - * Gets the language preferences. - * - * @return The language preferences, not null. - */ - public final LanguagePreferences getLanguagePreferences() { - return plugin.getLanguagePreferences(getLanguage()); - } - - /** - * Gets the compiler preferences. - * - * @return The compiler preferences, not null. - */ 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 null. - */ - 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 null. - * - * @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 null . */ - 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 null - */ + @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 singleLineCommentDelimiters = compiler.getDefinition().getSyntax() + List 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 newAnnotations = new HashMap(); + var newAnnotations = new HashMap(); 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 null. - */ - 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 null. - */ + @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 null. - */ - 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; diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java index affe3426..5c7a6b5a 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java @@ -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 { * null. * @return true if an error was found. */ - private boolean positionToFirstErrorOrWarning(LanguageEditor languageEditor, List markers) { + private boolean positionToFirstErrorOrWarning(ILanguageEditor languageEditor, List 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) diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommandHandler.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommandHandler.java index 7a616f31..638dfc01 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommandHandler.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommandHandler.java @@ -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."); diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesCommandHandler.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesCommandHandler.java index d8def0b3..0b4addad 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesCommandHandler.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesCommandHandler.java @@ -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 null. +// */ +// +// @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 null. +// */ +// 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 null. +// */ +// public final Language getLanguage() { +// return getCompilerDefinition().getLanguage(); +// } +// +// /** +// * Gets the language preferences. +// * +// * @return The language preferences, not null. +// */ +// public final LanguagePreferences getLanguagePreferences() { +// return getPlugin().getLanguagePreferences(getLanguage()); +// } +// +// /** +// * Gets the compiler for this editor. +// * +// * @return The compiler for this editor, not null. +// */ +// 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 null. +// * +// * @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 null. +// * +// * @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 null. +// */ +// 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 * null . * @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; } \ No newline at end of file diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesLogic.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesLogic.java index 97a89f87..8a4bf1f3 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesLogic.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorFilesLogic.java @@ -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 null. */ - 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; diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenDeclarationCommandHandler.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenDeclarationCommandHandler.java index d52961d0..676144fe 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenDeclarationCommandHandler.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenDeclarationCommandHandler.java @@ -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 hyperlinks = new ArrayList(); LanguageHyperlinkDetector.detectHyperlinks(languageEditor, document, offset, false, hyperlinks); if (!hyperlinks.isEmpty()) { diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenFolderCommandHandler.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenFolderCommandHandler.java index 98287759..11a0b6bf 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenFolderCommandHandler.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorOpenFolderCommandHandler.java @@ -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) { diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorPropertyTester.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorPropertyTester.java index c5765d8a..8d9891b9 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorPropertyTester.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorPropertyTester.java @@ -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; diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorToggleCommentAction.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorToggleCommentAction.java index dc8a8634..768435d9 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorToggleCommentAction.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorToggleCommentAction.java @@ -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. diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlink.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlink.java index 0ab300d0..1d7d9412 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlink.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlink.java @@ -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()) { diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlinkDetector.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlinkDetector.java index 3d2a8cdd..eb04397a 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlinkDetector.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageHyperlinkDetector.java @@ -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 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 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 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; } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java index dc7ec32d..3fdbf202 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java @@ -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; diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlinePage.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlinePage.java index 3e173715..d935daf3 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlinePage.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlinePage.java @@ -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 { * null. * @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 { * null. */ 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; } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlineTreeContentProvider.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlineTreeContentProvider.java index 9c6a93ad..a75e39e2 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlineTreeContentProvider.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/outline/LanguageOutlineTreeContentProvider.java @@ -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(); diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java index 20c19535..ad3d391e 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java @@ -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(); } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java index 41dfa794..6071471b 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java @@ -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;