Author: vrubezhny
Date: 2012-01-30 14:25:59 -0500 (Mon, 30 Jan 2012)
New Revision: 38296
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamViewHyperlinkPartitioner.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/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java 2012-01-30
19:25:22 UTC (rev 38295)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java 2012-01-30
19:25:59 UTC (rev 38296)
@@ -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.seam.text.ext.hyperlink;
@@ -19,38 +19,17 @@
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.EclipseResourceUtil;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.seam.core.SeamProjectsSet;
import org.jboss.tools.seam.text.ext.SeamExtPlugin;
-import org.w3c.dom.Node;
public class ComponentsHyperlink extends AbstractHyperlink {
private String hyperlinkText = "";
- private String partitionType = null;
-
@Override
- protected IRegion doGetHyperlinkRegion(int offset) {
- Node node = ComponentsHyperlinkPartitioner.getNode(getDocument(),
- offset);
- partitionType = ComponentsHyperlinkPartitioner.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;
@@ -63,11 +42,15 @@
SeamExtPlugin.getPluginLog().logError(ex);
}
+ IHyperlinkRegion partition = (getHyperlinkRegion() instanceof IHyperlinkRegion) ?
+ (IHyperlinkRegion)getHyperlinkRegion() : null;
+
+ String partitionType = partition == null ? null : partition.getType();
+
if (partitionType == ComponentsHyperlinkPartitioner.BPM_DEFINITION_PARTITION)
doBpmDefinitionHyperlink(region);
else if (partitionType == ComponentsHyperlinkPartitioner.DROOLS_RULE_PARTITION)
doDroolsRuleHyperlink(region);
-
}
private void doDroolsRuleHyperlink(IRegion region) {
@@ -153,5 +136,4 @@
public String getHyperlinkText() {
return hyperlinkText;
}
-
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java 2012-01-30
19:25:22 UTC (rev 38295)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java 2012-01-30
19:25:59 UTC (rev 38296)
@@ -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.seam.text.ext.hyperlink;
@@ -21,7 +21,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-
public class ComponentsHyperlinkPartitioner extends
AbstractHyperlinkPartitioner {
public static final String BPM_DEFINITION_PARTITION =
"org.jboss.tools.seam.text.ext.BPM_DEFINITION";
@@ -92,24 +91,23 @@
}
@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);
String type = getType(node);
if (type == null)
return null;
IndexedRegion text = (IndexedRegion) node;
- int length = text.getLength();
- int offset = text.getStartOffset();
+ int textLength = text.getLength();
+ int textOffset = text.getStartOffset();
String contentType = superRegion.getContentType();
String axis = getAxis(document, superRegion);
- IHyperlinkRegion hyperRegion = new HyperlinkRegion(offset, length,
+ IHyperlinkRegion hyperRegion = new HyperlinkRegion(textOffset, textLength,
axis, contentType, type);
return hyperRegion;
}
-
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2012-01-30
19:25:22 UTC (rev 38295)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2012-01-30
19:25:59 UTC (rev 38296)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2011 Red Hat, Inc.
+ * Copyright (c) 2008-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,
@@ -20,14 +20,11 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.jboss.tools.common.el.core.model.ELArgumentInvocation;
import org.jboss.tools.common.el.core.model.ELExpression;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
-import org.jboss.tools.common.el.core.parser.ELParserFactory;
-import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
@@ -55,37 +52,30 @@
public class SeamBeanHyperlinkPartitioner extends AbstractHyperlinkPartitioner implements
IHyperlinkPartitionRecognizer, IHyperLinkPartitionPriority {
public static final String SEAM_MESSAGES_BEAN_PARTITION =
"org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN";
- private ELParserFactory factory = ELParserUtil.getJbossFactory();
-
/**
* @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());
+ if (!recognize(document, offset, superRegion)) return null;
+ IHyperlinkRegion r = getRegion(document, offset);
if (r == null) return null;
- r = getWordRegion(document, superRegion.getOffset());
+ r = getWordRegion(document, offset);
if (r == null) return null;
- Map<String, ISeamMessages> messages = findMessagesComponents(document,
superRegion);
+ Map<String, ISeamMessages> messages = findMessagesComponents(document, offset);
if (messages != null && !messages.isEmpty()) {
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
String type = SEAM_MESSAGES_BEAN_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);
}
return null;
@@ -93,8 +83,6 @@
smw.dispose();
}
}
-
-
protected String getAxis(IDocument document, IHyperlinkRegion superRegion) {
if (superRegion.getAxis() == null || superRegion.getAxis().length() == 0) {
@@ -193,11 +181,9 @@
int propStart = bStart + start;
int propLength = bEnd - bStart;
-
if (propStart > offset || propStart + propLength < offset) return null;
- IHyperlinkRegion region = new HyperlinkRegion(propStart, propLength, null, null,
null);
- return region;
+ return new HyperlinkRegion(propStart, propLength, null, null, null);
} catch (BadLocationException x) {
SeamExtPlugin.getPluginLog().logError(x);
return null;
@@ -205,6 +191,7 @@
smw.dispose();
}
}
+
public static IHyperlinkRegion getRegion(IDocument document, final int offset) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
@@ -244,21 +231,19 @@
/**
* @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;
- Utils.findNodeForOffset(xmlDocument, region.getOffset());
-
- Map<String, ISeamMessages> messages = findMessagesComponents(document, region);
+ Map<String, ISeamMessages> messages = findMessagesComponents(document, offset);
if (messages != null && !messages.isEmpty()) {
return true;
}
- List<IJavaElement> javaElements = findJavaElements(document, region);
+ List<IJavaElement> javaElements = findJavaElements(document, offset);
if (javaElements != null && !javaElements.isEmpty()) {
return true;
}
@@ -269,20 +254,17 @@
}
}
- public static List<IJavaElement> findJavaElements(IDocument document, IRegion
region) {
+ public static List<IJavaElement> findJavaElements(IDocument document, int offset)
{
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- IHyperlinkRegion r = getRegion(document, region.getOffset());
+ IHyperlinkRegion r = getRegion(document, offset);
if (r == null) return null;
-
String propText = document.get(r.getOffset(), r.getLength());
-
-
IFile file = smw.getFile();
IProject project = (file == null ? null : file.getProject());
@@ -346,7 +328,7 @@
elText.append('.').append(app);
javaElements = engine.getJavaElementsForExpression(
- seamProject, file, elText.toString(), region.getOffset());
+ seamProject, file, elText.toString(), offset);
}
return javaElements;
} catch (BadLocationException x) {
@@ -357,14 +339,14 @@
}
}
- public static Map<String, ISeamMessages> findMessagesComponents(IDocument
document, IRegion region) {
+ public static Map<String, ISeamMessages> findMessagesComponents(IDocument
document, int offset) {
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
- IHyperlinkRegion r = getRegion(document, region.getOffset());
+ IHyperlinkRegion r = getRegion(document, offset);
if (r == null) return null;
String propText = document.get(r.getOffset(), r.getLength());
@@ -514,5 +496,4 @@
public int getPriority() {
return 0; // to be first
}
-
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamViewHyperlinkPartitioner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamViewHyperlinkPartitioner.java 2012-01-30
19:25:22 UTC (rev 38295)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamViewHyperlinkPartitioner.java 2012-01-30
19:25:59 UTC (rev 38296)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 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,
@@ -16,8 +16,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
-import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPLinkHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
+import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPLinkHyperlinkPartitioner;
import org.jboss.tools.seam.internal.core.SeamProject;
import org.jboss.tools.seam.text.ext.SeamExtPlugin;
@@ -64,8 +64,7 @@
/**
* @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) {
- return recognizeNature(document) ? super.recognize(document, region) : false;
+ public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
+ return recognizeNature(document) ? super.recognize(document, offset, region) : false;
}
-
}