Skip to content

Commit

Permalink
feat(comment): WIP Adds comments in the AST
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 9, 2016
1 parent e69dff4 commit fb893b6
Show file tree
Hide file tree
Showing 17 changed files with 379 additions and 36 deletions.
33 changes: 33 additions & 0 deletions src/main/java/spoon/reflect/code/CtComment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (C) 2006-2015 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 code element defines a comment
*
*/
public interface CtComment extends CtElement {
String getContent();

boolean isInline();

<E extends CtComment> E setContent(String content);

<E extends CtComment> E setInline(boolean inline);
}
13 changes: 13 additions & 0 deletions src/main/java/spoon/reflect/declaration/CtElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package spoon.reflect.declaration;

import spoon.processing.FactoryAccessor;
import spoon.reflect.code.CtComment;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.reference.CtReference;
import spoon.reflect.reference.CtTypeReference;
Expand Down Expand Up @@ -253,4 +254,16 @@ <E extends CtElement> List<E> getAnnotatedChildren(
* Returns the metadata keys stored in an element.
*/
Set<String> getMetadataKeys();

<E extends CtElement> E setComments(List<CtComment> comments);

/**
* The list of comments
* @return the list of comment
*/
List<CtComment> getComments();

<E extends CtElement> E addComment(CtComment comment);

<E extends CtElement> E removeComment(CtComment comment);
}
6 changes: 6 additions & 0 deletions src/main/java/spoon/reflect/factory/CoreFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import spoon.reflect.code.CtCatchVariable;
import spoon.reflect.code.CtCodeSnippetExpression;
import spoon.reflect.code.CtCodeSnippetStatement;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtConditional;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtContinue;
Expand Down Expand Up @@ -443,6 +444,11 @@ SourcePosition createSourcePosition(
*/
CtCodeSnippetStatement createCodeSnippetStatement();

/**
* Creates a comment.
*/
CtComment createComment();

/**
* Gets the main factory of that core factory (cannot be <code>null</code>).
*/
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/spoon/reflect/visitor/CtAbstractVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package spoon.reflect.visitor;

import java.lang.annotation.Annotation;

import spoon.reflect.code.CtAnnotationFieldAccess;
import spoon.reflect.code.CtArrayRead;
import spoon.reflect.code.CtArrayWrite;
Expand All @@ -31,6 +29,7 @@
import spoon.reflect.code.CtCatchVariable;
import spoon.reflect.code.CtCodeSnippetExpression;
import spoon.reflect.code.CtCodeSnippetStatement;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtConditional;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtContinue;
Expand Down Expand Up @@ -90,6 +89,8 @@
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.reference.CtUnboundVariableReference;

import java.lang.annotation.Annotation;

/** Provides an empty implementation of CtVIsitor.
* See {@link CtScanner} for a much more powerful implementation of CtVisitor.
*/
Expand Down Expand Up @@ -447,4 +448,9 @@ public <T> void visitCtFieldWrite(CtFieldWrite<T> fieldWrite) {
public <T> void visitCtSuperAccess(CtSuperAccess<T> f) {

}

@Override
public void visitCtComment(CtComment comment) {

}
}
7 changes: 7 additions & 0 deletions src/main/java/spoon/reflect/visitor/CtInheritanceScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import spoon.reflect.code.CtCodeElement;
import spoon.reflect.code.CtCodeSnippetExpression;
import spoon.reflect.code.CtCodeSnippetStatement;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtConditional;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtContinue;
Expand Down Expand Up @@ -834,6 +835,12 @@ public <T> void visitCtVariableWrite(CtVariableWrite<T> e) {
scanCtVisitable(e);
}

@Override
public void visitCtComment(CtComment e) {
scanCtElement(e);
scanCtVisitable(e);
}

public <T> void visitCtAnnotationFieldAccess(
CtAnnotationFieldAccess<T> e) {
visitCtVariableRead(e);
Expand Down
Loading

0 comments on commit fb893b6

Please sign in to comment.