Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup

  • Loading branch information...
commit bfb0695133779895a8d33db54a755a1f2e2e8c48 1 parent 81a9f7b
@jakobc jakobc authored
View
11 org.erlide.ui/src/org/erlide/ui/editors/erl/AbstractErlangEditor.java
@@ -62,6 +62,7 @@
private IndentAction indentAction;
private ToggleCommentAction toggleCommentAction;
private InformationPresenter fInformationPresenter;
+ private IErlScanner erlScanner;
public abstract void reconcileNow();
@@ -73,7 +74,14 @@
public abstract IDocument getDocument();
- public abstract IErlScanner getScanner();
+ public IErlScanner getScanner() {
+ if (erlScanner == null) {
+ erlScanner = getNewScanner();
+ }
+ return erlScanner;
+ }
+
+ protected abstract IErlScanner getNewScanner();
@Override
protected void configureSourceViewerDecorationSupport(
@@ -436,4 +444,5 @@ public void createPartControl(final Composite parent) {
.setDocumentPartitioning(getSourceViewerConfiguration()
.getConfiguredDocumentPartitioning(getSourceViewer()));
}
+
}
View
12 org.erlide.ui/src/org/erlide/ui/editors/erl/ErlangEditor.java
@@ -149,7 +149,6 @@
new ActivationListener());
private String stateDirCached;
- private IErlScanner scanner;
/**
* Simple constructor
@@ -607,8 +606,8 @@ public IErlModule getModule() {
try {
fModule = ErlModelUtils.getModule(getEditorInput());
fModule.createScanner();
- scanner = fModule.getScanner();
- scanner.dispose();
+ final IErlScanner erlScanner = fModule.getScanner();
+ erlScanner.dispose();
} catch (final CoreException e) {
}
}
@@ -1288,8 +1287,7 @@ public void resetAndCacheScannerAndParser() {
resetReconciler();
try {
module.createScanner();
- scanner = module.getScanner();
- scanner.dispose();
+ module.getScanner().dispose();
module.resetAndCacheScannerAndParser(getDocument().get());
} catch (final ErlModelException e) {
ErlLogger.error(e);
@@ -1572,8 +1570,8 @@ String getStateDir() {
}
@Override
- public IErlScanner getScanner() {
- return scanner;
+ protected IErlScanner getNewScanner() {
+ return getModule().getScanner();
}
/**
View
286 org.erlide.ui/src/org/erlide/ui/editors/scratchpad/ErlangScratchPad.java
@@ -1,33 +1,14 @@
package org.erlide.ui.editors.scratchpad;
-import java.util.ResourceBundle;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextHover;
-import org.eclipse.jface.text.ITextHoverExtension2;
-import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.ITextViewerExtension2;
-import org.eclipse.jface.text.ITextViewerExtension4;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.information.IInformationProvider;
-import org.eclipse.jface.text.information.IInformationProviderExtension;
-import org.eclipse.jface.text.information.IInformationProviderExtension2;
-import org.eclipse.jface.text.information.InformationPresenter;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.projection.ProjectionViewer;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
@@ -37,8 +18,6 @@
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
-import org.eclipse.ui.texteditor.TextEditorAction;
-import org.eclipse.ui.texteditor.TextOperationAction;
import org.erlide.model.erlang.ErlToken;
import org.erlide.model.erlang.IErlModule;
import org.erlide.model.erlang.IErlScanner;
@@ -51,7 +30,6 @@
import org.erlide.ui.editors.erl.ColorManager;
import org.erlide.ui.editors.erl.ErlangSourceViewerConfiguration;
import org.erlide.ui.editors.erl.folding.IErlangFoldingStructureProvider;
-import org.erlide.ui.editors.erl.scanner.IErlangPartitions;
import org.erlide.ui.internal.ErlideUIPlugin;
import org.erlide.util.ErlLogger;
import org.erlide.util.Util;
@@ -60,11 +38,9 @@
ISaveablePart2 {
private ColorManager colorManager;
- private InformationPresenter fInformationPresenter;
private IErlangFoldingStructureProvider fProjectionModelUpdater;
private CompositeActionGroup fActionGroups;
private CompositeActionGroup fContextMenuGroup;
- private IErlScanner erlScanner = null;
/**
* Simple constructor
@@ -144,32 +120,14 @@ public void createPartControl(final Composite parent) {
super.createPartControl(parent);
setupBracketInserter();
-
- final ProjectionViewer v = (ProjectionViewer) getSourceViewer();
- v.doOperation(ProjectionViewer.TOGGLE);
-
- final IInformationControlCreator informationControlCreator = getSourceViewerConfiguration()
- .getInformationControlCreator(getSourceViewer());
-
- fInformationPresenter = new InformationPresenter(
- informationControlCreator);
- // sizes: see org.eclipse.jface.text.TextViewer.TEXT_HOVER_*_CHARS
- fInformationPresenter.setSizeConstraints(100, 12, true, true);
- fInformationPresenter.install(getSourceViewer());
- fInformationPresenter
- .setDocumentPartitioning(getSourceViewerConfiguration()
- .getConfiguredDocumentPartitioning(getSourceViewer()));
}
@Override
protected void createActions() {
super.createActions();
- // ActionGroup oeg, ovg, jsg;
ActionGroup esg;
- fActionGroups = new CompositeActionGroup(new ActionGroup[] {
- // oeg= new OpenEditorActionGroup(this),
- // ovg= new OpenViewActionGroup(this),
- esg = new ErlangSearchActionGroup(this) });
+ fActionGroups = new CompositeActionGroup(
+ new ActionGroup[] { esg = new ErlangSearchActionGroup(this) });
fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { esg });
createCommonActions();
@@ -188,208 +146,6 @@ protected void createActions() {
}
- // FIXME Copied from ErlangEditor
- /**
- * This action behaves in two different ways: If there is no current text
- * hover, the javadoc is displayed using information presenter. If there is
- * a current text hover, it is converted into a information presenter in
- * order to make it sticky.
- */
- class InformationDispatchAction extends TextEditorAction {
-
- /** The wrapped text operation action. */
- private final TextOperationAction fTextOperationAction;
-
- /**
- * Creates a dispatch action.
- *
- * @param resourceBundle
- * the resource bundle
- * @param prefix
- * the prefix
- * @param textOperationAction
- * the text operation action
- */
- public InformationDispatchAction(final ResourceBundle resourceBundle,
- final String prefix,
- final TextOperationAction textOperationAction) {
- super(resourceBundle, prefix, ErlangScratchPad.this);
- if (textOperationAction == null) {
- throw new IllegalArgumentException();
- }
- fTextOperationAction = textOperationAction;
- }
-
- /*
- * @see org.eclipse.jface.action.IAction#run()
- */
- @SuppressWarnings("synthetic-access")
- @Override
- public void run() {
-
- /**
- * Information provider used to present the information.
- *
- * @since 3.0
- */
- class InformationProvider implements IInformationProvider,
- IInformationProviderExtension,
- IInformationProviderExtension2 {
-
- private final IRegion fHoverRegion;
-
- private final String fHoverInfo;
-
- private final IInformationControlCreator fControlCreator;
-
- InformationProvider(final IRegion hoverRegion,
- final String hoverInfo,
- final IInformationControlCreator controlCreator) {
- fHoverRegion = hoverRegion;
- fHoverInfo = hoverInfo;
- fControlCreator = controlCreator;
- }
-
- /*
- * @seeorg.eclipse.jface.text.information.IInformationProvider#
- * getSubject(org.eclipse.jface.text.ITextViewer, int)
- */
-
- @Override
- public IRegion getSubject(final ITextViewer textViewer,
- final int invocationOffset) {
- return fHoverRegion;
- }
-
- @Override
- public Object getInformation2(final ITextViewer textViewer,
- final IRegion subject) {
- return fHoverInfo;
- }
-
- /*
- * @see
- * org.eclipse.jface.text.information.IInformationProviderExtension2
- * #getInformationPresenterControlCreator()
- *
- * @since 3.0
- */
-
- @Override
- public IInformationControlCreator getInformationPresenterControlCreator() {
- return fControlCreator;
- }
-
- @Override
- @Deprecated
- public String getInformation(final ITextViewer textViewer,
- final IRegion subject) {
- return null;
- }
- }
-
- final ISourceViewer sourceViewer = getSourceViewer();
- if (sourceViewer == null) {
- fTextOperationAction.run();
- return;
- }
-
- if (sourceViewer instanceof ITextViewerExtension4) {
- final ITextViewerExtension4 extension4 = (ITextViewerExtension4) sourceViewer;
- if (extension4.moveFocusToWidgetToken()) {
- return;
- }
- }
-
- if (!(sourceViewer instanceof ITextViewerExtension2)) {
- fTextOperationAction.run();
- return;
- }
-
- final ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
-
- // does a text hover exist?
- final ITextHover textHover = textViewerExtension2
- .getCurrentTextHover();
- if (textHover == null) {
- // TODO this crashes...
- // fTextOperationAction.run();
- return;
- }
-
- final Point hoverEventLocation = textViewerExtension2
- .getHoverEventLocation();
- final int offset = computeOffsetAtLocation(sourceViewer,
- hoverEventLocation.x, hoverEventLocation.y);
- if (offset == -1) {
- fTextOperationAction.run();
- return;
- }
-
- try {
- // get the text hover content
- final String contentType = TextUtilities.getContentType(
- sourceViewer.getDocument(),
- IErlangPartitions.ERLANG_PARTITIONING, offset, true);
-
- final IRegion hoverRegion = textHover.getHoverRegion(
- sourceViewer, offset);
- if (hoverRegion == null) {
- return;
- }
-
- final String hoverInfo = "";
- if (textHover instanceof ITextHoverExtension2) {
- ((ITextHoverExtension2) textHover).getHoverInfo2(
- sourceViewer, hoverRegion);
- }
-
- IInformationControlCreator controlCreator = null;
- if (textHover instanceof IInformationProviderExtension2) {
- controlCreator = ((IInformationProviderExtension2) textHover)
- .getInformationPresenterControlCreator();
- }
-
- final IInformationProvider informationProvider = new InformationProvider(
- hoverRegion, hoverInfo, controlCreator);
-
- fInformationPresenter.setOffset(offset);
- fInformationPresenter
- .setDocumentPartitioning(IErlangPartitions.ERLANG_PARTITIONING);
- fInformationPresenter.setInformationProvider(
- informationProvider, contentType);
- fInformationPresenter.showInformation();
- } catch (final BadLocationException e) {
- }
- }
-
- // modified version from TextViewer
- private int computeOffsetAtLocation(final ITextViewer textViewer,
- final int x, final int y) {
-
- final StyledText styledText = textViewer.getTextWidget();
- final IDocument document = textViewer.getDocument();
-
- if (document == null) {
- return -1;
- }
-
- try {
- final int widgetLocation = styledText
- .getOffsetAtLocation(new Point(x, y));
- if (textViewer instanceof ITextViewerExtension5) {
- final ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer;
- return extension.widgetOffset2ModelOffset(widgetLocation);
- }
- final IRegion visibleRegion = textViewer.getVisibleRegion();
- return widgetLocation + visibleRegion.getOffset();
- } catch (final IllegalArgumentException e) {
- return -1;
- }
-
- }
- }
-
@Override
protected void editorContextMenuAboutToShow(final IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
@@ -454,27 +210,25 @@ private IFile getFile() {
}
@Override
- public IErlScanner getScanner() {
- if (erlScanner == null) {
- final IFile file = getFile();
- if (file != null) {
- try {
- final String filePath = file.getLocation()
- .toPortableString();
- String initialText;
- initialText = Util.getInputStreamAsString(
- file.getContents(), file.getCharset());
- erlScanner = ErlModelManager
- .getErlangModel()
- .getToolkit()
- .createScanner(getScannerName(), initialText,
- filePath, false);
- } catch (final CoreException e) {
- ErlLogger.warn(e);
- }
- }
+ protected IErlScanner getNewScanner() {
+ final IFile file = getFile();
+ if (file == null) {
+ return null;
}
- return erlScanner;
+ try {
+ final String filePath = file.getLocation().toPortableString();
+ String initialText;
+ initialText = Util.getInputStreamAsString(file.getContents(),
+ file.getCharset());
+ return ErlModelManager
+ .getErlangModel()
+ .getToolkit()
+ .createScanner(getScannerName(), initialText, filePath,
+ false);
+ } catch (final CoreException e) {
+ ErlLogger.warn(e);
+ }
+ return null;
}
@Override
Please sign in to comment.
Something went wrong with that request. Please try again.