Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public List<Modifier> clearVisibility(ASTNode body)

public void addModifier(ASTNode body, ModifierKeyword keyword)
{
getInternalModifiers(body).add(body.getAST().newModifier(keyword));
if (!hasModifier(body, keyword)) {
getInternalModifiers(body).add(body.getAST().newModifier(keyword));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thought. I guess I had originally assumed that the Eclipse JDT was "smart". Good fix!

}
}

public void removeModifier(ASTNode body, ModifierKeyword keyword)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jboss.forge.test.parser.java;

import static org.junit.Assert.assertEquals;

import java.io.InputStream;

import org.jboss.forge.parser.JavaParser;
import org.jboss.forge.parser.java.impl.MethodImpl;
import org.jboss.forge.parser.java.source.JavaClassSource;
import org.jboss.forge.parser.java.source.MethodSource;
import org.junit.Assert;
import org.junit.Test;

/**
* @author <a href="mailto:salemelrahal@gmail.com">Salem Elrahal</a>
*/
public class MethodModifierTest {

@Test
public void testDuplicateMethodModifier() throws Exception
{
MethodSource<JavaClassSource> method = JavaParser.create(JavaClassSource.class).addMethod("public static void test()");
((MethodImpl<?>)method).setStatic(true);
Assert.assertFalse(method.toString().contains("static static"));
Assert.assertTrue(method.toString().contains("static"));
}
}