use of com.google.errorprone.annotations.Var in project java-common-lib by sosy-lab.
the class ConfigurationBuilder method loadFromResource.
/**
* Load options from a class-loader resource with a "key = value" format.
*
* <p>There must not be any #include directives in the resource.
*
* @param contextClass The class to use for looking up the resource.
* @param resourceName The name of the resource relative to {@code contextClass}.
* @throws IllegalArgumentException If the resource cannot be found or read, or contains invalid
* syntax or #include directives.
*/
public ConfigurationBuilder loadFromResource(Class<?> contextClass, String resourceName) {
URL url = Resources.getResource(contextClass, resourceName);
CharSource source = Resources.asCharSource(url, StandardCharsets.UTF_8);
setupProperties();
// Get the path to the source, used for error messages and resolving relative path names.
@Var Path sourcePath;
@Var String sourceString;
try {
sourcePath = Paths.get(url.toURI());
sourceString = sourcePath.toString();
} catch (URISyntaxException | FileSystemNotFoundException | IllegalArgumentException e) {
// If this fails, e.g., because url is a HTTP URL, we can also use the raw string.
// This will not allow resolving relative path names, but everything else works.
sourcePath = null;
sourceString = url.toString();
}
try {
Parser parser = Parser.parse(source, Optional.ofNullable(sourcePath), sourceString);
properties.putAll(parser.getOptions());
sources.putAll(parser.getSources());
} catch (InvalidConfigurationException | IOException e) {
throw new IllegalArgumentException("Error in resource " + resourceName + " relative to " + contextClass.getName(), e);
}
return this;
}
use of com.google.errorprone.annotations.Var in project java-common-lib by sosy-lab.
the class OptionAnnotationProcessor method returnPackagePrefixCompletions.
private Iterable<? extends Completion> returnPackagePrefixCompletions(Element element, String userText) {
List<Completion> packages = new ArrayList<>();
PackageElement pkg = elementUtils().getPackageOf(element);
if (!pkg.isUnnamed()) {
@Var String name = pkg.getQualifiedName().toString();
do {
if (!name.startsWith(userText)) {
break;
}
packages.add(Completions.of(name));
int pos = name.lastIndexOf('.');
name = name.substring(0, Math.max(pos, 0));
} while (!name.isEmpty());
}
return packages;
}
use of com.google.errorprone.annotations.Var in project java-common-lib by sosy-lab.
the class ParserTest method recursiveIncludeDepthN.
@Test(expected = InvalidConfigurationFileException.class)
public final void recursiveIncludeDepthN() throws IOException, InvalidConfigurationException {
Path firstIncluded = TempFile.builder().prefix(TEST_FILE_PREFIX).suffix(TEST_FILE_SUFFIX).create();
List<Path> allFiles = new ArrayList<>();
allFiles.add(firstIncluded);
@Var Path included = firstIncluded;
for (int i = 0; i < MAX_RECURSIVE_INCLUDE_TEST_DEPTH; i++) {
included = createTempFile(TEST_FILE_PREFIX, TEST_FILE_SUFFIX, "#include " + included.toAbsolutePath());
allFiles.add(included);
}
IO.writeFile(firstIncluded, Charset.defaultCharset(), "#include " + included.toAbsolutePath());
try {
test("#include " + included.toAbsolutePath());
} finally {
for (Path toDelete : allFiles) {
Files.delete(toDelete);
}
}
}
use of com.google.errorprone.annotations.Var in project java-common-lib by sosy-lab.
the class ExtendedRationalTest method testMultiplicationZero.
@Test
public void testMultiplicationZero() {
@Var ExtendedRational a = ExtendedRational.ZERO;
@Var ExtendedRational b = ExtendedRational.NEG_INFTY;
assertThat(a.times(b)).isEqualTo(ExtendedRational.ZERO);
a = ExtendedRational.ZERO;
b = ExtendedRational.INFTY;
assertThat(a.times(b)).isEqualTo(ExtendedRational.ZERO);
}
use of com.google.errorprone.annotations.Var in project java-common-lib by sosy-lab.
the class ExtendedRationalTest method testMultiplicationNegInfty.
@Test
public void testMultiplicationNegInfty() {
ExtendedRational a = ExtendedRational.NEG_INFTY;
@Var ExtendedRational b = ExtendedRational.NEG_INFTY;
assertThat(a.times(b)).isEqualTo(ExtendedRational.INFTY);
b = ExtendedRational.INFTY;
assertThat(a.times(b)).isEqualTo(ExtendedRational.NEG_INFTY);
}
Aggregations