Skip to content

Commit 42cf4f3

Browse files
Merge pull request #112 from moosetechnology/issue-109
fix #109
2 parents d1c7247 + b9da5aa commit 42cf4f3

File tree

4 files changed

+77
-50
lines changed

4 files changed

+77
-50
lines changed

lib/verveine.extractor.java.jar

62 Bytes
Binary file not shown.

src/fr/inria/verveine/extractor/java/visitors/defvisitors/VisitorClassMethodDef.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ public void endVisit(TypeDeclaration node) {
168168
@Override
169169
public boolean visit(ClassInstanceCreation node) {
170170
// System.err.println("TRACE, Visiting ClassInstanceCreation: " + node);
171-
if (node.getAnonymousClassDeclaration() != null) {
172-
anonymousSuperTypeName.push(Util.jdtTypeName(node.getType()));
173-
}
171+
possiblyAnonymousClassDeclaration(node);
174172
return super.visit(node);
175173
}
176174

src/fr/inria/verveine/extractor/java/visitors/refvisitors/VisitorTypeRefRef.java

+39-30
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import org.eclipse.jdt.core.dom.*;
66
import org.moosetechnology.model.famix.famixjavaentities.ContainerEntity;
77
import org.moosetechnology.model.famix.famixjavaentities.Method;
8-
import org.moosetechnology.model.famix.famixjavaentities.ParameterType;
9-
import org.moosetechnology.model.famix.famixjavaentities.ParametricClass;
108
import org.moosetechnology.model.famix.famixjavaentities.Reference;
119
import org.moosetechnology.model.famix.famixtraits.TNamedEntity;
1210
import org.moosetechnology.model.famix.famixtraits.TType;
@@ -70,18 +68,19 @@ public void endVisit(TypeDeclaration node) {
7068
public boolean visit(ClassInstanceCreation node) {
7169
possiblyAnonymousClassDeclaration(node);
7270

73-
//if (node.getAnonymousClassDeclaration() == null) {
74-
Expression expr = node.getExpression();
75-
if (expr != null) {
76-
expr.accept(this);
77-
}
78-
for (Type typeArg : (List<Type>)node.typeArguments()) {
79-
typeArg.accept(this);
80-
}
81-
for (Expression arg : (List<Expression>)node.arguments()) {
82-
arg.accept(this);
83-
}
84-
//}
71+
if (node.getExpression() != null) {
72+
node.getExpression().accept(this);
73+
}
74+
for (Type typeArg : (List<Type>)node.typeArguments()) {
75+
typeArg.accept(this);
76+
}
77+
for (Expression arg : (List<Expression>)node.arguments()) {
78+
arg.accept(this);
79+
}
80+
if (node.getAnonymousClassDeclaration() != null) {
81+
node.getAnonymousClassDeclaration().accept(this);
82+
}
83+
8584
return false;
8685
}
8786

@@ -225,7 +224,7 @@ public boolean visit(InstanceofExpression node) {
225224
@Override
226225
public boolean visit(FieldDeclaration node) {
227226
hasInitBlock(node); // to recover optional EntityDictionary.INIT_BLOCK_NAME method
228-
visitVariableDeclaration((List<VariableDeclaration>)node.fragments(), node.getType()); // to create the TypeRefs
227+
visitVariablesDeclaration((List<VariableDeclaration>)node.fragments(), node.getType()); // to create the TypeRefs
229228
return true;
230229
}
231230

@@ -242,6 +241,21 @@ public void endVisit(EnumConstantDeclaration node) {
242241
endVisitEnumConstantDeclaration(node);
243242
}
244243

244+
/**
245+
* SingleVariableDeclaration ::=
246+
* { ExtendedModifier } Type {Annotation} [ ... ] Identifier { Dimension } [ = Expression ]
247+
*/
248+
@Override
249+
public boolean visit(SingleVariableDeclaration node) {
250+
setVariableDeclaredType(
251+
node,
252+
referedType(
253+
node.getType(),
254+
(org.moosetechnology.model.famix.famixjavaentities.Type) context.topType(),
255+
false));
256+
return true;
257+
}
258+
245259
/**
246260
* VariableDeclarationExpression ::=
247261
* { ExtendedModifier } Type VariableDeclarationFragment
@@ -250,7 +264,7 @@ public void endVisit(EnumConstantDeclaration node) {
250264
@SuppressWarnings("unchecked")
251265
@Override
252266
public boolean visit(VariableDeclarationExpression node) {
253-
return visitVariableDeclaration((List<VariableDeclaration>)node.fragments(), node.getType());
267+
return visitVariablesDeclaration((List<VariableDeclaration>)node.fragments(), node.getType());
254268
}
255269

256270
/**
@@ -261,7 +275,7 @@ public boolean visit(VariableDeclarationExpression node) {
261275
@SuppressWarnings("unchecked")
262276
@Override
263277
public boolean visit(VariableDeclarationStatement node) {
264-
return visitVariableDeclaration((List<VariableDeclaration>)node.fragments(), node.getType());
278+
return visitVariablesDeclaration((List<VariableDeclaration>)node.fragments(), node.getType());
265279
}
266280

267281
@SuppressWarnings("unchecked")
@@ -308,25 +322,20 @@ public boolean visit(SimpleName node) {
308322
* VariableDeclaration ::=
309323
* SingleVariableDeclaration VariableDeclarationFragment
310324
*/
311-
private <T extends TWithTypes & TNamedEntity> boolean visitVariableDeclaration(List<VariableDeclaration> fragments, Type declType) {
312-
setVariablesDeclaredType(fragments, referedType(declType, (T) context.topType(), false));
325+
@SuppressWarnings("unchecked")
326+
private <T extends TWithTypes & TNamedEntity> boolean visitVariablesDeclaration(List<VariableDeclaration> fragments, Type declType) {
313327
for (VariableDeclaration varDecl : fragments) {
328+
TType declaredType = referedType(declType, (T) context.topType(), false);
329+
setVariableDeclaredType( varDecl, declaredType);
314330
varDecl.accept(this);
315331
}
316332
return false;
317333
}
318334

319-
// public boolean visit(SimpleName node) {
320-
// IBinding bnd = node.resolveBinding();
321-
// if ( (bnd != null) && (bnd instanceof ITypeBinding) ) {
322-
// referedType((ITypeBinding) bnd, (ContainerEntity) context.top(), !((ITypeBinding) bnd).isEnum());
323-
324-
private void setVariablesDeclaredType(List<VariableDeclaration> vars, TType varTyp) {
325-
for (VariableDeclaration var : vars) {
326-
TTypedEntity fmx = (TTypedEntity) dico.getEntityByKey(var.resolveBinding());
327-
if (fmx != null) {
328-
fmx.setDeclaredType(varTyp);
329-
}
335+
protected void setVariableDeclaredType(VariableDeclaration var, TType varTyp) {
336+
TTypedEntity fmx = (TTypedEntity) dico.getEntityByKey(var.resolveBinding());
337+
if (fmx != null) {
338+
fmx.setDeclaredType(varTyp);
330339
}
331340
}
332341

tests/fr/inria/verveine/extractor/java/VerveineJTest_AdHoc.java

+37-17
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
package fr.inria.verveine.extractor.java;
55

66

7-
import fr.inria.verveine.extractor.java.utils.Util;
8-
import org.junit.Before;
9-
import org.junit.Test;
10-
import org.moosetechnology.model.famix.famixjavaentities.*;
11-
import org.moosetechnology.model.famix.famixjavaentities.Class;
12-
import org.moosetechnology.model.famix.famixjavaentities.Enum;
13-
import org.moosetechnology.model.famix.famixjavaentities.Package;
14-
import org.moosetechnology.model.famix.famixtraits.*;
7+
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertFalse;
9+
import static org.junit.Assert.assertNotNull;
10+
import static org.junit.Assert.assertNull;
11+
import static org.junit.Assert.assertSame;
12+
import static org.junit.Assert.assertTrue;
13+
import static org.junit.Assert.fail;
1514

1615
import java.io.File;
17-
import java.lang.Exception;
1816
import java.util.ArrayList;
1917
import java.util.Arrays;
2018
import java.util.Collection;
@@ -23,9 +21,34 @@
2321
import java.util.List;
2422
import java.util.Set;
2523

26-
import javax.swing.JFrame;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
import org.moosetechnology.model.famix.famixjavaentities.Access;
27+
import org.moosetechnology.model.famix.famixjavaentities.Attribute;
28+
import org.moosetechnology.model.famix.famixjavaentities.ContainerEntity;
29+
import org.moosetechnology.model.famix.famixjavaentities.Enum;
30+
import org.moosetechnology.model.famix.famixjavaentities.EnumValue;
31+
import org.moosetechnology.model.famix.famixjavaentities.Interface;
32+
import org.moosetechnology.model.famix.famixjavaentities.Invocation;
33+
import org.moosetechnology.model.famix.famixjavaentities.LocalVariable;
34+
import org.moosetechnology.model.famix.famixjavaentities.Method;
35+
import org.moosetechnology.model.famix.famixjavaentities.Package;
36+
import org.moosetechnology.model.famix.famixjavaentities.Parameter;
37+
import org.moosetechnology.model.famix.famixjavaentities.ParametricClass;
38+
import org.moosetechnology.model.famix.famixjavaentities.ParametricInterface;
39+
import org.moosetechnology.model.famix.famixjavaentities.Type;
40+
import org.moosetechnology.model.famix.famixtraits.TAccess;
41+
import org.moosetechnology.model.famix.famixtraits.TAttribute;
42+
import org.moosetechnology.model.famix.famixtraits.TEnumValue;
43+
import org.moosetechnology.model.famix.famixtraits.TInvocation;
44+
import org.moosetechnology.model.famix.famixtraits.TLocalVariable;
45+
import org.moosetechnology.model.famix.famixtraits.TMethod;
46+
import org.moosetechnology.model.famix.famixtraits.TNamedEntity;
47+
import org.moosetechnology.model.famix.famixtraits.TParameter;
48+
import org.moosetechnology.model.famix.famixtraits.TReference;
49+
import org.moosetechnology.model.famix.famixtraits.TType;
2750

28-
import static org.junit.Assert.*;
51+
import fr.inria.verveine.extractor.java.utils.Util;
2952

3053
/**
3154
* @author Nicolas Anquetil
@@ -151,11 +174,8 @@ public void testConstructorInvocations() {
151174
}
152175

153176
@ Test
154-
/*
155-
* issue https://github.com/moosetechnology/VerveineJ/issues/109
156-
* "creates two dependencies for one "new" instruction
157-
* instruction: new XYZ() results in an invocation of the constructor XYZ() + a reference to the type XYZ
158-
* The second is a mistake
177+
/* issue https://github.com/moosetechnology/VerveineJ/issues/109
178+
* no longer create a Reference to the type for "new" instruction
159179
*/
160180
public void testNoReferenceOnNew() {
161181
parse(new String[] {"test_src/ad_hoc/DefaultConstructor.java"});
@@ -164,7 +184,7 @@ public void testNoReferenceOnNew() {
164184
assertNotNull(aMethod);
165185

166186
assertEquals( 3, aMethod.numberOfOutgoingInvocations());
167-
/* new DefaultConstructor(); x.methodWithInstanceScope(); new JFrame("My title"); */
187+
/* new DefaultConstructor(); x.methodWithInstanceScope(); new JFrame(...); */
168188
assertEquals(0, aMethod.numberOfOutgoingReferences());
169189
}
170190

0 commit comments

Comments
 (0)