Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: refactor(label): remove labelledStatement that was not used #1398

Merged
merged 5 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/spoon/Metamodel.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static Set<CtType<?>> getAllMetamodelInterfaces() {
result.add(factory.Type().get(spoon.reflect.code.CtInvocation.class));
result.add(factory.Type().get(spoon.reflect.code.CtJavaDoc.class));
result.add(factory.Type().get(spoon.reflect.code.CtJavaDocTag.class));
result.add(factory.Type().get(spoon.reflect.code.CtLabelledFlowBreak.class));
result.add(factory.Type().get(spoon.reflect.code.CtLambda.class));
result.add(factory.Type().get(spoon.reflect.code.CtLiteral.class));
result.add(factory.Type().get(spoon.reflect.code.CtLocalVariable.class));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/generating/CloneVisitorGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private CtInvocation<Object> createFactoryInvocation(CtVariableAccess<CtElement>
private final List<String> excludesAST = Arrays.asList(//
"spoon.support.reflect.declaration.CtTypeInformationImpl", "spoon.support.reflect.code.CtAbstractInvocationImpl", //
"spoon.support.reflect.declaration.CtTypedElementImpl", "spoon.support.reflect.declaration.CtVariableImpl", //
"spoon.support.reflect.reference.CtActualTypeContainerImpl", "spoon.support.reflect.code.CtCFlowBreakImpl", //
"spoon.support.reflect.reference.CtActualTypeContainerImpl", "spoon.support.reflect.code.CtCFlowBreakImpl", "spoon.support.reflect.code.CtLabelledFlowBreakImpl", //
"spoon.support.reflect.declaration.CtCodeSnippetImpl", "spoon.support.reflect.declaration.CtFormalTypeDeclarerImpl", //
"spoon.support.reflect.declaration.CtGenericElementImpl", "spoon.support.reflect.reference.CtGenericElementReferenceImpl", //
"spoon.support.reflect.declaration.CtModifiableImpl", "spoon.support.reflect.declaration.CtMultiTypedElementImpl", //
Expand Down
21 changes: 1 addition & 20 deletions src/main/java/spoon/reflect/code/CtBreak.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
*/
package spoon.reflect.code;

import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;

import static spoon.reflect.path.CtRole.TARGET_LABEL;


/**
* This code element defines a break statement.
* Example:
Expand All @@ -33,20 +27,7 @@
* }
* </pre>
*/
public interface CtBreak extends CtCFlowBreak {
/**
* Gets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertyGetter(role = TARGET_LABEL)
String getTargetLabel();

/**
* Sets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertySetter(role = TARGET_LABEL)
<T extends CtBreak> T setTargetLabel(String targetLabel);
public interface CtBreak extends CtLabelledFlowBreak {

@Override
CtBreak clone();
Expand Down
33 changes: 1 addition & 32 deletions src/main/java/spoon/reflect/code/CtContinue.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
*/
package spoon.reflect.code;

import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;

import static spoon.reflect.path.CtRole.TARGET_LABEL;


/**
* This code element defines the continue statement.
* Example:
Expand All @@ -33,32 +27,7 @@
* }
* </pre>
*/
public interface CtContinue extends CtCFlowBreak {
/**
* Gets the statement where the control flow continues (null if no label
* defined).
*/
CtStatement getLabelledStatement();

/**
* Sets the statement where the control flow continues (null if no label
* defined).
*/
<T extends CtContinue> T setLabelledStatement(CtStatement labelledStatement);

/**
* Gets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertyGetter(role = TARGET_LABEL)
String getTargetLabel();

/**
* Sets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertySetter(role = TARGET_LABEL)
<T extends CtContinue> T setTargetLabel(String targetLabel);
public interface CtContinue extends CtLabelledFlowBreak {

@Override
CtContinue clone();
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/spoon/reflect/code/CtLabelledFlowBreak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (C) 2006-2017 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.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.support.DerivedProperty;

import static spoon.reflect.path.CtRole.TARGET_LABEL;

/**
* This abstract code element represents all the statements that break the
* control flow of the program and which can support a label.
*/
public interface CtLabelledFlowBreak extends CtCFlowBreak {
/**
* Gets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertyGetter(role = TARGET_LABEL)
String getTargetLabel();

/**
* Sets the label from which the control flow breaks (null if no label
* defined).
*/
@PropertySetter(role = TARGET_LABEL)
<T extends CtLabelledFlowBreak> T setTargetLabel(String targetLabel);

@DerivedProperty
CtStatement getLabelledStatement();
}
3 changes: 0 additions & 3 deletions src/main/java/spoon/reflect/path/CtRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ public static CtRole fromName(String name) {
if ("cases".equals(name)) {
return CASE;
}
if ("labelledstatement".equals(name)) {
return LABEL;
}
if ("enumvalues".equals(name) || "elementvalues".equals(name)) {
return VALUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ public void visitCtContinue(final spoon.reflect.code.CtContinue continueStatemen
spoon.reflect.code.CtContinue other = ((spoon.reflect.code.CtContinue) (this.stack.peek()));
enter(continueStatement);
biScan(continueStatement.getAnnotations(), other.getAnnotations());
biScan(continueStatement.getLabelledStatement(), other.getLabelledStatement());
biScan(continueStatement.getComments(), other.getComments());
exit(continueStatement);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/spoon/reflect/visitor/CtInheritanceScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import spoon.reflect.code.CtInvocation;
import spoon.reflect.code.CtJavaDoc;
import spoon.reflect.code.CtJavaDocTag;
import spoon.reflect.code.CtLabelledFlowBreak;
import spoon.reflect.code.CtLambda;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.code.CtLocalVariable;
Expand Down Expand Up @@ -182,6 +183,12 @@ public <T> void scanCtAbstractInvocation(CtAbstractInvocation<T> a) {
public void scanCtCFlowBreak(CtCFlowBreak flowBreak) {
}

/**
* Scans a labelled control flow break.
*/
public void scanCtLabelledFlowBreak(CtLabelledFlowBreak labelledFlowBreak) {
}

/**
* Scans an abstract code element.
*/
Expand Down Expand Up @@ -430,6 +437,7 @@ public <R> void visitCtBlock(CtBlock<R> e) {
}

public void visitCtBreak(CtBreak e) {
scanCtLabelledFlowBreak(e);
scanCtCFlowBreak(e);
scanCtStatement(e);
scanCtCodeElement(e);
Expand Down Expand Up @@ -493,6 +501,7 @@ public <T> void visitCtConstructor(CtConstructor<T> e) {
}

public void visitCtContinue(CtContinue e) {
scanCtLabelledFlowBreak(e);
scanCtCFlowBreak(e);
scanCtStatement(e);
scanCtCodeElement(e);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/spoon/reflect/visitor/CtScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ public <T> void visitCtConstructor(final CtConstructor<T> c) {
public void visitCtContinue(final CtContinue continueStatement) {
enter(continueStatement);
scan(continueStatement.getAnnotations());
scan(continueStatement.getLabelledStatement());
scan(continueStatement.getComments());
exit(continueStatement);
}
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/spoon/support/reflect/code/CtBreakImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
*/
package spoon.support.reflect.code;

import spoon.reflect.code.CtLabelledFlowBreak;
import spoon.reflect.code.CtBreak;
import spoon.reflect.code.CtStatement;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.reflect.annotations.MetamodelPropertyField;
import spoon.reflect.visitor.filter.ParentFunction;

import java.util.List;

public class CtBreakImpl extends CtStatementImpl implements CtBreak {
private static final long serialVersionUID = 1L;
Expand All @@ -38,11 +44,27 @@ public String getTargetLabel() {
}

@Override
public <T extends CtBreak> T setTargetLabel(String targetLabel) {
public <T extends CtLabelledFlowBreak> T setTargetLabel(String targetLabel) {
this.targetLabel = targetLabel;
return (T) this;
}

@Override
public CtStatement getLabelledStatement() {
List<CtStatement> listParents = this.map(new ParentFunction().includingSelf(true)).list();

for (CtElement parent : listParents) {
if (parent instanceof CtStatement) {
CtStatement statement = (CtStatement) parent;

if (statement.getLabel() != null && statement.getLabel().equals(this.getTargetLabel())) {
return statement;
}
}
}
return null;
}

@Override
public CtBreak clone() {
return (CtBreak) super.clone();
Expand Down
40 changes: 22 additions & 18 deletions src/main/java/spoon/support/reflect/code/CtContinueImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
*/
package spoon.support.reflect.code;

import spoon.reflect.code.CtLabelledFlowBreak;
import spoon.reflect.annotations.MetamodelPropertyField;
import spoon.reflect.code.CtContinue;
import spoon.reflect.code.CtStatement;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.path.CtRole;
import spoon.reflect.visitor.CtVisitor;
import spoon.reflect.annotations.MetamodelPropertyField;
import spoon.reflect.visitor.filter.ParentFunction;

import java.util.List;

public class CtContinueImpl extends CtStatementImpl implements CtContinue {
private static final long serialVersionUID = 1L;

@MetamodelPropertyField(role = CtRole.LABEL)
CtStatement labelledStatement;

@MetamodelPropertyField(role = CtRole.TARGET_LABEL)
String targetLabel;

Expand All @@ -37,28 +39,30 @@ public void accept(CtVisitor visitor) {
}

@Override
public CtStatement getLabelledStatement() {
return labelledStatement;
public String getTargetLabel() {
return targetLabel;
}

@Override
public <T extends CtContinue> T setLabelledStatement(CtStatement labelledStatement) {
if (labelledStatement != null) {
labelledStatement.setParent(this);
}
this.labelledStatement = labelledStatement;
public <T extends CtLabelledFlowBreak> T setTargetLabel(String targetLabel) {
this.targetLabel = targetLabel;
return (T) this;
}

@Override
public String getTargetLabel() {
return targetLabel;
}
public CtStatement getLabelledStatement() {
List<CtStatement> listParents = this.map(new ParentFunction().includingSelf(true)).list();

@Override
public <T extends CtContinue> T setTargetLabel(String targetLabel) {
this.targetLabel = targetLabel;
return (T) this;
for (CtElement parent : listParents) {
if (parent instanceof CtStatement) {
CtStatement statement = (CtStatement) parent;

if (statement.getLabel() != null && statement.getLabel().equals(this.getTargetLabel())) {
return statement;
}
}
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public <T> void visitCtConstructor(final spoon.reflect.declaration.CtConstructor
public void visitCtContinue(final spoon.reflect.code.CtContinue continueStatement) {
spoon.reflect.code.CtContinue aCtContinue = spoon.support.visitor.clone.CloneBuilder.build(this.builder, continueStatement, continueStatement.getFactory().Core().createContinue());
aCtContinue.setAnnotations(spoon.support.visitor.equals.CloneHelper.clone(continueStatement.getAnnotations()));
aCtContinue.setLabelledStatement(spoon.support.visitor.equals.CloneHelper.clone(continueStatement.getLabelledStatement()));
aCtContinue.setComments(spoon.support.visitor.equals.CloneHelper.clone(continueStatement.getComments()));
this.other = aCtContinue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,25 +745,10 @@ public <T> void visitCtConstructor(final spoon.reflect.declaration.CtConstructor
replaceInListIfExist(c.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(c));
}

// auto-generated, see spoon.generating.ReplacementVisitorGenerator
class CtContinueLabelledStatementReplaceListener implements spoon.generating.replace.ReplaceListener<spoon.reflect.code.CtStatement> {
private final spoon.reflect.code.CtContinue element;

CtContinueLabelledStatementReplaceListener(spoon.reflect.code.CtContinue element) {
this.element = element;
}

@java.lang.Override
public void set(spoon.reflect.code.CtStatement replace) {
this.element.setLabelledStatement(replace);
}
}

// auto-generated, see spoon.generating.ReplacementVisitorGenerator
@java.lang.Override
public void visitCtContinue(final spoon.reflect.code.CtContinue continueStatement) {
replaceInListIfExist(continueStatement.getAnnotations(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementAnnotationsReplaceListener(continueStatement));
replaceElementIfExist(continueStatement.getLabelledStatement(), new spoon.support.visitor.replace.ReplacementVisitor.CtContinueLabelledStatementReplaceListener(continueStatement));
replaceInListIfExist(continueStatement.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(continueStatement));
}

Expand Down
Loading