Search in sources :

Example 1 with Var

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;
}
Also used : Path(java.nio.file.Path) CharSource(com.google.common.io.CharSource) Var(com.google.errorprone.annotations.Var) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URL(java.net.URL) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException)

Example 2 with Var

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;
}
Also used : Completion(javax.annotation.processing.Completion) Var(com.google.errorprone.annotations.Var) ArrayList(java.util.ArrayList) PackageElement(javax.lang.model.element.PackageElement)

Example 3 with Var

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);
        }
    }
}
Also used : Path(java.nio.file.Path) Var(com.google.errorprone.annotations.Var) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with Var

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);
}
Also used : ExtendedRational(org.sosy_lab.common.rationals.ExtendedRational) Var(com.google.errorprone.annotations.Var) Test(org.junit.Test)

Example 5 with Var

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);
}
Also used : ExtendedRational(org.sosy_lab.common.rationals.ExtendedRational) Var(com.google.errorprone.annotations.Var) Test(org.junit.Test)

Aggregations

Var (com.google.errorprone.annotations.Var)37 Test (org.junit.Test)9 Path (java.nio.file.Path)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)6 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 ObjectName (javax.management.ObjectName)6 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4 Nullable (javax.annotation.Nullable)4 MBeanException (javax.management.MBeanException)4 MBeanServer (javax.management.MBeanServer)4 ReflectionException (javax.management.ReflectionException)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 IOException (java.io.IOException)3 AccessibleObject (java.lang.reflect.AccessibleObject)3 ClassPath (com.google.common.reflect.ClassPath)2 EqualsTester (com.google.common.testing.EqualsTester)2 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeUnit (java.util.concurrent.TimeUnit)2