diff options
author | bvosburgh | 2008-03-24 19:57:04 +0000 |
---|---|---|
committer | bvosburgh | 2008-03-24 19:57:04 +0000 |
commit | f4acad1ac9d656dc85940e2cb1f41c88f3c1ee76 (patch) | |
tree | 436778d12ac3c92c2bae6e74fb8baf7b20891b20 /jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility | |
parent | 51a2e43b0f2453b876b8fcf7e65b7dbbdf72ebdd (diff) | |
download | webtools.dali-f4acad1ac9d656dc85940e2cb1f41c88f3c1ee76.tar.gz webtools.dali-f4acad1ac9d656dc85940e2cb1f41c88f3c1ee76.tar.xz webtools.dali-f4acad1ac9d656dc85940e2cb1f41c88f3c1ee76.zip |
reworked TextRange
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility')
2 files changed, 14 insertions, 98 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleTextRange.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleTextRange.java index c8e5ca8b3f..398196374d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleTextRange.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleTextRange.java @@ -9,13 +9,12 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.utility; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.core.utility.AbstractTextRange; /** - * Straightforward, albeit almost useless, implementation of ITextRange. + * Straightforward implementation of TextRange. */ -public class SimpleTextRange implements TextRange { +public class SimpleTextRange extends AbstractTextRange { private final int offset; private final int length; private final int lineNumber; @@ -27,57 +26,16 @@ public class SimpleTextRange implements TextRange { this.lineNumber = lineNumber; } - public int getOffset() { + public int offset() { return this.offset; } - public int getLength() { + public int length() { return this.length; } - public int getLineNumber() { + public int lineNumber() { return this.lineNumber; } - public boolean includes(int index) { - return (this.offset <= index) && (index < this.end()); - } - - public boolean touches(int index) { - return this.includes(index) || (index == this.end()); - } - - /** - * The end offset is "exclusive", i.e. the element at the end offset - * is not included in the range. - */ - private int end() { - return this.offset + this.length; - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if ( ! (o instanceof TextRange)) { - return false; - } - TextRange r = (TextRange) o; - return (r.getOffset() == this.offset) - && (r.getLength() == this.length); - } - - @Override - public int hashCode() { - return this.offset ^ this.length; - } - - @Override - public String toString() { - String start = String.valueOf(this.offset); - String end = String.valueOf(this.end()); - return StringTools.buildToStringFor(this, start + ", " + end); - } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ASTNodeTextRange.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ASTNodeTextRange.java index 552585ee75..e29a7b2c51 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ASTNodeTextRange.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ASTNodeTextRange.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * Copyright (c) 2006, 2008 Oracle. All rights reserved. * This program and the accompanying materials are 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. @@ -11,13 +11,12 @@ package org.eclipse.jpt.core.internal.utility.jdt; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.core.utility.AbstractTextRange; /** - * Straightforward implementation of ITextRange that adapts an ASTNode. + * Adapt an ASTNode to the TextRange interface. */ -public class ASTNodeTextRange implements TextRange { +public class ASTNodeTextRange extends AbstractTextRange { private final ASTNode astNode; public ASTNodeTextRange(ASTNode astNode) { @@ -25,57 +24,16 @@ public class ASTNodeTextRange implements TextRange { this.astNode = astNode; } - public int getOffset() { + public int offset() { return this.astNode.getStartPosition(); } - public int getLength() { + public int length() { return this.astNode.getLength(); } - public int getLineNumber() { - return ((CompilationUnit) this.astNode.getRoot()).getLineNumber(this.getOffset()); - } - - public boolean includes(int index) { - return (this.getOffset() <= index) && (index < this.end()); - } - - public boolean touches(int index) { - return this.includes(index) || (index == this.end()); - } - - /** - * The end offset is "exclusive", i.e. the element at the end offset - * is not included in the range. - */ - private int end() { - return this.getOffset() + this.getLength(); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if ( ! (o instanceof TextRange)) { - return false; - } - TextRange r = (TextRange) o; - return (r.getOffset() == this.getOffset()) - && (r.getLength() == this.getLength()); - } - - @Override - public int hashCode() { - return this.getOffset() ^ this.getLength(); - } - - @Override - public String toString() { - String start = String.valueOf(this.getOffset()); - String end = String.valueOf(this.getOffset() + this.getLength() - 1); - return StringTools.buildToStringFor(this, start + ", " + end); + public int lineNumber() { + return ((CompilationUnit) this.astNode.getRoot()).getLineNumber(this.offset()); } } |