Author: vrubezhny
Date: 2012-01-30 14:20:43 -0500 (Mon, 30 Jan 2012)
New Revision: 38289
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassMethodHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkDetector.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IExclusiblePartitionerRecognition.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitionRecognizer.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JumpToHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/LinkHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/RelativeLinkHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/XModelBasedHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLClassHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLContextParamLinkHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeNameHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeValueHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementNameHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLJumpToHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLLinkHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLRootHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTagAttributeValueHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTextHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/AbstractBaseHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/BaseHyperlinkDetector.java
Log:
JBIDE-10621
Redesign HyperlinkDetector so that partitioning and hyperlinks not do twice the same job.
Hyperlinks and Hyperlink Partitioners are redesigned due to exclude duplication work on
regions calculation.
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -35,7 +35,6 @@
import org.jboss.tools.common.el.core.GlobalELReferenceList;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.resref.core.ResourceReference;
@@ -49,11 +48,9 @@
@SuppressWarnings("restriction")
abstract public class AbstractHyperlink extends AbstractBaseHyperlink implements
IHyperlink {
public static final String DOLLAR_PREFIX = "${"; //$NON-NLS-1$
-
private static final String SUFFIX = "}"; //$NON-NLS-1$
-
public static final String SHARP_PREFIX = "#{"; //$NON-NLS-1$
-
+
public static XModel getXModel(IFile file) {
if (file == null)
return null;
@@ -155,8 +152,10 @@
return EclipseResourceUtil.getFile(path);
}
- abstract protected IRegion doGetHyperlinkRegion(int offset);
-
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ return hyperlinkRegion;
+ }
+
abstract protected void doHyperlink(IRegion region);
protected IFile getFileFromProject(String fileName) {
@@ -335,5 +334,4 @@
public IFile getReadyToOpenFile(){
return null;
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -28,8 +28,8 @@
*/
public abstract class AbstractHyperlinkPartitioner implements IHyperlinkPartitioner {
- public String getChildPartitionType(IDocument document, IHyperlinkRegion superRegion)
{
- IHyperlinkRegion childRegion = parse(document, superRegion);
+ public IHyperlinkRegion getChildPartitionRegion(IDocument document, int offset,
IHyperlinkRegion superRegion) {
+ IHyperlinkRegion childRegion = parse(document, offset, superRegion);
if (childRegion == null) return null;
HyperlinkPartitionerDefinition[] hyperlinkPartitionerDefinitions =
HyperlinkPartitionerBuilder.getInstance().getHyperlinkPartitionerDefinitions(childRegion.getContentType(),
childRegion.getType(), childRegion.getAxis());
@@ -45,18 +45,18 @@
for(int i=0; sortedPartitioners != null &&
i<sortedPartitioners.length; i++) {
IHyperlinkPartitioner partitioner = sortedPartitioners[i];
if((!(partitioner instanceof IHyperlinkPartitionRecognizer)) ||
- ((IHyperlinkPartitionRecognizer)partitioner).recognize(document,
childRegion)) {
+ ((IHyperlinkPartitionRecognizer)partitioner).recognize(document, offset,
childRegion)) {
if (partitioner instanceof IExclusiblePartitionerRecognition) {
IExclusiblePartitionerRecognition epr =
(IExclusiblePartitionerRecognition)partitioner;
- IHyperlinkPartitioner replacement =
findExclusionPartitioner(epr.getExclusionPartitionType(), hyperlinkPartitionerDefinitions,
document, childRegion);
+ IHyperlinkPartitioner replacement =
findExclusionPartitioner(epr.getExclusionPartitionType(), hyperlinkPartitionerDefinitions,
document, offset, childRegion);
if (replacement != null)
- return replacement.getChildPartitionType(document, childRegion);
+ return replacement.getChildPartitionRegion(document, offset,
childRegion);
}
- return partitioner.getChildPartitionType(document, childRegion);
+ return partitioner.getChildPartitionRegion(document, offset,
childRegion);
}
}
- return childRegion.getType();
+ return childRegion;
}
protected Sorter createSorter() {
@@ -94,12 +94,12 @@
}
- IHyperlinkPartitioner findExclusionPartitioner (String partitionType,
HyperlinkPartitionerDefinition[] hyperlinkPartitionerDefinitions, IDocument document,
IHyperlinkRegion region) {
+ IHyperlinkPartitioner findExclusionPartitioner (String partitionType,
HyperlinkPartitionerDefinition[] hyperlinkPartitionerDefinitions, IDocument document, int
offset, IHyperlinkRegion region) {
for(int i=0; i<hyperlinkPartitionerDefinitions.length; i++) {
HyperlinkPartitionerDefinition def = hyperlinkPartitionerDefinitions[i];
IHyperlinkPartitioner partitioner = def.createHyperlinkPartitioner();
if((partitioner instanceof IExclusiblePartitionerRecognition) &&
- ((IExclusiblePartitionerRecognition)partitioner).excludes(partitionType,
document, region)) {
+ ((IExclusiblePartitionerRecognition)partitioner).excludes(partitionType,
document, offset, region)) {
return partitioner;
}
}
@@ -110,7 +110,7 @@
return StructuredModelManager.getModelManager();
}
- protected abstract IHyperlinkRegion parse(IDocument document, IHyperlinkRegion
superRegion);
+ protected abstract IHyperlinkRegion parse(IDocument document, int offset,
IHyperlinkRegion superRegion);
protected String getAxis(IDocument document, IHyperlinkRegion superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
@@ -128,5 +128,4 @@
smw.dispose();
}
}
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -42,20 +42,12 @@
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
-import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
-import org.jboss.tools.common.text.ext.util.Utils;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -198,96 +190,16 @@
return null;
}
- IRegion fLastRegion = null;
/*
* (non-Javadoc)
*
- * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
- */
- protected IRegion doGetHyperlinkRegion(int offset) {
- fLastRegion = getRegion(offset);
- return fLastRegion;
- }
-
- public IRegion getRegion (int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null || !(n instanceof Text || n instanceof Attr)) return null;
-
- String text = null;
- int bStart = 0;
- int bEnd = 0;
-
- if (n instanceof Text) {
- int start = Utils.getValueStart(n);
- int end = Utils.getValueEnd(n);
- if (start < 0 || start > offset) return null;
-
- text = getDocument().get(start, end - start);
- bStart = offset - start;
- bEnd = offset - start;
- } else if (n instanceof Attr) {
- IDOMAttr attr = (IDOMAttr)n;
- int start = Utils.getValueStart(n);
- if(start < 0) return null;
-
- text = getDocument().get(start,
- attr.getValueRegionText().length());
- bStart = offset - start;
- bEnd = offset - start;
- }
- StringBuffer sb = new StringBuffer(text);
-
- while (bStart >= 0) {
- if (!Character.isJavaIdentifierPart(sb.charAt(bStart)) &&
- sb.charAt(bStart) != '.' && sb.charAt(bStart) != '_') {
- bStart++;
- break;
- }
-
- if (bStart == 0) break;
- bStart--;
- }
-
- while (bEnd < sb.length()) {
- if (!Character.isJavaIdentifierPart(sb.charAt(bEnd)) &&
- sb.charAt(bEnd) != '.' && sb.charAt(bEnd) != '_') {
- break;
- }
- bEnd++;
- }
-
- final int propStart = bStart + Utils.getValueStart(n);
- final int propLength = bEnd - bStart;
-
- if (propStart > offset || propStart + propLength < offset) return null;
-
- return new Region(propStart,propLength);
- } catch (BadLocationException x) {
- //ignore
- return null;
- } finally {
- smw.dispose();
- }
- }
-
- /*
- * (non-Javadoc)
- *
* @see IHyperlink#getHyperlinkText()
*/
public String getHyperlinkText() {
- String className = getClassName(fLastRegion);
+ String className = getClassName(getHyperlinkRegion());
if (className == null)
return MessageFormat.format(Messages.OpenA, Messages.Class);
return MessageFormat.format(Messages.OpenClass, className);
}
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassMethodHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassMethodHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/ClassMethodHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -42,7 +42,6 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -82,62 +81,7 @@
openFileFailed();
}
}
-
- protected IRegion fLastRegion = null;
- /**
- * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
- */
- protected IRegion doGetHyperlinkRegion(int offset) {
- fLastRegion = getRegion(offset);
- return fLastRegion;
- }
- private IRegion getRegion(int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null || !(n instanceof Attr || n instanceof Text)) return null;
-
- int start = Utils.getValueStart(n);
- int end = Utils.getValueEnd(n);
-
- if (start < 0 || start > offset || end < offset) return null;
-
- String text = getDocument().get(start, end - start);
- StringBuffer sb = new StringBuffer(text);
-
- //find start and end of path property
- int bStart = 0;
- int bEnd = text.length() - 1;
-
- while (bStart < bEnd && (Character.isWhitespace(sb.charAt(bStart))
- || sb.charAt(bStart) == '\"' || sb.charAt(bStart) ==
'\"')) {
- bStart++;
- }
- while (bEnd > bStart && (Character.isWhitespace(sb.charAt(bEnd))
- || sb.charAt(bEnd) == '\"' || sb.charAt(bEnd) == '\"')) {
- bEnd--;
- }
- bEnd++;
-
- int propStart = bStart + start;
- int propLength = bEnd - bStart;
- if (propStart > offset || propStart + propLength < offset) return null;
- IRegion region = new HyperlinkRegion(propStart, propLength);
- return region;
- } catch (BadLocationException x) {
- //ignore
- return null;
- } finally {
- smw.dispose();
- }
- }
-
protected IJavaElement searchForClassMethod(IJavaProject javaProject,
String className, String methodName) {
// Get the search pattern
@@ -234,5 +178,4 @@
smw.dispose();
}
}
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkDetector.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkDetector.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkDetector.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -20,7 +20,6 @@
import org.jboss.tools.common.text.ext.util.AxisUtil;
public class HyperlinkDetector extends BaseHyperlinkDetector {
-
private static HyperlinkDetector fInstance;
/**
@@ -40,10 +39,10 @@
* @param offset
* @return String partition types
*/
- protected String[] getPartitionTypes(IDocument document, int offset) {
+ protected IHyperlinkRegion[] getPartitions(IDocument document, int offset) {
String documentRegionType = null;
ITypedRegion region = null;
- ArrayList<String> types = new ArrayList<String>();
+ ArrayList<IHyperlinkRegion> regions = new ArrayList<IHyperlinkRegion>();
region = (document instanceof IDocumentExtension3 ?
((IDocumentExtension3)document).getDocumentPartitioner("org.eclipse.wst.sse.core.default_structured_text_partitioning").getPartition(offset)
: //$NON-NLS-1$
@@ -51,13 +50,13 @@
if (region != null) {
documentRegionType = region.getType();
-
String contentType = getContentType(document);
+ IHyperlinkRegion documentRegion = new HyperlinkRegion(region.getOffset(),
region.getLength(), null, contentType, region.getType());
HyperlinkPartitionerDefinition[] defs =
HyperlinkPartitionerBuilder.getInstance().getHyperlinkPartitionerDefinitions(contentType,
documentRegionType, null);
if(defs==null || defs.length==0) {
- types.add(documentRegionType);
+ regions.add(documentRegion);
} else {
for(int i=0; i<defs.length; i++) {
final ITypedRegion finalDocumentRegion = region;
@@ -71,16 +70,16 @@
finalContentType,
finalDocumentRegion.getType());
if((!(hyperlinkPartitioner instanceof IHyperlinkPartitionRecognizer)) ||
- ((IHyperlinkPartitionRecognizer)hyperlinkPartitioner).recognize(document,
startHyperlinkRegion)) {
- String type = hyperlinkPartitioner.getChildPartitionType(document,
startHyperlinkRegion);
- if(type!=null && !types.contains(type)) {
- types.add(type);
+ ((IHyperlinkPartitionRecognizer)hyperlinkPartitioner).recognize(document,
offset, startHyperlinkRegion)) {
+ IHyperlinkRegion childRegion =
hyperlinkPartitioner.getChildPartitionRegion(document, offset, startHyperlinkRegion);
+ if(childRegion!=null && !regions.contains(childRegion)) {
+ regions.add(childRegion);
}
}
}
}
}
- return types.toArray(new String[types.size()]);
+ return regions.toArray(new IHyperlinkRegion[regions.size()]);
}
static class HyperlinkDetectorHolder {
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IExclusiblePartitionerRecognition.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IExclusiblePartitionerRecognition.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IExclusiblePartitionerRecognition.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -14,5 +14,5 @@
public interface IExclusiblePartitionerRecognition {
String getExclusionPartitionType();
- boolean excludes(String partitionType, IDocument document, IHyperlinkRegion
superRegion);
+ boolean excludes(String partitionType, IDocument document, int offset, IHyperlinkRegion
superRegion);
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitionRecognizer.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitionRecognizer.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitionRecognizer.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -16,6 +16,5 @@
* @author Igels
*/
public interface IHyperlinkPartitionRecognizer {
-
- public boolean recognize(IDocument document, IHyperlinkRegion region);
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region);
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/IHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -16,6 +16,5 @@
* @author Igels
*/
public interface IHyperlinkPartitioner {
-
- public String getChildPartitionType(IDocument document, IHyperlinkRegion
superRegion);
+ public IHyperlinkRegion getChildPartitionRegion(IDocument document, int offset,
IHyperlinkRegion superRegion);
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JumpToHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JumpToHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JumpToHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -26,7 +26,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -144,66 +143,10 @@
return elements;
}
- /**
- * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
- */
- protected IRegion doGetHyperlinkRegion(int offset) {
- return getRegion(offset);
- }
-
- protected IRegion getRegion(int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null || !(n instanceof Text)) return null;
- int start = Utils.getValueStart(n);
- int end = Utils.getValueEnd(n);
-
- if (start < 0 || start > offset) return null;
-
- String attrText = getDocument().get(start, end - start);
- StringBuffer sb = new StringBuffer(attrText);
-
- //find start and end of path property
- int bStart = 0;
- int bEnd = attrText.length() - 1;
-
- while (bStart < bEnd &&
- (sb.charAt(bStart) == '\'' || sb.charAt(bStart) == '\"' ||
- Character.isWhitespace(sb.charAt(bStart)))) {
- bStart++;
- }
- while (bEnd > bStart &&
- (sb.charAt(bEnd) == '\'' || sb.charAt(bEnd) == '\"' ||
- Character.isWhitespace(sb.charAt(bEnd)))) {
- bEnd--;
- }
- bEnd++;
-
- final int propStart = bStart + start;
- final int propLength = bEnd - bStart;
-
- if (propStart > offset || propStart + propLength < offset) return null;
-
- return new Region(propStart,propLength);
- } catch (BadLocationException e) {
- openFileFailed();
- } finally {
- smw.dispose();
- }
- return null;
- }
-
/*
* (non-Javadoc)
*
* @see IHyperlink#getHyperlinkText()
*/
abstract public String getHyperlinkText();
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/LinkHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/LinkHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/LinkHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -27,12 +27,6 @@
import org.eclipse.ui.ide.IDE;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
-import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
-import org.jboss.tools.common.text.ext.util.Utils;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -43,7 +37,7 @@
* @see
com.ibm.sse.editor.AbstractHyperlink#doHyperlink(org.eclipse.jface.text.IRegion)
*/
protected void doHyperlink(IRegion region) {
-
+
String fileName = getFilePath(region);
IFile fileToOpen = getFileFromProject(fileName);
if (fileToOpen != null && fileToOpen.exists()) {
@@ -82,84 +76,13 @@
return filename;
}
- IRegion fLastRegion = null;
- /**
- * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
- */
- protected IRegion doGetHyperlinkRegion(int offset) {
- fLastRegion = getRegion(offset);
- return fLastRegion;
- }
-
- protected IRegion getRegion(int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null || !(n instanceof Attr || n instanceof Text)) return null;
-
- int start = Utils.getValueStart(n);
- int end = Utils.getValueEnd(n);
-
- if (start > offset || end < offset) return null;
-
- String text = getDocument().get(start, end - start);
- StringBuffer sb = new StringBuffer(text);
-
- int bStart = offset - start;
- //find start and end of path property
- while (bStart >= 0) {
- if (!Character.isJavaIdentifierPart(sb.charAt(bStart)) &&
- sb.charAt(bStart) != '\\' && sb.charAt(bStart) != '/'
&&
- sb.charAt(bStart) != ':' && sb.charAt(bStart) != '-'
&&
- sb.charAt(bStart) != '.' && sb.charAt(bStart) != '_'
&&
- sb.charAt(bStart) != '%' && sb.charAt(bStart) != '?'
&&
- sb.charAt(bStart) != '&' && sb.charAt(bStart) != '=')
{
- bStart++;
- break;
- }
-
- if (bStart == 0) break;
- bStart--;
- }
- // find end of bean property
- int bEnd = offset - start;
- while (bEnd < sb.length()) {
- if (!Character.isJavaIdentifierPart(sb.charAt(bEnd)) &&
- sb.charAt(bEnd) != '\\' && sb.charAt(bEnd) != '/'
&&
- sb.charAt(bEnd) != ':' && sb.charAt(bEnd) != '-'
&&
- sb.charAt(bEnd) != '.' && sb.charAt(bEnd) != '_'
&&
- sb.charAt(bEnd) != '%' && sb.charAt(bEnd) != '?'
&&
- sb.charAt(bEnd) != '&' && sb.charAt(bEnd) != '=') {
- break;
- }
- bEnd++;
- }
-
- int propStart = bStart + start;
- int propLength = bEnd - bStart;
- if (propStart > offset + 1 || propStart + propLength < offset) return null;
- IRegion region = new HyperlinkRegion(propStart, propLength);
- return region;
- } catch (BadLocationException x) {
- //ignore
- return null;
- } finally {
- smw.dispose();
- }
- }
-
/*
* (non-Javadoc)
*
* @see IHyperlink#getHyperlinkText()
*/
public String getHyperlinkText() {
- String filePath = getFilePath(fLastRegion);
+ String filePath = getFilePath(getHyperlinkRegion());
if (filePath == null)
return MessageFormat.format(Messages.OpenA, Messages.File);
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/RelativeLinkHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/RelativeLinkHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/RelativeLinkHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -17,17 +17,10 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.ide.IDE;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
-import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
-import org.jboss.tools.common.text.ext.util.Utils;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -75,75 +68,16 @@
return super.getFileFromProject(updateFilenameForModel(fileName, project));
}
- IRegion fLastRegion = null;
- /**
- * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
- */
- protected IRegion doGetHyperlinkRegion(int offset) {
- fLastRegion = getRegion(offset);
- return fLastRegion;
- }
-
- protected IRegion getRegion(int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null || !(n instanceof Attr || n instanceof Text)) return null;
-
- int start = Utils.getValueStart(n);
- int end = Utils.getValueEnd(n);
-
- if (start < 0 || start > offset || end < offset) return null;
-
- String text = getDocument().get(start, end - start);
- StringBuffer sb = new StringBuffer(text);
-
- //find start and end of path property
- int bStart = 0;
- int bEnd = text.length() - 1;
-
- while (bStart < bEnd &&
- (sb.charAt(bStart) == '\'' || sb.charAt(bStart) == '\"' ||
- Character.isWhitespace(sb.charAt(bStart)))) {
- bStart++;
- }
- while (bEnd > bStart &&
- (sb.charAt(bEnd) == '\'' || sb.charAt(bEnd) == '\"' ||
- Character.isWhitespace(sb.charAt(bEnd)))) {
- bEnd--;
- }
- bEnd++;
-
- final int propStart = bStart + start;
- final int propLength = bEnd - bStart;
-
- if (propStart > offset || propStart + propLength < offset) return null;
-
- return new Region(propStart,propLength);
- } catch (BadLocationException x) {
- //ignore
- return null;
- } finally {
- smw.dispose();
- }
- }
-
/*
* (non-Javadoc)
*
* @see IHyperlink#getHyperlinkText()
*/
public String getHyperlinkText() {
- String filePath = getFilePath(fLastRegion);
+ String filePath = getFilePath(getHyperlinkRegion());
if (filePath == null)
return MessageFormat.format(Messages.OpenA, Messages.File);
return MessageFormat.format(Messages.OpenFile, filePath);
}
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/XModelBasedHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/XModelBasedHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/XModelBasedHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
@@ -14,18 +14,10 @@
import java.util.Properties;
import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.project.IPromptingProvider;
import org.jboss.tools.common.model.project.PromptingProviderFactory;
-import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
-import org.jboss.tools.common.text.ext.util.Utils;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -63,59 +55,4 @@
protected abstract String getRequestMethod();
protected abstract Properties getRequestProperties(IRegion region);
-
- protected IRegion fLastRegion = null;
- /**
- * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
- */
- protected IRegion doGetHyperlinkRegion(int offset) {
- fLastRegion = getRegion(offset);
- return fLastRegion;
- }
-
- protected IRegion getRegion (int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null || !(n instanceof Attr || n instanceof Text)) return null;
-
- int start = Utils.getValueStart(n);
- int end = Utils.getValueEnd(n);
-
- if (start > offset || end < offset) return null;
-
- String text = getDocument().get(start, end - start);
- StringBuffer sb = new StringBuffer(text);
-
- //find start and end of class property
- int bStart = 0;
- int bEnd = text.length() - 1;
-
- while (bStart < bEnd && (Character.isWhitespace(sb.charAt(bStart))
- || sb.charAt(bStart) == '\"' || sb.charAt(bStart) ==
'\"')) {
- bStart++;
- }
- while (bEnd > bStart && (Character.isWhitespace(sb.charAt(bEnd))
- || sb.charAt(bEnd) == '\"' || sb.charAt(bEnd) == '\"')) {
- bEnd--;
- }
- bEnd++;
-
- final int propStart = bStart + start;
- final int propLength = bEnd - bStart;
-
- if (propStart > offset || propStart + propLength < offset) return null;
- return new Region(propStart,propLength);
- } catch (BadLocationException x) {
- //ignore
- return null;
- } finally {
- smw.dispose();
- }
- }
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -14,29 +14,14 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.common.text.ext.util.Utils;
-import org.w3c.dom.Node;
public class IncludeHyperlink extends AbstractHyperlink {
private String hyperlinkText = ""; //$NON-NLS-1$
@Override
- protected IRegion doGetHyperlinkRegion(int offset) {
- Node n = IncludeHyperlinkPartitioner.getNode(getDocument(), offset);
-
- int start = Utils.getValueStart(n);
- if(start < 0) return null;
- int end = Utils.getValueEnd(n);
-
- Region region = new Region(start, end-start);
-
- return region;
- }
-
- @Override
protected void doHyperlink(IRegion region) {
if (region == null)
return;
@@ -63,5 +48,4 @@
public String getHyperlinkText() {
return hyperlinkText;
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/IncludeHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -40,10 +40,10 @@
}
@Override
- protected IHyperlinkRegion parse(IDocument document,
+ protected IHyperlinkRegion parse(IDocument document, int offset,
IHyperlinkRegion superRegion) {
- Node node = getNode(document, superRegion.getOffset());
+ Node node = getNode(document, offset);
if(!URL_NAME.equals(node.getNodeName()))
return null;
@@ -59,5 +59,4 @@
axis, contentType, INCLUDE_FILE_PARTITION);
return hyperRegion;
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2009 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2009-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -20,39 +20,18 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
-import org.w3c.dom.Node;
public class PortletHyperlink extends AbstractHyperlink {
private static final String PROP_EXTENSION = ".properties"; //$NON-NLS-1$
private String hyperlinkText = ""; //$NON-NLS-1$
-
private String partitionType = null;
@Override
- protected IRegion doGetHyperlinkRegion(int offset) {
- Node node = PortletHyperlinkPartitioner.getNode(getDocument(),
- offset);
- partitionType = PortletHyperlinkPartitioner.getType(node);
- if (partitionType == null)
- return null;
-
- IndexedRegion text = (IndexedRegion) node;
-
- int regLength = text.getLength();
- int regOffset = text.getStartOffset();
-
- Region region = new Region(regOffset, regLength);
- return region;
- }
-
- @Override
protected void doHyperlink(IRegion region) {
if (region == null)
return;
@@ -115,7 +94,6 @@
openFileFailed();
}
-
private IProject getProject() {
IFile documentFile = getFile();
if (documentFile == null || !documentFile.isAccessible())
@@ -130,6 +108,4 @@
public String getHyperlinkText() {
return hyperlinkText;
}
-
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2009 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2009-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -26,7 +26,6 @@
public static final String PORTLET_RESOURCE_BUNDLE_PARTITION =
"org.jboss.tools.common.text.ext.hyperlink.xml.PORTLET_RESOURCE"; //$NON-NLS-1$
static final String textNodeName = "#text"; //$NON-NLS-1$
-
static final String portletNodeName = "portlet"; //$NON-NLS-1$
static final String portletClassNodeName = "portlet-class"; //$NON-NLS-1$
static final String portletResourceBundleNodeName = "resource-bundle";
//$NON-NLS-1$
@@ -69,7 +68,7 @@
}
@Override
- protected IHyperlinkRegion parse(IDocument document,
+ protected IHyperlinkRegion parse(IDocument document, int offset,
IHyperlinkRegion superRegion) {
Node node = getNode(document, superRegion.getOffset());
String type = getType(node);
@@ -79,14 +78,13 @@
IndexedRegion text = (IndexedRegion) node;
int length = text.getLength();
- int offset = text.getStartOffset();
+ int startOffset = text.getStartOffset();
String contentType = superRegion.getContentType();
String axis = getAxis(document, superRegion);
- IHyperlinkRegion hyperRegion = new HyperlinkRegion(offset, length,
+ IHyperlinkRegion hyperRegion = new HyperlinkRegion(startOffset, length,
axis, contentType, type);
return hyperRegion;
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLClassHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLClassHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLClassHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,27 +1,26 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -32,26 +31,21 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
-// if (!recognize(document, superRegion)) return null;
- IHyperlinkRegion r = getRegion(document, superRegion.getOffset());
+ IHyperlinkRegion r = getRegion(document, offset);
if (r == null) return null;
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = XML_CLASS_PARTITION;
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ return new HyperlinkRegion(r.getOffset(), r.getLength(), axis, contentType, type);
} finally {
smw.dispose();
}
@@ -138,5 +132,4 @@
smw.dispose();
}
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLContextParamLinkHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLContextParamLinkHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLContextParamLinkHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -14,16 +14,15 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -33,26 +32,22 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
- if (!recognize(document, superRegion)) return null;
- IRegion r = getRegion(document, superRegion.getOffset());
+ if (!recognize(document, offset, superRegion)) return null;
+ IRegion r = getRegion(document, offset);
if (r == null) return null;
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = getPartitionType();
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
-
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+
+ return new HyperlinkRegion(r.getOffset(), r.getLength(), axis, contentType, type);
} finally {
smw.dispose();
}
@@ -108,5 +103,4 @@
smw.dispose();
}
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,19 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
-import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
-import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
import org.w3c.dom.Attr;
@@ -22,71 +19,7 @@
import org.w3c.dom.Node;
public class XMLDoctypeHyperlink extends XMLXmlNsHyperlink {
-
- protected IRegion getRegion(int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
- if (n instanceof Attr) n = ((Attr)n).getOwnerElement();
- if ((n == null) || !(n instanceof DocumentType)) return null;
-
- int start = Utils.getValueStart(n);
- if(start < 0) return null;
- int end = Utils.getValueEnd(n);
-
- DocumentType node = (DocumentType)n;
-
- String text = ""; //$NON-NLS-1$
- try {
- text = getDocument().get(start, end - start);
- } catch (BadLocationException x) {
- ExtensionsPlugin.getPluginLog().logError(x);
- };
- String publicId = (node.getPublicId() == null ? "" : node.getPublicId());
//$NON-NLS-1$
- String systemId = (node.getSystemId() == null ? "" : node.getSystemId());
//$NON-NLS-1$
-
- int valueStart = -1;
- int valueLength = 0;
-
- int index = -1;
-
- if (publicId.length() > 0) {
- index = text.indexOf(publicId);
- if (offset >= start + index && offset < start + index +
publicId.length()) {
- valueStart = start + index;
- valueLength = publicId.length();
- }
- }
- if (valueStart == -1) {
- if (systemId.length() > 0) {
- index = text.indexOf(systemId);
- if (systemId.length() > 0 && offset >= start + index &&
offset < start + index + systemId.length()) {
- valueStart = start + index;
- valueLength = systemId.length();
- }
- }
- }
- if (valueStart == -1) {
- valueStart = start;
- valueLength = end - start;
- }
- final int propStart = valueStart;
- final int propLength = valueLength;
-
- if (propStart > offset || propStart + propLength < offset) return null;
-
- return new Region(propStart,propLength);
- } finally {
- smw.dispose();
- }
-
- }
-
protected String getPublicId(IRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
@@ -124,6 +57,4 @@
smw.dispose();
}
}
-
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLDoctypeHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,26 +1,26 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Node;
-
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Node;
/**
* @author Jeremy
@@ -32,28 +32,49 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Node n = Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof DocumentType)) return null;
int start = Utils.getValueStart(n);
int end = Utils.getValueEnd(n);
if(end < 0) return null;
+ String text = document.get(start, end - start);
+ StringBuffer sb = new StringBuffer(text);
+
+ //find start and end of property value
+ int bStart = 0;
+ int bEnd = text.length() - 1;
+
+ while (bStart < bEnd && (Character.isWhitespace(sb.charAt(bStart))
+ || sb.charAt(bStart) == '\"' || sb.charAt(bStart) ==
'\"')) {
+ bStart++;
+ }
+ while (bEnd > bStart && (Character.isWhitespace(sb.charAt(bEnd))
+ || sb.charAt(bEnd) == '\"' || sb.charAt(bEnd) == '\"')) {
+ bEnd--;
+ }
+ bEnd++;
+
+ final int propStart = bStart + start;
+ final int propLength = bEnd - bStart;
+
+ if (propStart > offset || propStart + propLength < offset) return null;
+
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = XML_DOCTYPE_PARTITION;
- int length = end - start - (superRegion.getOffset() - start);
- int offset = superRegion.getOffset();
-
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+
+ return new HyperlinkRegion(propStart, propLength, axis, contentType, type);
+ } catch (BadLocationException e) {
+ return null;
} finally {
smw.dispose();
}
@@ -79,14 +100,14 @@
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof DocumentType)) return false;
return true;
@@ -94,5 +115,4 @@
smw.dispose();
}
}
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeNameHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeNameHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeNameHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -23,7 +23,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-
/**
* @author Jeremy
*/
@@ -37,14 +36,14 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Node n = Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (n == null || !(n instanceof Attr)) return null;
int start = (n instanceof IDOMAttr) ? ((IDOMAttr)n).getNameRegionStartOffset() : -1;
int end = (n instanceof IDOMAttr) ? ((IDOMAttr)n).getNameRegionEndOffset() : -1;
@@ -52,11 +51,8 @@
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = getPartitionType();
- int length = end - start - (superRegion.getOffset() - start);
- int offset = superRegion.getOffset();
-
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+
+ return new HyperlinkRegion(start, end - start, axis, contentType, type);
} finally {
smw.dispose();
}
@@ -65,18 +61,18 @@
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof Attr)) return false;
int start = (n instanceof IDOMAttr) ? ((IDOMAttr)n).getNameRegionStartOffset() : -1;
int end = (n instanceof IDOMAttr) ? ((IDOMAttr)n).getNameRegionEndOffset() : -1;
- if (start < 0 || start > region.getOffset() || end < region.getOffset())
+ if (start < 0 || start > offset || end < offset)
return false;
return true;
@@ -85,13 +81,11 @@
}
}
- public boolean excludes(String partitionType, IDocument document, IHyperlinkRegion
superRegion) {
+ public boolean excludes(String partitionType, IDocument document, int offset,
IHyperlinkRegion superRegion) {
return false;
}
public String getExclusionPartitionType() {
return getPartitionType();
}
-
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeValueHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeValueHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementAttributeValueHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,16 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
+import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IExclusiblePartitionerRecognition;
@@ -22,7 +24,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-
/**
* @author Jeremy
*/
@@ -36,26 +37,49 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Node n = Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (n == null || !(n instanceof Attr)) return null;
int start = Utils.getValueStart(n);
int end = Utils.getValueEnd(n);
+ String text = document.get(start, end - start);
+ StringBuffer sb = new StringBuffer(text);
+
+ //find start and end of property value
+ int bStart = 0;
+ int bEnd = text.length() - 1;
+
+ while (bStart < bEnd && (Character.isWhitespace(sb.charAt(bStart))
+ || sb.charAt(bStart) == '\"' || sb.charAt(bStart) ==
'\"')) {
+ bStart++;
+ }
+ while (bEnd > bStart && (Character.isWhitespace(sb.charAt(bEnd))
+ || sb.charAt(bEnd) == '\"' || sb.charAt(bEnd) == '\"')) {
+ bEnd--;
+ }
+ bEnd++;
+
+ final int propStart = bStart + start;
+ final int propLength = bEnd - bStart;
+
+ if (propStart > offset || propStart + propLength < offset) return null;
+
+
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = getPartitionType();
- int length = end - start - (superRegion.getOffset() - start);
- int offset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ return new HyperlinkRegion(propStart, propLength, axis, contentType, type);
+ } catch (BadLocationException e) {
+ ExtensionsPlugin.getPluginLog().logError(e);
+ return null;
} finally {
smw.dispose();
}
@@ -64,18 +88,18 @@
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof Attr)) return false;
int start = Utils.getValueStart(n);
int end = Utils.getValueEnd(n);
- if (start < 0 || start > region.getOffset() || end < region.getOffset())
+ if (start < 0 || start > offset || end < offset)
return false;
return true;
@@ -84,13 +108,11 @@
}
}
- public boolean excludes(String partitionType, IDocument document, IHyperlinkRegion
superRegion) {
+ public boolean excludes(String partitionType, IDocument document, int offset,
IHyperlinkRegion superRegion) {
return false;
}
public String getExclusionPartitionType() {
return getPartitionType();
}
-
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,27 +1,26 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
import org.eclipse.jface.text.IDocument;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
/**
* @author Jeremy
@@ -33,14 +32,14 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Node n = Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (n == null || !(n instanceof Attr || n instanceof Element) ) return null;
Node node = (Node)(n instanceof Attr ? ((Attr)n).getOwnerElement() :
n.getParentNode());
@@ -51,11 +50,8 @@
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = XML_ELEMENT_PARTITION;
- int length = end - start - (superRegion.getOffset() - start);
- int offset = superRegion.getOffset();
-
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+
+ return new HyperlinkRegion(start, end - start, axis, contentType, type);
} finally {
smw.dispose();
}
@@ -64,14 +60,14 @@
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof Attr || n instanceof Element)) return false;
return true;
@@ -79,5 +75,4 @@
smw.dispose();
}
}
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementNameHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementNameHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLElementNameHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -30,26 +30,23 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Node n = Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (n == null || !(n instanceof IDOMElement)) return null;
- IHyperlinkRegion r = getRegion(document, superRegion.getOffset());
- if (r == null) return null;
+ IHyperlinkRegion r = getRegion(document, offset);
+ if (r == null) return null;// document.get(r.getOffset(), r.getLength())
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = XML_ELEMENT_NAME_PARTITION;
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
-
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+
+ return new HyperlinkRegion(r.getOffset(), r.getLength(), axis, contentType, type);
} finally {
smw.dispose();
}
@@ -73,25 +70,23 @@
if (nameStart > offset || nameEnd <= offset) return null;
- IHyperlinkRegion region = new HyperlinkRegion(nameStart, nameEnd - nameStart, null,
null, null);
- return region;
+ return new HyperlinkRegion(nameStart, nameEnd - nameStart, null, null, null);
} finally {
smw.dispose();
}
-
}
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof IDOMElement)) return false;
IDOMElement elem = (IDOMElement)n;
@@ -99,10 +94,9 @@
int start = elem.getStartOffset();
int nameStart = start + (elem.isEndTag() ? "</" :
"<").length(); //$NON-NLS-1$ //$NON-NLS-2$
int nameEnd = nameStart + tagName.length();
- return (region.getOffset() >= nameStart && region.getOffset() <=
nameEnd);
+ return (offset >= nameStart && offset <= nameEnd);
} finally {
smw.dispose();
}
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLJumpToHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLJumpToHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLJumpToHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -18,17 +18,16 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -43,26 +42,22 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
- if (!recognize(document, superRegion)) return null;
- IRegion r = getRegion(document, superRegion.getOffset());
+ if (!recognize(document, offset, superRegion)) return null;
+ IRegion r = getRegion(document, offset);
if (r == null) return null;
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = getPartitionType();
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ return new HyperlinkRegion(r.getOffset(), r.getLength(), axis, contentType, type);
} finally {
smw.dispose();
}
@@ -76,7 +71,6 @@
if (xmlDocument == null) return null;
Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
if (n == null || !(n instanceof Text)) return null;
int start = Utils.getValueStart(n);
@@ -115,7 +109,6 @@
} finally {
smw.dispose();
}
-
}
protected String[] getValidAxisEndings() {
@@ -123,36 +116,36 @@
}
private boolean validAxis(Node n, String validAxisEnding) {
- if (validAxisEnding == null || validAxisEnding.lastIndexOf('/') == -1) return
false;
- StringTokenizer st = new StringTokenizer(validAxisEnding, "/");
//$NON-NLS-1$
- List<String> tokens = new ArrayList<String>();
- while (st.hasMoreTokens()) {
- tokens.add(st.nextToken());
- }
- if (tokens.size() == 0) return false;
- Node currentElement = n;
- for (int i = tokens.size() - 1; i >= 0; i--) {
- if (currentElement == null || !(currentElement instanceof Element))
- return false;
- String token = (String)tokens.get(i);
- if (!token.equals(currentElement.getNodeName()))
- return false;
- currentElement = currentElement.getParentNode();
- }
- return true;
+ if (validAxisEnding == null || validAxisEnding.lastIndexOf('/') == -1) return
false;
+ StringTokenizer st = new StringTokenizer(validAxisEnding, "/");
//$NON-NLS-1$
+ List<String> tokens = new ArrayList<String>();
+ while (st.hasMoreTokens()) {
+ tokens.add(st.nextToken());
+ }
+ if (tokens.size() == 0) return false;
+ Node currentElement = n;
+ for (int i = tokens.size() - 1; i >= 0; i--) {
+ if (currentElement == null || !(currentElement instanceof Element))
+ return false;
+ String token = (String)tokens.get(i);
+ if (!token.equals(currentElement.getNodeName()))
+ return false;
+ currentElement = currentElement.getParentNode();
+ }
+ return true;
}
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof Text)) return false;
@@ -167,5 +160,4 @@
smw.dispose();
}
}
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLLinkHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLLinkHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLLinkHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,30 +1,28 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -33,26 +31,21 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
-// if (!recognize(document, superRegion)) return null;
- IRegion r = getRegion(document, superRegion.getOffset());
+ IRegion r = getRegion(document, offset);
if (r == null) return null;
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = getPartitionType();
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ return new HyperlinkRegion(r.getOffset(), r.getLength(), axis, contentType, type);
} finally {
smw.dispose();
}
@@ -74,37 +67,60 @@
int start = Utils.getValueStart(n);
int end = Utils.getValueEnd(n);
- if (start > offset || end < offset) return null;
-
String text = document.get(start, end - start);
StringBuffer sb = new StringBuffer(text);
- //find start and end of path property
- int bStart = 0;
- int bEnd = text.length() - 1;
-
- while (bStart < bEnd &&
- (sb.charAt(bStart) == '\'' || sb.charAt(bStart) == '\"' ||
- Character.isWhitespace(sb.charAt(bStart)))) {
+ int bStart = 0;
+ int bEnd = sb.length();
+
+ // In case of attribute value we need to skip leading and ending quotes &&
whitespaces
+ while (bStart < bEnd && (sb.charAt(bStart) == '"' ||
sb.charAt(bStart) == '\'' ||
+ sb.charAt(bStart) == 0x09 || sb.charAt(bStart) == 0x0A ||
+ sb.charAt(bStart) == 0x0D || sb.charAt(bStart) == 0x20)) {
bStart++;
}
- while (bEnd > bStart &&
- (sb.charAt(bEnd) == '\'' || sb.charAt(bEnd) == '\"' ||
- Character.isWhitespace(sb.charAt(bEnd)))) {
+
+ while (bEnd - 1 > bStart && (sb.charAt(bEnd - 1) == '"' ||
sb.charAt(bEnd - 1) == '\'' ||
+ sb.charAt(bEnd - 1) == 0x09 || sb.charAt(bEnd - 1) == 0x0A ||
+ sb.charAt(bEnd - 1) == 0x0D || sb.charAt(bEnd - 1) == 0x20)) {
bEnd--;
}
- bEnd++;
+ if (start + bStart > offset || start + bEnd - 1 < offset) return null;
+
+ //find start and end of path property
+ while (bStart >= 0) {
+ if (!Character.isJavaIdentifierPart(sb.charAt(bStart)) &&
+ sb.charAt(bStart) != '\\' && sb.charAt(bStart) != '/'
&&
+ sb.charAt(bStart) != ':' && sb.charAt(bStart) != '-'
&&
+ sb.charAt(bStart) != '.' && sb.charAt(bStart) != '_'
&&
+ sb.charAt(bStart) != '%' && sb.charAt(bStart) != '?'
&&
+ sb.charAt(bStart) != '&' && sb.charAt(bStart) != '=')
{
+ bStart++;
+ break;
+ }
+
+ if (bStart == 0) break;
+ bStart--;
+ }
+ // find end of bean property
+ bEnd = bStart;
+ while (bEnd < sb.length()) {
+ if (!Character.isJavaIdentifierPart(sb.charAt(bEnd)) &&
+ sb.charAt(bEnd) != '\\' && sb.charAt(bEnd) != '/'
&&
+ sb.charAt(bEnd) != ':' && sb.charAt(bEnd) != '-'
&&
+ sb.charAt(bEnd) != '.' && sb.charAt(bEnd) != '_'
&&
+ sb.charAt(bEnd) != '%' && sb.charAt(bEnd) != '?'
&&
+ sb.charAt(bEnd) != '&' && sb.charAt(bEnd) != '=') {
+ break;
+ }
+ bEnd++;
+ }
- final int propStart = bStart + start;
- final int propLength = bEnd - bStart;
+ int propStart = bStart + start;
+ int propLength = bEnd - bStart;
+ if (propStart > offset + 1 || propStart + propLength < offset) return null;
- // JBIDE-1736: do not detect XMLLink region for the offset that is more than
- // closing quote position of an attribute value.
- if (start + bEnd <= offset) return null;
-
- if (propStart > offset || propStart + propLength < offset) return null;
-
- return new Region(propStart,propLength);
+ return new HyperlinkRegion(propStart, propLength);
} catch (BadLocationException x) {
// Ignore
return null;
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLRootHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLRootHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLRootHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -35,16 +35,16 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
- if (!recognize(document, superRegion)) return null;
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
+ if (!recognize(document, offset, superRegion)) return null;
- String axis = computeAxis(document, superRegion.getOffset()) + "/";
//$NON-NLS-1$
+ String axis = computeAxis(document, offset) + "/"; //$NON-NLS-1$
String contentType = superRegion.getContentType();
String type = XML_ROOT_PARTITION;
- int length = superRegion.getLength();
- int offset = superRegion.getOffset();
+ int superLength = superRegion.getLength();
+ int superOffset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
+ IHyperlinkRegion region = new HyperlinkRegion(superOffset, superLength, axis,
contentType, type);
return region;
}
@@ -121,19 +121,18 @@
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
return n != null;
} finally {
smw.dispose();
}
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTagAttributeValueHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTagAttributeValueHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTagAttributeValueHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -14,15 +14,14 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
/**
* @author Jeremy
@@ -31,25 +30,21 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
- IRegion r = getRegion(document, superRegion.getOffset());
+ IRegion r = getRegion(document, offset);
if (r == null) return null;
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = getPartitionType();
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ return new HyperlinkRegion(r.getOffset(), r.getLength(), axis, contentType, type);
} finally {
smw.dispose();
}
@@ -102,7 +97,6 @@
} finally {
smw.dispose();
}
-
}
protected abstract String getPartitionType();
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTextHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTextHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLTextHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,26 +1,25 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
import org.eclipse.jface.text.IDocument;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
/**
* @author Jeremy
@@ -33,14 +32,14 @@
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
@Override
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Node n = Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (n == null || !(n instanceof Text)) return null;
String axis = getAxis(document, superRegion);
@@ -49,11 +48,8 @@
int start = Utils.getValueStart(n);
int end = Utils.getValueEnd(n);
if(start < 0 || end < start) return null;
- int length = end - start;
- int offset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ return new HyperlinkRegion(start, end - start, axis, contentType, type);
} finally {
smw.dispose();
}
@@ -62,14 +58,14 @@
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
return (n instanceof Text);
} finally {
smw.dispose();
@@ -79,5 +75,4 @@
protected String getPartitionType(String axis) {
return XML_TEXT_PARTITION;
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -18,7 +18,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
-import java.util.StringTokenizer;
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IStorage;
@@ -29,7 +28,6 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.eclipse.pde.internal.ui.editor.JarEntryEditorInput;
import org.eclipse.pde.internal.ui.editor.JarEntryFile;
import org.eclipse.ui.IEditorInput;
@@ -43,21 +41,15 @@
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.editors.text.ILocationProvider;
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
-import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
/**
* @author Jeremy
*/
public class XMLXmlNsHyperlink extends AbstractHyperlink {
-
-
class StorageEditorInput extends PlatformObject implements IStorageEditorInput,
IStorage, ILocationProvider {
private File fFile;
@@ -142,14 +134,10 @@
protected void doHyperlink(IRegion region) {
try {
-// IFile f = getFileFromCatalog(getURI(region));
-// IFile f = getFileFromCatalog(getPublicId(region), getSystemId(region));
-
String mappedSystemId = getMappedSystemIdFromCatalog(getPublicId(region),
getSystemId(region));
String filename = getFilenameFromMappedSystemId(mappedSystemId);
IEditorPart part = null;
if (filename != null) {
-// openFileInEditor(filename);
part = openExternalFile(filename);
if (part == null)
openFileFailed();
@@ -303,77 +291,16 @@
return fileName;
}
- IRegion fLastRegion = null;
- /**
- * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
- */
- protected IRegion doGetHyperlinkRegion(int offset) {
- fLastRegion = getRegion(offset);
- return fLastRegion;
- }
-
- protected IRegion getRegion(int offset) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- try {
- smw.init(getDocument());
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
- if (!(n instanceof IDOMAttr)) return null;
- IDOMAttr xmlnsAttr = (IDOMAttr)n;
- if (xmlnsAttr.getName() == null ||
- (!xmlnsAttr.getName().equals("xmlns") && //$NON-NLS-1$
- !xmlnsAttr.getName().startsWith("xmlns:") && //$NON-NLS-1$
- !xmlnsAttr.getName().endsWith(":schemaLocation") //$NON-NLS-1$
- )) return null;
-
- String text = xmlnsAttr.getValueRegionText();
- String value = Utils.trimQuotes(xmlnsAttr.getNodeValue());
- int start = xmlnsAttr.getValueRegionStartOffset();
-
- taglibLength = value.length();
- taglibOffset = start + text.indexOf(value);
-
- StringTokenizer tokenizer = new StringTokenizer(value);
-
- int newOffset = -1;
- int newLength = -1;
- if (tokenizer.countTokens() > 1) {
- while (tokenizer.hasMoreTokens()) {
- String next = tokenizer.nextToken();
- int nextStart = taglibOffset + value.indexOf(next);
- if (offset >= nextStart
- && offset <= nextStart + next.length()) {
- newOffset = nextStart;
- newLength = next.length();
- break;
- }
- }
- }
- if (newOffset != -1) {
- taglibLength = newLength;
- taglibOffset = newOffset;
- }
-
- return new Region(taglibOffset,taglibLength);
- } finally {
- smw.dispose();
- }
-
- }
-
/*
* (non-Javadoc)
*
* @see IHyperlink#getHyperlinkText()
*/
public String getHyperlinkText() {
- String uri = getURI(fLastRegion);
+ String uri = getURI(getHyperlinkRegion());
if (uri == null)
return MessageFormat.format(Messages.NotFound, "URI"); //$NON-NLS-1$
return MessageFormat.format(Messages.Open, uri);
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlinkPartitioner.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/XMLXmlNsHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
@@ -32,47 +32,45 @@
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ protected IHyperlinkRegion parse(IDocument document, int offset, IHyperlinkRegion
superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- Node n = Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof IDOMAttr)) return null;
IDOMAttr xmlnsAttr = (IDOMAttr)n;
if (xmlnsAttr.getName() == null ||
-// (!xmlnsAttr.getName().equals("xmlns") &&
(!xmlnsAttr.getName().startsWith("xmlns:") && //$NON-NLS-1$
!xmlnsAttr.getName().endsWith(":schemaLocation") //$NON-NLS-1$
)) return null;
String xmlns = xmlnsAttr.getValueRegionText();
+ int start = Utils.getValueStart(n);
+ int end = Utils.getValueEnd(n);
+
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = XML_XMLNS_PARTITION;
- int length = xmlns.length() - (superRegion.getOffset() -
xmlnsAttr.getValueRegionStartOffset());
- int offset = superRegion.getOffset();
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ return new HyperlinkRegion(start, end - start, axis, contentType, type);
} finally {
smw.dispose();
}
}
-
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
- public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
if (!(n instanceof IDOMAttr)) return false;
IDOMAttr xmlnsAttr = (IDOMAttr)n;
if (xmlnsAttr.getName() == null ||
@@ -87,5 +85,4 @@
smw.dispose();
}
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/AbstractBaseHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/AbstractBaseHyperlink.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/AbstractBaseHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -40,6 +40,7 @@
import org.eclipse.wst.sse.core.internal.util.URIResolver;
import org.eclipse.wst.sse.ui.internal.openon.ExternalFileEditorInput;
import org.eclipse.wst.sse.ui.internal.util.PlatformStatusLineUtil;
+import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
public abstract class AbstractBaseHyperlink {
@@ -47,8 +48,12 @@
public final String HTTP_PROTOCOL = "http://";//$NON-NLS-1$
+ protected IRegion hyperlinkRegion;
-
+ public void setRegion(IRegion region) {
+ this.hyperlinkRegion = region;
+ }
+
public AbstractBaseHyperlink() {
super();
}
@@ -258,8 +263,12 @@
* @see IHyperlink#getHyperlinkRegion()
*/
public IRegion getHyperlinkRegion() {
- IRegion region = doGetHyperlinkRegion(getOffset());
- return (region != null) ? region : new Region(getOffset(), 0);
+ if (hyperlinkRegion != null) {
+ return hyperlinkRegion;
+ }
+ hyperlinkRegion = (IHyperlinkRegion)doGetHyperlinkRegion(getOffset());
+
+ return (hyperlinkRegion != null) ? hyperlinkRegion: new Region(getOffset(), 0);
}
abstract protected IRegion doGetHyperlinkRegion(int offset);
@@ -289,15 +298,6 @@
return fDocument;
}
- /*
- * (non-Javadoc)
- *
- * @see IHyperlink#getHyperlinkText()
- */
-// public String getHyperlinkText() {
-// return null;
-// }
-
abstract public String getHyperlinkText();
/*
@@ -308,6 +308,4 @@
public String getTypeLabel() {
return null;
}
-
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/BaseHyperlinkDetector.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/BaseHyperlinkDetector.java 2012-01-30
19:17:36 UTC (rev 38288)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xpl/BaseHyperlinkDetector.java 2012-01-30
19:20:43 UTC (rev 38289)
@@ -26,6 +26,7 @@
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkBuilder;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkDetector;
+import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
public class BaseHyperlinkDetector implements IHyperlinkDetector{
@@ -35,8 +36,8 @@
// determine the current partition
if (textViewer != null && textViewer.getDocument() != null) {
String contentType = getContentType(textViewer.getDocument());
- String partitionType = getPartitionType(textViewer.getDocument(),
region.getOffset());
- hyperlinks = getHyperlinks(textViewer, region, contentType, partitionType);
+ IHyperlinkRegion partition = getPartition(textViewer.getDocument(),
region.getOffset());
+ hyperlinks = partition == null ? null : getHyperlinks(textViewer, region, contentType,
partition);
}
return hyperlinks;
}
@@ -44,13 +45,13 @@
/**
* Returns IHyperlink array for the document and region type.
*/
- public IHyperlink[] getHyperlinks(ITextViewer textViewer, IRegion region, String
contentType, String partitionType) {
- ArrayList hyperlinks = new ArrayList();
+ public IHyperlink[] getHyperlinks(ITextViewer textViewer, IRegion region, String
contentType, IHyperlinkRegion partition) {
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
// determine the current partition
if (textViewer != null && textViewer.getDocument() != null) {
// query HyperlinkBuilder and get the list of open ons for the
// current partition
- HyperlinkDefinition[] defs =
HyperlinkBuilder.getInstance().getHyperlinkDefinitions(contentType, partitionType);
+ HyperlinkDefinition[] defs =
HyperlinkBuilder.getInstance().getHyperlinkDefinitions(contentType, partition.getType());
if(defs==null) return null;
@@ -60,6 +61,7 @@
if (hyperlink instanceof AbstractHyperlink) {
((AbstractHyperlink)hyperlink).setDocument(textViewer.getDocument());
((AbstractHyperlink)hyperlink).setOffset(region.getOffset());
+ ((AbstractHyperlink)hyperlink).setRegion(partition);
}
hyperlinks.add(hyperlink);
}
@@ -101,14 +103,11 @@
* @param offset
* @return String partition type
*/
- protected String getPartitionType(IDocument document, int offset) {
+ protected IHyperlinkRegion getPartition(IDocument document, int offset) {
String type = null;
- String[] types = getPartitionTypes(document, offset);
+ IHyperlinkRegion[] regions = getPartitions(document, offset);
// if more than 1 hyperlink partitioner type is returned just returning the first
one.
- if(types != null && types.length > 0) {
- type = types[0];
- }
- return type;
+ return (regions != null && regions.length > 0 ? regions[0] : null);
}
/**
@@ -125,7 +124,7 @@
return hyperlinks;
}
- protected String[] getPartitionTypes(IDocument document, int offset) {
- return new String[0];
+ protected IHyperlinkRegion[] getPartitions(IDocument document, int offset) {
+ return new IHyperlinkRegion[0];
}
}