WALA/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/translator/RangePosition.java

85 lines
1.9 KiB
Java
Raw Normal View History

/*******************************************************************************
* Copyright (c) 2007 IBM Corporation.
* 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
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.wala.cast.js.translator;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
import com.ibm.wala.cast.tree.impl.AbstractSourcePosition;
public class RangePosition extends AbstractSourcePosition implements Position {
private final URL url;
private final int line;
private final int startOffset;
private final int endOffset;
public RangePosition(URL url, int line, int startOffset, int endOffset) {
super();
this.url = url;
this.line = line;
this.startOffset = startOffset;
this.endOffset = endOffset;
}
2013-06-25 15:57:37 +00:00
@Override
public int compareTo(Object o) {
Position other = (Position) o;
if (startOffset != other.getFirstOffset()) {
return startOffset - other.getFirstOffset();
} else {
return endOffset - other.getLastOffset();
}
}
2013-06-25 15:57:37 +00:00
@Override
public int getFirstLine() {
return line;
}
2013-06-25 15:57:37 +00:00
@Override
public int getLastLine() {
return -1;
}
2013-06-25 15:57:37 +00:00
@Override
public int getFirstCol() {
return -1;
}
2013-06-25 15:57:37 +00:00
@Override
public int getLastCol() {
return -1;
}
2013-06-25 15:57:37 +00:00
@Override
public int getFirstOffset() {
return startOffset;
}
2013-06-25 15:57:37 +00:00
@Override
public int getLastOffset() {
return endOffset;
}
2013-06-25 15:57:37 +00:00
@Override
public URL getURL() {
return url;
}
2013-06-25 15:57:37 +00:00
@Override
public InputStream getInputStream() throws IOException {
return url.openStream();
}
}