Skip to content

Commit

Permalink
added interface CtBodyHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Nov 10, 2016
1 parent a9da3fc commit 47f3c23
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 21 deletions.
30 changes: 30 additions & 0 deletions src/main/java/spoon/reflect/code/CtBodyHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2006-2016 INRIA and contributors
* Spoon - http://spoon.gforge.inria.fr/
*
* This software is governed by the CeCILL-C License under French law and
* abiding by the rules of distribution of free software. You can use, modify
* and/or redistribute the software under the terms of the CeCILL-C license as
* circulated by CEA, CNRS and INRIA at http://www.cecill.info.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package spoon.reflect.code;

import spoon.reflect.declaration.CtElement;

/**
* This abstract code element defines an element, which contains a body
*/
public interface CtBodyHolder extends CtElement {

/**
* Gets the body of this element
*/
CtStatement getBody();
}
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/code/CtCatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @see spoon.reflect.code.CtTry
*/
public interface CtCatch extends CtCodeElement {
public interface CtCatch extends CtCodeElement, CtBodyHolder {

/**
* Gets the catch's parameter (a throwable).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/code/CtLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* This abstract code element defines a loop.
*/
public interface CtLoop extends CtStatement, TemplateParameter<Void> {
public interface CtLoop extends CtStatement, TemplateParameter<Void>, CtBodyHolder {

/**
* Gets the body of this loop.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/code/CtTry.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* } catch (Exception ignore) {}
* </pre>
*/
public interface CtTry extends CtStatement, TemplateParameter<Void> {
public interface CtTry extends CtStatement, TemplateParameter<Void>, CtBodyHolder {

/**
* Gets the <i>catchers</i> of this <code>try</code>.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/spoon/reflect/declaration/CtExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package spoon.reflect.declaration;

import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtBodyHolder;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtTypeReference;

Expand All @@ -27,7 +28,7 @@
* This element represents an executable element such as a method, a
* constructor, or an anonymous block.
*/
public interface CtExecutable<R> extends CtNamedElement, CtTypedElement<R> {
public interface CtExecutable<R> extends CtNamedElement, CtTypedElement<R>, CtBodyHolder {

/**
* The separator for a string representation of an executable.
Expand All @@ -44,7 +45,7 @@ public interface CtExecutable<R> extends CtNamedElement, CtTypedElement<R> {
/**
* Gets the body expression.
*/
<B extends R> CtBlock<B> getBody();
CtBlock<R> getBody();

/**
* Sets the body expression.
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/spoon/support/compiler/jdt/JDTCommentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtBodyHolder;
import spoon.reflect.code.CtCase;
import spoon.reflect.code.CtCatch;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtConditional;
import spoon.reflect.code.CtIf;
import spoon.reflect.code.CtLoop;
import spoon.reflect.code.CtNewArray;
import spoon.reflect.code.CtStatement;
import spoon.reflect.code.CtStatementList;
import spoon.reflect.code.CtSwitch;
import spoon.reflect.code.CtTry;
import spoon.reflect.cu.CompilationUnit;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.declaration.CtAnonymousExecutable;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtInterface;
import spoon.reflect.declaration.CtMethod;
Expand Down Expand Up @@ -436,14 +433,8 @@ public void scan(CtElement element) {
* @return body of element or null if this element has no body
*/
static CtElement getBody(CtElement e) {
if (e instanceof CtLoop) {
return ((CtLoop) e).getBody();
} else if (e instanceof CtExecutable) {
return ((CtExecutable<?>) e).getBody();
} else if (e instanceof CtTry) {
return ((CtTry) e).getBody();
} else if (e instanceof CtCatch) {
return ((CtCatch) e).getBody();
if (e instanceof CtBodyHolder) {
return ((CtBodyHolder) e).getBody();
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtLambdaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public <C extends CtNamedElement> C setSimpleName(String simpleName) {

@Override
@SuppressWarnings("unchecked")
public <B extends T> CtBlock<B> getBody() {
return (CtBlock<B>) body;
public CtBlock<T> getBody() {
return (CtBlock<T>) body;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public CtExecutableImpl() {

@Override
@SuppressWarnings("unchecked")
public <B extends R> CtBlock<B> getBody() {
return (CtBlock<B>) body;
public CtBlock<R> getBody() {
return (CtBlock<R>) body;
}

@Override
Expand Down

0 comments on commit 47f3c23

Please sign in to comment.