Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

started to add the functionality of URIUtil to ISourceLocation for better encapsulation of OS-specific behavior #195

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/main/java/io/usethesource/vallang/ISourceLocation.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation.
* Copyright (c) 2007 IBM Corporation, 2023 NWO-I Centrum Wiskunde & Informatica
* 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:
* Robert Fuhrer ([email protected]) - initial API and implementation

* Jurgen Vinju ([email protected]) - extensions and maintenance
*******************************************************************************/

package io.usethesource.vallang;

import java.net.URI;
import java.net.URISyntaxException;

import io.usethesource.vallang.visitors.IValueVisitor;

Expand Down Expand Up @@ -134,6 +135,30 @@ public interface ISourceLocation extends IValue {
* @return the source location without any offset & length information.
*/
public ISourceLocation top();

public String getFileName();

public boolean hasFileName();

public ISourceLocation changeScheme(String newScheme) throws URISyntaxException;

public ISourceLocation changeAuthority(String newAuthority) throws URISyntaxException;

public ISourceLocation changePath(String newPath) throws URISyntaxException;

public ISourceLocation changeFile(String newFile) throws URISyntaxException;

public ISourceLocation changeExtension(String newExtension) throws URISyntaxException;

public ISourceLocation changeFragment(String newFragment) throws URISyntaxException;

public ISourceLocation changeQuery(String newQuery) throws URISyntaxException;

public ISourceLocation changeFileName(String newFileName) throws URISyntaxException;

public ISourceLocation makeChildLocation(String childPath) throws URISyntaxException;

public ISourceLocation getParentLocation();

@Override
default <T, E extends Throwable> T accept(IValueVisitor<T, E> v) throws E {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/usethesource/vallang/IValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public ISourceLocation sourceLocation(String scheme, String authority,

/**
* Get a set writer of which the element type will be the least upper bound
* of the element types
* of the element types. ISetWriter instances are stream of IValue collectors.
*
* @return a set writer
*/
Expand All @@ -461,7 +461,7 @@ public ISourceLocation sourceLocation(String scheme, String authority,

/**
* Get a list writer of which the element type will be the least upper bound
* of the element types
* of the element types. IListWriter instances are stream of IValue collectors.
*
* @return a list writer
*/
Expand All @@ -478,7 +478,8 @@ public ISourceLocation sourceLocation(String scheme, String authority,

/**
* Get a map writer of which the key and value types will be the least upper
* bound of the keys and values that are put in.
* bound of the keys and values that are put in. IMapWriter instances are
* stream collectors; the stream must be made of binary ITuple instances.
*
* @return a list writer
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,70 @@ public boolean hasOffsetLength() {
return false;
}


@Override
public ISourceLocation top() {
return this;
}

@Override
public ISourceLocation changeAuthority(String authority) throws URISyntaxException {
return newURI(scheme, authority, null, null, null);
}

@Override
public ISourceLocation changeScheme(String scheme) throws URISyntaxException {
return newURI(scheme, null, null, null, null);
}

@Override
public ISourceLocation changeFragment(String fragment) throws URISyntaxException {
return newURI(scheme, null, null, null, fragment);
}

@Override
public ISourceLocation changeQuery(String fragment) throws URISyntaxException {
return newURI(scheme, null, null, null, fragment);
}

@Override
public ISourceLocation getParentLocation() {
return this;
}

@Override
public boolean hasFileName() {
return false;
}

@Override
public ISourceLocation changeExtension(String ext) {
throw new UnsupportedOperationException();
}

@Override
public String getFileName() {
throw new UnsupportedOperationException();
}

@Override
public ISourceLocation changeFileName(String file) throws URISyntaxException {
throw new UnsupportedOperationException();
}

@Override
public ISourceLocation changeFile(String file) throws URISyntaxException {
throw new UnsupportedOperationException();
}

@Override
public ISourceLocation changePath(String path) throws URISyntaxException {
throw new UnsupportedOperationException();
}

@Override
public ISourceLocation makeChildLocation(String path) throws URISyntaxException {
return newURI(scheme, null, path, null, null);
}
}

private static final Pattern squareBrackets = Pattern.compile("(\\[|\\])");
Expand Down Expand Up @@ -361,6 +420,7 @@ public String getAuthority() {
public int hashCode() {
return scheme.hashCode() + authority.hashCode();
}

@Override
public boolean equals(@Nullable Object obj) {
if (obj == null) {
Expand Down Expand Up @@ -500,7 +560,7 @@ public QueryURI(String scheme, String query) {

@Override
@SuppressWarnings("nullness") // CF doesn't have a model for URI
public URI getURI() {
public URI getURI() {
try {
URI result = new URI(scheme, "", "/", query, null);
return new URI(result.toASCIIString());
Expand Down Expand Up @@ -598,7 +658,7 @@ public QueryPathURI(String scheme, String path, String query) {

@Override
@SuppressWarnings("nullness") // CF doesn't have a model for URI
public URI getURI() {
public URI getURI() {
try {
URI result = new URI(scheme, "", path, query, null);
return new URI(result.toASCIIString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public int getLength() throws UnsupportedOperationException {
public int getOffset() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}

}

private static class IntIntIntIntIntInt extends Complete {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Random;
import java.util.stream.StreamSupport;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

Expand Down
Loading