Author: vrubezhny
Date: 2012-01-30 14:21:22 -0500 (Mon, 30 Jan 2012)
New Revision: 38290
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.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/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java 2012-01-30
19:21:22 UTC (rev 38290)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright (c) 2011-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,
@@ -28,14 +28,13 @@
public class CDISeamResourceLoadingHyperlink extends AbstractHyperlink{
private final static String PROPERTIES = ".properties";
- private IRegion region;
private String path;
private IFile file;
public CDISeamResourceLoadingHyperlink(IFile file, IDocument document, IRegion region,
String path){
super();
this.file = file;
- this.region = region;
+ setRegion(region);
this.path = path;
setDocument(document);
}
@@ -45,11 +44,6 @@
}
@Override
- protected IRegion doGetHyperlinkRegion(int offset) {
- return region;
- }
-
- @Override
public IFile getReadyToOpenFile(){
String fileName = path;
@@ -165,5 +159,4 @@
public String getHyperlinkText() {
return NLS.bind(CDISeamExtMessages.CDI_SEAM_RESOURCE_LOADING_HYPERLINK, path);
}
-
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java 2012-01-30
19:20:43 UTC (rev 38289)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java 2012-01-30
19:21:22 UTC (rev 38290)
@@ -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.cdi.seam.text.ext.hyperlink;
@@ -25,29 +25,25 @@
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.eclipse.ui.PartInitException;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.seam.config.core.CDISeamConfigExtension;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamBeansDefinition;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamFieldDefinition;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamMemberDefinition;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamMethodDefinition;
+import org.jboss.tools.cdi.seam.config.core.util.Util;
import org.jboss.tools.cdi.seam.text.ext.CDISeamExtMessages;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
-import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPRootHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPRootHyperlinkPartitioner;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.jboss.tools.cdi.seam.config.core.CDISeamConfigExtension;
-import org.jboss.tools.cdi.seam.config.core.definition.SeamBeansDefinition;
-import org.jboss.tools.cdi.seam.config.core.definition.SeamFieldDefinition;
-import org.jboss.tools.cdi.seam.config.core.definition.SeamMemberDefinition;
-import org.jboss.tools.cdi.seam.config.core.definition.SeamMethodDefinition;
-import org.jboss.tools.cdi.seam.config.core.util.Util;
-
/**
* @author Jeremy
*/
@@ -189,62 +185,16 @@
}
}
- 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();
- smw.init(getDocument());
- try {
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null) return null;
-
- int start, nameStart, nameEnd;
-
- if(n instanceof IDOMElement) {
- IDOMElement elem = (IDOMElement)n;
- String tagName = elem.getTagName();
- start = elem.getStartOffset();
- nameStart = start + (elem.isEndTag() ? "</" :
"<").length(); //$NON-NLS-1$ //$NON-NLS-2$
- nameEnd = nameStart + tagName.length();
- } else if (n instanceof IDOMAttr) {
- String attrName = n.getNodeName();
- start = ((IDOMAttr)n).getStartOffset();
- nameStart = start;
- nameEnd = start + attrName.length();
- } else {
- return null;
- }
-
- if (nameStart > offset || nameEnd <= offset) return null;
-
- return new Region(nameStart,nameEnd - nameStart);
- } finally {
- smw.dispose();
- }
- }
-
/*
* (non-Javadoc)
*
* @see IHyperlink#getHyperlinkText()
*/
public String getHyperlinkText() {
- String tagName = getTagName(fLastRegion);
+ String tagName = getTagName(getHyperlinkRegion());
if (tagName == null)
return CDISeamExtMessages.CDI_SEAM_CONFIG_OPEN_TAG;
return MessageFormat.format(CDISeamExtMessages.CDI_SEAM_CONFIG_OPEN_TAG, tagName);
}
-
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java 2012-01-30
19:20:43 UTC (rev 38289)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java 2012-01-30
19:21:22 UTC (rev 38290)
@@ -40,25 +40,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();
smw.init(document);
try {
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 = SEAM_CONFIG_TAG_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();
}
@@ -67,19 +63,13 @@
/**
* @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();
smw.init(document);
try {
IFile documentFile = smw.getFile();
- if(documentFile==null) {
- return false;
- }
- IProject project = documentFile.getProject();
- if(project == null) {
- return false;
- }
- return true;
+ if(documentFile==null) return false;
+ return (documentFile.getProject() != null);
} finally {
smw.dispose();
}
@@ -129,7 +119,6 @@
} finally {
smw.dispose();
}
-
}
protected String getAxis(IDocument document, IHyperlinkRegion superRegion) {
@@ -138,5 +127,4 @@
}
return superRegion.getAxis();
}
-
}