aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDawid Pakuła2018-07-18 12:45:45 -0400
committerDawid Pakuła2018-07-18 12:45:45 -0400
commit60e42eaa287de963b7fb4ec8e09e4f1d1620fd43 (patch)
treeb9fdf50ca71db8b5bdbd1870d6e5ecb91e5e0ed1
parent2c6068be6526c262706d8e78423c6aa1388f37d3 (diff)
downloadorg.eclipse.pdt-60e42eaa287de963b7fb4ec8e09e4f1d1620fd43.tar.gz
org.eclipse.pdt-60e42eaa287de963b7fb4ec8e09e4f1d1620fd43.tar.xz
org.eclipse.pdt-60e42eaa287de963b7fb4ec8e09e4f1d1620fd43.zip
Bug 536109 - Editor selection event problems
Use correct WTP API Signed-off-by: Dawid Pakuła <zulus@w3des.net>
-rw-r--r--plugins/org.eclipse.php.ui/plugin.xml16
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/adapter/DOMModelAdapterFactory.java94
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/configuration/PHPStructuredTextViewerConfiguration.java7
3 files changed, 35 insertions, 82 deletions
diff --git a/plugins/org.eclipse.php.ui/plugin.xml b/plugins/org.eclipse.php.ui/plugin.xml
index 570fc25fe..f61717f9f 100644
--- a/plugins/org.eclipse.php.ui/plugin.xml
+++ b/plugins/org.eclipse.php.ui/plugin.xml
@@ -794,15 +794,15 @@
adaptableType="org.eclipse.php.internal.core.documentModel.DOMModelForPHP"
class="org.eclipse.php.internal.ui.spelling.SpellcheckDelegateAdapterFactory">
<adapter
- type="org.eclipse.wst.sse.ui.internal.spelling.ISpellcheckDelegate"/>
+ type="org.eclipse.wst.sse.ui.internal.spelling.ISpellcheckDelegate"/>
+ </factory>
+ <factory
+ adaptableType="org.eclipse.php.internal.core.documentModel.DOMModelForPHP"
+ class="org.eclipse.php.internal.ui.editor.adapter.DOMModelAdapterFactory">
+ <adapter
+ type="org.eclipse.wst.sse.ui.SelectionConverter">
+ </adapter>
</factory>
- <factory
- adaptableType="org.eclipse.php.internal.core.documentModel.DOMModelForPHP"
- class="org.eclipse.php.internal.ui.editor.adapter.DOMModelAdapterFactory">
- <adapter
- type="org.eclipse.wst.sse.ui.internal.editor.SelectionConvertor">
- </adapter>
- </factory>
</extension>
<!-- Editor actionsets -->
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/adapter/DOMModelAdapterFactory.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/adapter/DOMModelAdapterFactory.java
index 7e706618e..9a3406198 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/adapter/DOMModelAdapterFactory.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/adapter/DOMModelAdapterFactory.java
@@ -14,28 +14,24 @@ package org.eclipse.php.internal.ui.editor.adapter;
import java.util.Enumeration;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.dltk.core.IModelElement;
-import org.eclipse.dltk.core.ISourceModule;
-import org.eclipse.dltk.core.ISourceReference;
-import org.eclipse.dltk.core.ModelException;
+import org.eclipse.dltk.core.*;
import org.eclipse.dltk.internal.core.BufferManager;
import org.eclipse.dltk.internal.ui.editor.DocumentAdapter;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
import org.eclipse.php.internal.core.documentModel.DOMModelForPHP;
import org.eclipse.php.internal.ui.Logger;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.ui.internal.editor.SelectionConvertor;
+import org.eclipse.wst.sse.ui.SelectionConverter;
public class DOMModelAdapterFactory implements IAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
- if (SelectionConvertor.class.equals(adapterType)) {
+ if (SelectionConverter.class.equals(adapterType)) {
return (T) new PHPSelectionConverter();
}
return null;
@@ -43,64 +39,10 @@ public class DOMModelAdapterFactory implements IAdapterFactory {
@Override
public Class<?>[] getAdapterList() {
- return new Class<?>[] { SelectionConvertor.class };
+ return new Class<?>[] { SelectionConverter.class };
}
- public class ModelSelection implements IndexedRegion, IAdaptable {
- private IModelElement modelElement;
-
- public ModelSelection(IModelElement modelElement) {
- this.modelElement = modelElement;
- }
-
- public IModelElement getModelElement() {
- return modelElement;
- }
-
- @Override
- public boolean contains(int testPosition) {
- return getStartOffset() >= testPosition && getEndOffset() <= testPosition;
- }
-
- @Override
- public int getEndOffset() {
- return getStartOffset() + getLength();
- }
-
- @Override
- public int getStartOffset() {
- try {
- return ((ISourceReference) modelElement).getSourceRange().getOffset();
- } catch (ModelException e) {
- Logger.logException(e);
- }
-
- return 0;
- }
-
- @Override
- public int getLength() {
- try {
- return ((ISourceReference) modelElement).getSourceRange().getLength();
- } catch (ModelException e) {
- Logger.logException(e);
- }
-
- return 0;
- }
-
- @Override
- public <T> T getAdapter(Class<T> adapter) {
- if (IResource.class.equals(adapter)) {
- return (T) modelElement.getResource();
- } else if (IModelElement.class.equals(adapter)) {
- return (T) modelElement;
- }
- return null;
- }
- }
-
- private class PHPSelectionConverter extends SelectionConvertor {
+ private class PHPSelectionConverter extends SelectionConverter {
@Override
public Object[] getElements(IStructuredModel model, int start, int end) {
DOMModelForPHP impl = (DOMModelForPHP) model;
@@ -120,8 +62,12 @@ public class DOMModelAdapterFactory implements IAdapterFactory {
if (modelElement != null) {
try {
IModelElement elementAt = modelElement.getElementAt(start);
+ if (elementAt instanceof IField
+ && (elementAt.getParent() instanceof IMethod || elementAt.getParent() instanceof IType)) {
+ elementAt = elementAt.getParent();
+ }
if (elementAt instanceof ISourceReference) {
- return new Object[] { new ModelSelection(elementAt) };
+ return new Object[] { elementAt };
}
} catch (ModelException e) {
Logger.logException(e);
@@ -130,6 +76,20 @@ public class DOMModelAdapterFactory implements IAdapterFactory {
return super.getElements(model, start, end);
}
+
+ @Override
+ public IRegion getRegion(Object o) {
+ if (o instanceof ISourceReference) {
+ ISourceRange sourceRange;
+ try {
+ sourceRange = ((ISourceReference) o).getSourceRange();
+ return new Region(sourceRange.getOffset(), sourceRange.getLength());
+ } catch (ModelException e) {
+ Logger.logException(e);
+ }
+ }
+ return super.getRegion(o);
+ }
}
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/configuration/PHPStructuredTextViewerConfiguration.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/configuration/PHPStructuredTextViewerConfiguration.java
index 889418748..f7475d280 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/configuration/PHPStructuredTextViewerConfiguration.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/configuration/PHPStructuredTextViewerConfiguration.java
@@ -54,7 +54,6 @@ import org.eclipse.php.internal.ui.autoEdit.MainAutoEditStrategy;
import org.eclipse.php.internal.ui.doubleclick.PHPDoubleClickStrategy;
import org.eclipse.php.internal.ui.editor.PHPStructuredRegionProcessor;
import org.eclipse.php.internal.ui.editor.PHPStructuredTextViewer;
-import org.eclipse.php.internal.ui.editor.adapter.DOMModelAdapterFactory.ModelSelection;
import org.eclipse.php.internal.ui.editor.contentassist.PHPCompletionProcessor;
import org.eclipse.php.internal.ui.editor.contentassist.PHPContentAssistant;
import org.eclipse.php.internal.ui.editor.highlighter.LineStyleProviderForPHP;
@@ -169,9 +168,6 @@ public class PHPStructuredTextViewerConfiguration extends StructuredTextViewerCo
if (element instanceof IModelElement) {
return parentProvider.getText(element);
}
- if (element instanceof ModelSelection) {
- return parentProvider.getText(((ModelSelection) element).getModelElement());
- }
StringBuilder s = new StringBuilder();
Node node = (Node) element;
@@ -198,9 +194,6 @@ public class PHPStructuredTextViewerConfiguration extends StructuredTextViewerCo
if (element instanceof IModelElement) {
return parentProvider.getImage(element);
}
- if (element instanceof ModelSelection) {
- return parentProvider.getImage(((ModelSelection) element).getModelElement());
- }
if (element instanceof ElementImplForPHP) {
return null;
}