Interface CtTryWithResource

All Superinterfaces:
Cloneable, CtBodyHolder, CtCodeElement, CtElement, CtQueryable, CtStatement, CtTry, CtVisitable, FactoryAccessor, Serializable, SourcePositionHolder, TemplateParameter<Void>
All Known Implementing Classes:
CtTryWithResourceImpl

public interface CtTryWithResource extends CtTry
This code element defines a try with resource statement. Example:
    // br is the resource
    try (java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader("/foo"))) {
        br.readLine();
   }
 
  • Method Details

    • getResources

      List<CtResource<?>> getResources()
      Gets the auto-closeable resources of this try. Available from Java 7 with the try-with-resource statement. The returned list is immutable for sake of proper encapsulation.
    • setResources

      <T extends CtTryWithResource> T setResources(List<? extends CtResource<?>> resources)
      Sets the auto-closeable resources of this try. Available from Java 7 with the try-with-resource statement.
    • addResource

      <T extends CtTryWithResource> T addResource(CtResource<?> resource)
      Adds a resource.
    • removeResource

      boolean removeResource(CtResource<?> resource)
      Removes a resource.
    • clone

      Description copied from interface: CtElement
      Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
      Specified by:
      clone in interface CtCodeElement
      Specified by:
      clone in interface CtElement
      Specified by:
      clone in interface CtStatement
      Specified by:
      clone in interface CtTry