Skip to content

Commit 3b7967e

Browse files
committed
Discover interface methods
1 parent 71e9319 commit 3b7967e

File tree

8 files changed

+71
-24
lines changed

8 files changed

+71
-24
lines changed

lang-java/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
</dependencies>
106106

107107
<build>
108+
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
108109
<plugins>
109110
<plugin>
110111
<groupId>org.apache.maven.plugins</groupId>

lang-java/src/main/java/org/eclipse/steady/java/ClassFileAnalyzer.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,15 @@ public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException
107107
// TODO HP, 4.4.16: This does not yet seem to work
108108
ClassPoolUpdater.getInstance().updateClasspath(ctclass, this.file);
109109

110-
// Only add constructs of ctclass is either a class or enum (no interfaces)
111-
if (ctclass.isInterface()) {
112-
ClassFileAnalyzer.log.debug("Interface [" + ctclass.getName() + "] skipped");
113-
} else {
114-
// Use a class visitor to get all constructs from the class file
115-
final ClassVisitor cv = new ClassVisitor(ctclass);
116-
final Set<ConstructId> temp_constructs = cv.getConstructs();
117-
118-
// Add all constructs with a "" body
119-
// TODO: Change Construct so that string (for source files) and binary bodies (file
120-
// compiled classes) can be covered
121-
for (ConstructId c : temp_constructs) this.constructs.put(c, new Construct(c, ""));
110+
// Use a class visitor to get all constructs from the class file
111+
final ClassVisitor cv = new ClassVisitor(ctclass);
112+
final Set<ConstructId> temp_constructs = cv.getConstructs();
113+
114+
// Add all constructs with a "" body
115+
// TODO: Change Construct so that string (for source files) and binary bodies (file
116+
// compiled classes) can be covered
117+
for (ConstructId c : temp_constructs) {
118+
this.constructs.put(c, new Construct(c, ""));
122119
}
123120
} catch (FileNotFoundException e) {
124121
throw new FileAnalysisException(e.getMessage(), e);

lang-java/src/main/java/org/eclipse/steady/java/JavaFileAnalyzer2.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ public void enterClassBody(@NotNull JavaParser.ClassBodyContext ctx) {
229229
this.constructIdBuilder.resetCurrentDeclarationContext();
230230
}
231231

232+
@Override public void enterInterfaceMemberDeclaration(JavaParser.InterfaceMemberDeclarationContext ctx) {
233+
if(ctx.interfaceMethodDeclaration()!=null) {
234+
// Peek JavaId and ensure it is an interface
235+
final JavaId class_ctx = (JavaId) this.contextStack.peek().getConstructId();
236+
this.isOfExpectedType(class_ctx, new JavaId.Type[] {JavaId.Type.INTERFACE}, true);
237+
238+
// Build the identifier
239+
final JavaMethodId id =
240+
new JavaMethodId(
241+
(JavaId) class_ctx,
242+
ctx.interfaceMethodDeclaration().IDENTIFIER().getText(),
243+
this.getParameters(ctx.interfaceMethodDeclaration().formalParameters().formalParameterList()));
244+
this.saveConstruct(id, this.getConstructContent(ctx));
245+
}
246+
}
247+
232248
/** {@inheritDoc} */
233249
@Override
234250
public void exitClassBody(@NotNull JavaParser.ClassBodyContext ctx) {
@@ -242,7 +258,7 @@ public void exitClassBody(@NotNull JavaParser.ClassBodyContext ctx) {
242258
public void enterMethodDeclaration(@NotNull JavaParser.MethodDeclarationContext ctx) {
243259
// Peek JavaId and ensure it is a class or enum
244260
final JavaId class_ctx = (JavaId) this.contextStack.peek().getConstructId();
245-
this.isOfExpectedType(class_ctx, new JavaId.Type[] {JavaId.Type.CLASS, JavaId.Type.ENUM}, true);
261+
this.isOfExpectedType(class_ctx, new JavaId.Type[] {JavaId.Type.CLASS, JavaId.Type.ENUM, JavaId.Type.INTERFACE}, true);
246262

247263
// Build the identifier
248264
final JavaMethodId id =

lang-java/src/main/java/org/eclipse/steady/java/JavaId.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,15 @@ public static JavaMethodId parseMethodQName(JavaId.Type _ctx_type, String _s) {
539539
JavaId def_ctx = null;
540540
JavaMethodId mid = null;
541541
try {
542-
if (_ctx_type.equals(JavaId.Type.CLASS)) def_ctx = JavaId.parseClassQName(_s.substring(0, j));
543-
else if (_ctx_type.equals(JavaId.Type.ENUM))
542+
if (_ctx_type.equals(JavaId.Type.CLASS)) {
543+
def_ctx = JavaId.parseClassQName(_s.substring(0, j));
544+
}
545+
else if (_ctx_type.equals(JavaId.Type.ENUM)) {
544546
def_ctx = JavaId.parseEnumQName(_s.substring(0, j));
547+
}
548+
else if (_ctx_type.equals(JavaId.Type.INTERFACE)) {
549+
def_ctx = JavaId.parseInterfaceQName(_s.substring(0, j));
550+
}
545551

546552
mid =
547553
new JavaMethodId(

lang-java/src/main/java/org/eclipse/steady/java/monitor/ClassVisitor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ private static final Logger getLog() {
108108
*/
109109
public ClassVisitor(CtClass _c) {
110110
// Build the JavaId
111-
if (_c.isInterface()) this.javaId = JavaId.parseInterfaceQName(_c.getName());
112-
else if (_c.isEnum()) this.javaId = JavaId.parseEnumQName(_c.getName());
113-
else this.javaId = JavaId.parseClassQName(_c.getName());
111+
if (_c.isInterface()) {
112+
this.javaId = JavaId.parseInterfaceQName(_c.getName());
113+
}
114+
else if (_c.isEnum()) {
115+
this.javaId = JavaId.parseEnumQName(_c.getName());
116+
}
117+
else {
118+
this.javaId = JavaId.parseClassQName(_c.getName());
119+
}
114120

115121
this.qname = this.javaId.getQualifiedName();
116122
this.c = _c;

lang-java/src/test/java/org/eclipse/steady/java/JavaFileAnalyzer2Test.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,19 @@ public void testAnonClassInInterfaceInit() {
9191

9292
// The parsing should produce the following 5 elements:
9393
final JavaPackageId p = new JavaPackageId("org.eclipse.steady.java.test");
94+
9495
final JavaInterfaceId itf =
9596
JavaId.parseInterfaceQName("org.eclipse.steady.java.test.ConfigurationKey");
97+
final JavaMethodId itf_m1 =
98+
JavaId.parseMethodQName(
99+
"org.eclipse.steady.java.test.ConfigurationKey.getType(String,int)");
100+
final JavaMethodId itf_m2 =
101+
JavaId.parseMethodQName(
102+
"org.eclipse.steady.java.test.ConfigurationKey.getKey()");
103+
final JavaMethodId itf_m3 =
104+
JavaId.parseMethodQName(
105+
"org.eclipse.steady.java.test.ConfigurationKey.getDefaultValue()");
106+
96107
final JavaClassId anon1 =
97108
JavaId.parseClassQName("org.eclipse.steady.java.test.ConfigurationKey$1");
98109
final JavaMethodId anon1_m =
@@ -105,9 +116,12 @@ public void testAnonClassInInterfaceInit() {
105116
"org.eclipse.steady.java.test.ConfigurationKey$2.compare(ConfigurationKey,ConfigurationKey)");
106117

107118
// Assertions
108-
assertEquals(6, constructs.size());
119+
assertEquals(9, constructs.size());
109120
assertTrue(constructs.containsKey(p));
110121
assertTrue(constructs.containsKey(itf));
122+
assertTrue(constructs.containsKey(itf_m1));
123+
assertTrue(constructs.containsKey(itf_m2));
124+
assertTrue(constructs.containsKey(itf_m3));
111125
assertTrue(constructs.containsKey(anon1));
112126
assertTrue(constructs.containsKey(anon1_m));
113127
assertTrue(constructs.containsKey(anon2));
@@ -205,7 +219,7 @@ public void testNamedClassInInterfaceAndAnonClassInConstructor() {
205219
"org.eclipse.steady.java.test.HttpRequestCompletionLog$Builder$1.getResponseContentType()");
206220

207221
// Assertions
208-
assertEquals(24, constructs.size());
222+
assertEquals(33, constructs.size());
209223
assertTrue(constructs.containsKey(p));
210224
assertTrue(constructs.containsKey(itf));
211225

@@ -381,7 +395,9 @@ public void testNestedDeclarationMess() {
381395

382396
// The parsing should produce the following elements:
383397
final JavaPackageId p = new JavaPackageId("org.eclipse.steady.java.test");
384-
final JavaInterfaceId itf = JavaId.parseInterfaceQName("org.eclipse.steady.java.test.DoSomethingElse");
398+
399+
final JavaInterfaceId itf = JavaId.parseInterfaceQName("org.eclipse.steady.java.test.NestedDeclarations$DoSomethingElse");
400+
final JavaMethodId itf_m = JavaId.parseMethodQName("org.eclipse.steady.java.test.NestedDeclarations$DoSomethingElse.doSomethingElse()");
385401

386402
final JavaClassId cl1 =
387403
JavaId.parseClassQName("org.eclipse.steady.java.test.NestedDeclarations"); // line 5
@@ -464,9 +480,12 @@ public void testNestedDeclarationMess() {
464480
JavaId.parseMethodQName(
465481
"org.eclipse.steady.java.test.NestedDeclarations$Foo$1DoThis$1.doThat()"); // line 72
466482

467-
assertEquals(26, constructs.size());
483+
assertEquals(27, constructs.size());
468484
assertTrue(constructs.containsKey(p));
485+
469486
assertTrue(constructs.containsKey(itf));
487+
assertTrue(constructs.containsKey(itf_m));
488+
470489
assertTrue(constructs.containsKey(cl1));
471490
assertTrue(constructs.containsKey(cl1_m));
472491

@@ -563,7 +582,8 @@ public void testCxfClass() {
563582
}
564583

565584
/**
566-
* Tests whether the constructs extracted from a Java file correspond to the ones obtained from the compiled file.
585+
* Tests whether the constructs extracted from a Java file correspond to the
586+
* ones obtained from the compiled file.
567587
*/
568588
@Test
569589
public void testCompareConstructCreation() {

lang-java/src/test/java/org/eclipse/steady/java/test/ConfigurationKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public int compare(final ConfigurationKey key1, final ConfigurationKey key2) {
4141
}
4242
};
4343

44-
Class getType();
44+
Class getType(String a, int b);
4545

4646
String getKey();
4747

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@
397397
</dependencyManagement>
398398

399399
<build>
400+
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
400401
<plugins>
401402

402403
<!-- Flattens the pom.xml files included in artifacts,

0 commit comments

Comments
 (0)