Skip to content
Open
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 codemodel/src/main/java/com/sun/codemodel/JMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public final class JMod {
public final static int SYNCHRONIZED = 0x080;
public final static int TRANSIENT = 0x100;
public final static int VOLATILE = 0x200;
public final static int DEFAULT = 0x400;
}
7 changes: 6 additions & 1 deletion codemodel/src/main/java/com/sun/codemodel/JMods.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class JMods implements JGenerable {
| JMod.STATIC | JMod.FINAL
| JMod.TRANSIENT | JMod.VOLATILE);
private static int METHOD = (JMod.PUBLIC | JMod.PRIVATE | JMod.PROTECTED | JMod.FINAL
| JMod.ABSTRACT | JMod.STATIC | JMod.NATIVE | JMod.SYNCHRONIZED);
| JMod.ABSTRACT | JMod.STATIC | JMod.NATIVE | JMod.SYNCHRONIZED | JMod.DEFAULT);
private static int CLASS = (JMod.PUBLIC | JMod.PRIVATE | JMod.PROTECTED
| JMod.STATIC | JMod.FINAL | JMod.ABSTRACT);
private static int INTERFACE = JMod.PUBLIC;
Expand Down Expand Up @@ -145,6 +145,10 @@ public void setFinal(boolean newValue) {
setFlag(JMod.FINAL, newValue);
}

public void setDefault(boolean newValue) {
setFlag(JMod.DEFAULT, newValue);
}

private void setFlag(int bit, boolean newValue) {
mods = (mods & ~bit) | (newValue ? bit : 0);
}
Expand All @@ -160,6 +164,7 @@ public void generate(JFormatter f) {
if ((mods & JMod.SYNCHRONIZED) != 0) f.p("synchronized");
if ((mods & JMod.TRANSIENT) != 0) f.p("transient");
if ((mods & JMod.VOLATILE) != 0) f.p("volatile");
if ((mods & JMod.DEFAULT) != 0) f.p("default");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sun.codemodel.tests;

import org.junit.Test;

import com.sun.codemodel.ClassType;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JMod;
import com.sun.codemodel.writer.SingleStreamCodeWriter;

public class DefaultMethodTest {

@Test
public void defaultMethodOnAnInterface() throws Exception {
JCodeModel cm = new JCodeModel();
JDefinedClass cls = cm._class(JMod.PUBLIC, "TestInterface", ClassType.INTERFACE);

cls.method(JMod.DEFAULT, cm.VOID, "defaultFoo");

cm.build(new SingleStreamCodeWriter(System.out));
}
}