spoon.reflect.code.CtTry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spoon-core Show documentation
Show all versions of spoon-core Show documentation
Spoon is a tool for meta-programming, analysis and transformation of Java programs.
/*
* SPDX-License-Identifier: (MIT OR CECILL-C)
*
* Copyright (C) 2006-2023 INRIA and contributors
*
* Spoon is available either under the terms of the MIT License (see LICENSE-MIT.txt) or the Cecill-C License (see LICENSE-CECILL-C.txt). You as the user are entitled to choose the terms under which to adopt Spoon.
*/
package spoon.reflect.code;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.template.TemplateParameter;
import java.util.List;
import static spoon.reflect.path.CtRole.BODY;
import static spoon.reflect.path.CtRole.CATCH;
import static spoon.reflect.path.CtRole.FINALIZER;
/**
* This code element defines a try
statement.
*
* Example:
*
* try {
* System.out.println("foo");
* } catch (Exception ignore) {}
*
*/
public interface CtTry extends CtStatement, TemplateParameter, CtBodyHolder {
/**
* Gets the catchers of this try
.
*/
@PropertyGetter(role = CATCH)
List getCatchers();
/**
* Sets the catchers of this try
.
*/
@PropertySetter(role = CATCH)
T setCatchers(List catchers);
/**
* Adds a catch block.
*/
@PropertySetter(role = CATCH)
T addCatcher(CtCatch catcher);
/**
* Adds a catch block at the specified position in the try
statement.
* Behaves similarly to {@link java.util.List#add(int, Object)}.
*
* @param position the position at which the catcher
is to be inserted
* @param catcher the catch statement to be inserted
* @return this try statement
* @throws IndexOutOfBoundsException if the position is out of range (position < 0 || position > number of catchers)
*/
@PropertySetter(role = CATCH)
CtTry addCatcherAt(int position, CtCatch catcher);
/**
* Removes a catch block.
*/
@PropertySetter(role = CATCH)
boolean removeCatcher(CtCatch catcher);
/**
* Gets the try body.
*/
@Override
@PropertyGetter(role = BODY)
CtBlock> getBody();
/**
* Gets the finalizer block of this try
(
* finally
part).
*/
@PropertyGetter(role = FINALIZER)
CtBlock> getFinalizer();
/**
* Sets the finalizer block of this try
(
* finally
part).
*/
@PropertySetter(role = FINALIZER)
T setFinalizer(CtBlock> finalizer);
@Override
CtTry clone();
}