Skip to content

Commit

Permalink
Add default, private and static methods in interface support
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed Jun 16, 2019
1 parent 448b176 commit cdb695a
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@

public interface Declaration {
// Access flags for Class, Field, Method, Nested class, Module, Module Requires, Module Exports, Module Opens
int FLAG_PUBLIC = 0x0001; // C F M N . . . .
int FLAG_PRIVATE = 0x0002; // . F M N . . . .
int FLAG_PROTECTED = 0x0004; // . F M N . . . .
int FLAG_STATIC = 0x0008; // C F M N . . . .
int FLAG_FINAL = 0x0010; // C F M N . . . .
int FLAG_SYNCHRONIZED = 0x0020; // . . M . . . . .
int FLAG_SUPER = 0x0020; // C . . . . . . .
int FLAG_OPEN = 0x0020; // . . . . Mo . . .
int FLAG_TRANSITIVE = 0x0020; // . . . . . MR . .
int FLAG_VOLATILE = 0x0040; // . F . . . . . .
int FLAG_BRIDGE = 0x0040; // . . M . . . . .
int FLAG_STATIC_PHASE = 0x0040; // . . M . . MR . .
int FLAG_TRANSIENT = 0x0080; // . F . . . . . .
int FLAG_VARARGS = 0x0080; // . . M . . . . .
int FLAG_NATIVE = 0x0100; // . . M . . . . .
int FLAG_INTERFACE = 0x0200; // C . . N . . . .
int FLAG_ABSTRACT = 0x0400; // C . M N . . . .
int FLAG_STRICT = 0x0800; // . . M . . . . .
int FLAG_SYNTHETIC = 0x1000; // C F M N Mo MR ME MO
int FLAG_ANNOTATION = 0x2000; // C . . N . . . .
int FLAG_ENUM = 0x4000; // C F . N . . . .
int FLAG_MODULE = 0x8000; // C . . . . . . .
int FLAG_MANDATED = 0x8000; // . . . . Mo MR ME MO

int FLAG_PUBLIC = 0x0001; // C F M N . . . .
int FLAG_PRIVATE = 0x0002; // . F M N . . . .
int FLAG_PROTECTED = 0x0004; // . F M N . . . .
int FLAG_STATIC = 0x0008; // C F M N . . . .
int FLAG_FINAL = 0x0010; // C F M N . . . .
int FLAG_SYNCHRONIZED = 0x0020; // . . M . . . . .
int FLAG_SUPER = 0x0020; // C . . . . . . .
int FLAG_OPEN = 0x0020; // . . . . Mo . . .
int FLAG_TRANSITIVE = 0x0020; // . . . . . MR . .
int FLAG_VOLATILE = 0x0040; // . F . . . . . .
int FLAG_BRIDGE = 0x0040; // . . M . . . . .
int FLAG_STATIC_PHASE = 0x0040; // . . M . . MR . .
int FLAG_TRANSIENT = 0x0080; // . F . . . . . .
int FLAG_VARARGS = 0x0080; // . . M . . . . .
int FLAG_NATIVE = 0x0100; // . . M . . . . .
int FLAG_INTERFACE = 0x0200; // C . . N . . . .
int FLAG_ABSTRACT = 0x0400; // C . M N . . . .
int FLAG_STRICT = 0x0800; // . . M . . . . .
int FLAG_SYNTHETIC = 0x1000; // C F M N Mo MR ME MO
int FLAG_ANNOTATION = 0x2000; // C . . N . . . .
int FLAG_ENUM = 0x4000; // C F . N . . . .
int FLAG_MODULE = 0x8000; // C . . . . . . .
int FLAG_MANDATED = 0x8000; // . . . . Mo MR ME MO

// Extension
int FLAG_DEFAULT = 0x10000; // . . M . . . . .

void accept(DeclarationVisitor visitor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import org.jd.core.v1.model.classfile.attribute.*;
import org.jd.core.v1.model.classfile.constant.*;
import org.jd.core.v1.model.javasyntax.CompilationUnit;
import org.jd.core.v1.model.javasyntax.declaration.ExpressionVariableInitializer;
import org.jd.core.v1.model.javasyntax.declaration.FieldDeclarator;
import org.jd.core.v1.model.javasyntax.declaration.ModuleDeclaration;
import org.jd.core.v1.model.javasyntax.declaration.TypeDeclaration;
import org.jd.core.v1.model.javasyntax.declaration.*;
import org.jd.core.v1.model.javasyntax.expression.*;
import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference;
import org.jd.core.v1.model.javasyntax.reference.ElementValue;
Expand Down Expand Up @@ -180,11 +177,18 @@ protected List<ClassFileConstructorOrMethodDeclaration> convertMethods(Signature
} else if ("<clinit>".equals(name)) {
list.add(new ClassFileStaticInitializerDeclaration(bodyDeclaration, classFile, method, firstLineNumber));
} else {
ClassFileMethodDeclaration methodDeclaration;
SignatureParser.MethodTypes methodTypes = parser.parseMethodSignature(method);
list.add(new ClassFileMethodDeclaration(
list.add(methodDeclaration = new ClassFileMethodDeclaration(
bodyDeclaration, classFile, method, annotationReferences, name, methodTypes.typeParameters,
methodTypes.returned, methodTypes.parameters, methodTypes.exceptions, defaultAnnotationValue,
firstLineNumber));
if ((classFile.getAccessFlags() & Constants.ACC_INTERFACE) != 0) {
if (methodDeclaration.getFlags() == Constants.ACC_PUBLIC) {
// For interfaces, add 'default' access flag on public methods
methodDeclaration.setFlags(Declaration.FLAG_PUBLIC|Declaration.FLAG_DEFAULT);
}
}
}
}

Expand Down Expand Up @@ -284,7 +288,7 @@ protected ModuleDeclaration convertModuleDeclaration(ClassFile classFile) {
List<ModuleDeclaration.ServiceInfo> provides = convertModuleDeclarationServiceInfo(attributeModule.getProvides());

return new ModuleDeclaration(
attributeModule.getFlags(), attributeModule.getName(), attributeModule.getName(),
attributeModule.getFlags(), classFile.getInternalTypeName(), attributeModule.getName(),
attributeModule.getVersion(), requires, exports, opens, uses, provides);
}

Expand Down
Loading

0 comments on commit cdb695a

Please sign in to comment.