Author: dgolovin
Date: 2008-10-28 02:46:22 -0400 (Tue, 28 Oct 2008)
New Revision: 11231
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/HyperlinkRegion.java
Log:
increase code coverage and optimize code
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 2008-10-28
02:33:42 UTC (rev 11230)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkDetector.java 2008-10-28
06:46:22 UTC (rev 11231)
@@ -33,53 +33,43 @@
protected String[] getPartitionTypes(IDocument document, int offset) {
String documentRegionType = null;
ITypedRegion region = null;
-
+ ArrayList<String> types = new ArrayList<String>();
+
region = (document instanceof IDocumentExtension3 ?
((IDocumentExtension3)document).getDocumentPartitioner("org.eclipse.wst.sse.core.default_structured_text_partitioning").getPartition(offset)
:
document.getDocumentPartitioner().getPartition(offset));
if (region != null) {
documentRegionType = region.getType();
- } else {
- return null;
+
+ String contentType = getContentType(document);
+
+ HyperlinkPartitionerDefinition[] defs =
HyperlinkPartitionerBuilder.getInstance().getHyperlinkPartitionerDefinitions(contentType,
documentRegionType, null);
+
+ if(defs==null || defs.length==0) {
+ types.add(documentRegionType);
+ } else {
+ for(int i=0; i<defs.length; i++) {
+ final ITypedRegion finalDocumentRegion = region;
+ final IDocument finalDocument = document;
+ final String finalContentType = contentType;
+ IHyperlinkPartitioner hyperlinkPartitioner =
defs[i].createHyperlinkPartitioner();
+ IHyperlinkRegion startHyperlinkRegion = new HyperlinkRegion(
+ finalDocumentRegion.getOffset(),
+ finalDocumentRegion.getLength(),
+ AxisUtil.getAxis(finalDocument, finalDocumentRegion.getOffset()),
+ 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);
+ }
+ }
+ }
+ }
}
- String contentType = getContentType(document);
- ArrayList<String> types = new ArrayList<String>();
- HyperlinkPartitionerDefinition[] defs =
HyperlinkPartitionerBuilder.getInstance().getHyperlinkPartitionerDefinitions(contentType,
documentRegionType, null);
-
- if(defs==null || defs.length==0) {
- return new String[]{documentRegionType};
- }
- for(int i=0; i<defs.length; i++) {
- final ITypedRegion finalDocumentRegion = region;
- final IDocument finalDocument = document;
- final String finalContentType = contentType;
- IHyperlinkPartitioner hyperlinkPartitioner = defs[i].createHyperlinkPartitioner();
- IHyperlinkRegion startHyperlinkRegion = new IHyperlinkRegion() {
- public String getAxis() {
- return AxisUtil.getAxis(finalDocument,
finalDocumentRegion.getOffset());
- }
- public String getContentType() {
- return finalContentType;
- }
- public String getType() {
- return finalDocumentRegion.getType();
- }
- public int getLength() {
- return finalDocumentRegion.getLength();
- }
- public int getOffset() {
- return finalDocumentRegion.getOffset();
- }
- };
- if((!(hyperlinkPartitioner instanceof IHyperlinkPartitionRecognizer)) ||
- ((IHyperlinkPartitionRecognizer)hyperlinkPartitioner).recognize(document,
startHyperlinkRegion)) {
- String type = hyperlinkPartitioner.getChildPartitionType(document,
startHyperlinkRegion);
- if(type!=null && !types.contains(type)) {
- types.add(type);
- }
- }
- }
return types.toArray(new String[types.size()]);
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkRegion.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkRegion.java 2008-10-28
02:33:42 UTC (rev 11230)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkRegion.java 2008-10-28
06:46:22 UTC (rev 11231)
@@ -10,24 +10,20 @@
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
-public class HyperlinkRegion implements IHyperlinkRegion {
- int start;
- int length;
-
+import org.eclipse.jface.text.TypedRegion;
+
+public class HyperlinkRegion extends TypedRegion implements IHyperlinkRegion {
String axis;
String contentType;
- String type;
public HyperlinkRegion(int propStart, int propLength) {
this(propStart, propLength, null, null, null);
}
public HyperlinkRegion(int start, int length, String axis, String contentType, String
type) {
- this.start = start;
- this.length = length;
+ super(start,length,type);
this.axis = axis;
this.contentType = contentType;
- this.type = type;
}
public String getAxis() {
@@ -37,28 +33,14 @@
public String getContentType() {
return contentType;
}
-
- public String getType() {
- return type;
- }
-
- public int getLength() {
- return length;
- }
-
- public int getOffset() {
- return start;
- }
-
+
public boolean equals(Object arg) {
if (!(arg instanceof IHyperlinkRegion)) return false;
IHyperlinkRegion region = (IHyperlinkRegion)arg;
- if (getOffset() != region.getOffset()) return false;
- if (getLength() != region.getLength()) return false;
- if(!areArqumentsEqual(getContentType(), region.getContentType())) return false;
- if(!areArqumentsEqual(getType(), region.getType())) return false;
- if(!areArqumentsEqual(getAxis(), region.getAxis())) return false;
- return true;
+ return getOffset() == region.getOffset()
+ && getLength() == region.getLength()
+ && areArqumentsEqual(getContentType(), region.getContentType())
+ && areArqumentsEqual(getAxis(), region.getAxis());
}
private boolean areArqumentsEqual(String s1, String s2) {
Show replies by date