From 8e7c0a855752beea3911a1502e72431f9e2e4754 Mon Sep 17 00:00:00 2001 From: Muntazir Fadhel Date: Sat, 3 Sep 2016 01:05:49 -0400 Subject: [PATCH 1/2] test updates. --- clarpse/.checkstyle | 7 + .../invocation/AnnotationInvocation.java | 22 ++- .../invocation/ComponentInvocation.java | 49 ++++- .../clarity/invocation/EmptyInvocation.java | 20 ++- .../clarity/invocation/MethodInvocation.java | 20 ++- .../clarity/invocation/ThrownException.java | 20 ++- .../clarity/invocation/TypeDeclaration.java | 20 ++- .../com/clarity/invocation/TypeExtension.java | 20 ++- .../invocation/TypeImplementation.java | 21 ++- .../clarity/invocation/TypeInstantiation.java | 21 ++- .../com/clarity/invocation/TypeParameter.java | 27 +++ .../invocation/TypeReferenceInvocation.java | 8 - .../sources/MethodInvocationSourceImpl.java | 4 +- .../clarity/listener/JavaTreeListener.java | 142 ++++++++++----- .../com/clarity/sourcemodel/Component.java | 18 +- .../sourcemodel/OOPSourceModelConstants.java | 37 ++-- .../clarityparsecheckstyleconfig.xml | 2 +- .../com/clarity/java/ChildComponentsTest.java | 58 +++--- .../com/clarity/java/CommentsParsingTest.java | 103 +++++++++++ .../java/ComplexMethodInvocationsTest.java | 3 +- .../com/clarity/java/ComponentCodeTest.java | 9 +- .../java/SimpleMethodInvocationsTest.java | 4 +- .../com/clarity/java/TypeExtensionTest.java | 97 +++++----- .../clarity/java/TypeImplementationTest.java | 170 +++++++++--------- 24 files changed, 649 insertions(+), 253 deletions(-) create mode 100644 clarpse/.checkstyle create mode 100644 clarpse/src/main/java/com/clarity/invocation/TypeParameter.java delete mode 100644 clarpse/src/main/java/com/clarity/invocation/TypeReferenceInvocation.java create mode 100644 clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java diff --git a/clarpse/.checkstyle b/clarpse/.checkstyle new file mode 100644 index 0000000..c6c5ff0 --- /dev/null +++ b/clarpse/.checkstyle @@ -0,0 +1,7 @@ + + + + + + + diff --git a/clarpse/src/main/java/com/clarity/invocation/AnnotationInvocation.java b/clarpse/src/main/java/com/clarity/invocation/AnnotationInvocation.java index 327de95..743d2be 100644 --- a/clarpse/src/main/java/com/clarity/invocation/AnnotationInvocation.java +++ b/clarpse/src/main/java/com/clarity/invocation/AnnotationInvocation.java @@ -1,5 +1,6 @@ package com.clarity.invocation; +import java.io.Serializable; import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.HashMap; @@ -7,9 +8,11 @@ import java.util.Map; import java.util.Map.Entry; -public class AnnotationInvocation extends ComponentInvocation { +public class AnnotationInvocation extends ComponentInvocation implements Serializable { - private final List>> annotations = new ArrayList>>(); + private static final long serialVersionUID = 4146299386492074733L; + private final String type = "annotation"; + private List>> annotations = new ArrayList>>(); public List>> annotations() { return annotations; @@ -21,8 +24,23 @@ public AnnotationInvocation(final String invocationComponentName, final int line annotations.add(annotation); } + public AnnotationInvocation() { + super(); + } + + public AnnotationInvocation(String invokedComponent, List lines, + List>> annotations2) { + super(invokedComponent, lines); + annotations = annotations2; + } + @Override public boolean empty() { return (super.empty() && annotations.isEmpty()); } + + @Override + public Object clone() { + return new AnnotationInvocation(invokedComponent(), lines(), annotations); + } } diff --git a/clarpse/src/main/java/com/clarity/invocation/ComponentInvocation.java b/clarpse/src/main/java/com/clarity/invocation/ComponentInvocation.java index 43a4deb..28d3f2b 100644 --- a/clarpse/src/main/java/com/clarity/invocation/ComponentInvocation.java +++ b/clarpse/src/main/java/com/clarity/invocation/ComponentInvocation.java @@ -1,18 +1,37 @@ package com.clarity.invocation; +import java.io.Serializable; import java.util.ArrayList; +import java.util.List; import com.clarity.EmptyResource; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; +import com.fasterxml.jackson.annotation.JsonTypeInfo; /** * Represents an invocation of another component in the code base. * * @author Muntazir Fadhel */ -public abstract class ComponentInvocation implements EmptyResource { +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "type") +@JsonSubTypes({ + @Type(value = AnnotationInvocation.class, name = "annotation"), + @Type(value = EmptyInvocation.class, name = "empty"), + @Type(value = MethodInvocation.class, name = "method"), + @Type(value = ThrownException.class, name = "exception"), + @Type(value = TypeDeclaration.class, name = "declaration"), + @Type(value = TypeExtension.class, name = "extension"), + @Type(value = TypeImplementation.class, name = "implementation"), + @Type(value = TypeParameter.class, name = "typeparameter") }) +public abstract class ComponentInvocation implements EmptyResource, Serializable, Cloneable { - private final String invokedComponent; - private final ArrayList invocationLines = new ArrayList(); + private static final long serialVersionUID = -242718695900611890L; + private String invokedComponent = ""; + private List invocationLines = new ArrayList(); public ComponentInvocation(final String invocationComponentName, final int lineNum) { invokedComponent = invocationComponentName; @@ -26,17 +45,27 @@ public ComponentInvocation(final ComponentInvocation invocation) { invokedComponent = invocation.invokedComponent(); } + public ComponentInvocation() { + } + + public ComponentInvocation(String invokedComponent2, List lines) { + invokedComponent = invokedComponent2; + invocationLines = lines; + } + public String invokedComponent() { return invokedComponent; } - public void insertLineNum(final int invocationLineNums) { - if (!invocationLines.contains(invocationLineNums)) { - invocationLines.add(invocationLineNums); + public void insertLineNums(final List list) { + for (final Integer lineNum : list) { + if (!this.lines().contains(lineNum)) { + this.lines().add(lineNum); + } } } - public ArrayList lines() { + public List lines() { return invocationLines; } @@ -45,4 +74,10 @@ public ArrayList lines() { boolean empty() { return (invokedComponent.isEmpty() && invocationLines.isEmpty()); } + + @Override + public Object clone() throws CloneNotSupportedException { + + return super.clone(); + } } diff --git a/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java b/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java index 599d5db..15e8270 100644 --- a/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java +++ b/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java @@ -1,7 +1,12 @@ package com.clarity.invocation; -public class EmptyInvocation extends ComponentInvocation { +import java.io.Serializable; +import java.util.List; +public class EmptyInvocation extends ComponentInvocation implements Serializable{ + + private static final long serialVersionUID = -3058881761749807208L; + public final String type = "empty"; public EmptyInvocation(String invocationComponentName, int lineNum) { super(invocationComponentName, lineNum); } @@ -10,4 +15,17 @@ public EmptyInvocation(String invocationComponentName, int lineNum) { public boolean empty() { return true; } + + public EmptyInvocation() { + super(); + } + + public EmptyInvocation(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new EmptyInvocation(invokedComponent(), lines()); + } } diff --git a/clarpse/src/main/java/com/clarity/invocation/MethodInvocation.java b/clarpse/src/main/java/com/clarity/invocation/MethodInvocation.java index caa2667..ca3a502 100644 --- a/clarpse/src/main/java/com/clarity/invocation/MethodInvocation.java +++ b/clarpse/src/main/java/com/clarity/invocation/MethodInvocation.java @@ -1,10 +1,28 @@ package com.clarity.invocation; +import java.io.Serializable; +import java.util.List; -public class MethodInvocation extends ComponentInvocation { +public class MethodInvocation extends ComponentInvocation implements Serializable { + + private static final long serialVersionUID = 6518046913196400190L; + public final String type = "method"; public MethodInvocation(final String invocationComponentName, final int lineNum) { super(invocationComponentName, lineNum); } + + public MethodInvocation() { + super(); + } + + public MethodInvocation(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new MethodInvocation(invokedComponent(), lines()); + } } diff --git a/clarpse/src/main/java/com/clarity/invocation/ThrownException.java b/clarpse/src/main/java/com/clarity/invocation/ThrownException.java index d421726..ec357f3 100644 --- a/clarpse/src/main/java/com/clarity/invocation/ThrownException.java +++ b/clarpse/src/main/java/com/clarity/invocation/ThrownException.java @@ -1,9 +1,27 @@ package com.clarity.invocation; -public class ThrownException extends ComponentInvocation { +import java.io.Serializable; +import java.util.List; +public class ThrownException extends ComponentInvocation implements Serializable{ + + private static final long serialVersionUID = 3346563314076095662L; + public final String type = "exception"; public ThrownException(String invocationComponentName, int lineNum) { super(invocationComponentName, lineNum); } + public ThrownException() { + super(); + } + + public ThrownException(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new ThrownException(invokedComponent(), lines()); + } + } diff --git a/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java b/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java index eef7676..b687bd9 100644 --- a/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java +++ b/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java @@ -1,8 +1,26 @@ package com.clarity.invocation; -public class TypeDeclaration extends ComponentInvocation { +import java.io.Serializable; +import java.util.List; +public class TypeDeclaration extends ComponentInvocation implements Serializable{ + + private static final long serialVersionUID = 7304258760520469246L; + public final String type = "declaration"; public TypeDeclaration(final String invocationComponentName, final int lineNum) { super(invocationComponentName, lineNum); } + + public TypeDeclaration() { + super(); + } + + public TypeDeclaration(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new TypeDeclaration(invokedComponent(), lines()); + } } diff --git a/clarpse/src/main/java/com/clarity/invocation/TypeExtension.java b/clarpse/src/main/java/com/clarity/invocation/TypeExtension.java index 1640370..c326df2 100644 --- a/clarpse/src/main/java/com/clarity/invocation/TypeExtension.java +++ b/clarpse/src/main/java/com/clarity/invocation/TypeExtension.java @@ -1,8 +1,26 @@ package com.clarity.invocation; -public final class TypeExtension extends ComponentInvocation { +import java.io.Serializable; +import java.util.List; +public final class TypeExtension extends ComponentInvocation implements Serializable { + + private static final long serialVersionUID = 6641497827060470449L; + public final String type = "extension"; public TypeExtension(final String invocationComponentName, final int lineNum) { super(invocationComponentName, lineNum); } + + public TypeExtension() { + super(); + } + + public TypeExtension(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new TypeExtension(invokedComponent(), lines()); + } } diff --git a/clarpse/src/main/java/com/clarity/invocation/TypeImplementation.java b/clarpse/src/main/java/com/clarity/invocation/TypeImplementation.java index 4778fcb..43c48d1 100644 --- a/clarpse/src/main/java/com/clarity/invocation/TypeImplementation.java +++ b/clarpse/src/main/java/com/clarity/invocation/TypeImplementation.java @@ -1,9 +1,28 @@ package com.clarity.invocation; -public class TypeImplementation extends ComponentInvocation { +import java.io.Serializable; +import java.util.List; + +public class TypeImplementation extends ComponentInvocation implements Serializable { + + private static final long serialVersionUID = 7807962152246261233L; + public final String type = "implementation"; public TypeImplementation(String invocationComponentName, int lineNum) { super(invocationComponentName, lineNum); } + public TypeImplementation() { + super(); + } + + public TypeImplementation(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new TypeImplementation(invokedComponent(), lines()); + } + } diff --git a/clarpse/src/main/java/com/clarity/invocation/TypeInstantiation.java b/clarpse/src/main/java/com/clarity/invocation/TypeInstantiation.java index 73c0c24..8acce3b 100644 --- a/clarpse/src/main/java/com/clarity/invocation/TypeInstantiation.java +++ b/clarpse/src/main/java/com/clarity/invocation/TypeInstantiation.java @@ -1,9 +1,28 @@ package com.clarity.invocation; -public class TypeInstantiation extends ComponentInvocation { +import java.io.Serializable; +import java.util.List; + +public class TypeInstantiation extends ComponentInvocation implements Serializable { + + private static final long serialVersionUID = 7253490170234016131L; + public final String type = "instantiation"; public TypeInstantiation(String invocationComponentName, int lineNum) { super(invocationComponentName, lineNum); } + public TypeInstantiation() { + super(); + } + + public TypeInstantiation(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new TypeInstantiation(invokedComponent(), lines()); + } + } diff --git a/clarpse/src/main/java/com/clarity/invocation/TypeParameter.java b/clarpse/src/main/java/com/clarity/invocation/TypeParameter.java new file mode 100644 index 0000000..a9b06bb --- /dev/null +++ b/clarpse/src/main/java/com/clarity/invocation/TypeParameter.java @@ -0,0 +1,27 @@ +package com.clarity.invocation; + +import java.io.Serializable; +import java.util.List; + +public class TypeParameter extends ComponentInvocation implements Serializable { + + private static final long serialVersionUID = -6321838812633289752L; + public final String type = "typeparameter"; + + public TypeParameter(String invokedClass, int lineNumber) { + super(invokedClass, lineNumber); + } + + public TypeParameter() { + super(); + } + + public TypeParameter(String invokedComponent, List lines) { + super(invokedComponent, lines); + } + + @Override + public Object clone() { + return new TypeParameter(invokedComponent(), lines()); + } +} \ No newline at end of file diff --git a/clarpse/src/main/java/com/clarity/invocation/TypeReferenceInvocation.java b/clarpse/src/main/java/com/clarity/invocation/TypeReferenceInvocation.java deleted file mode 100644 index d6c41e6..0000000 --- a/clarpse/src/main/java/com/clarity/invocation/TypeReferenceInvocation.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.clarity.invocation; - -public class TypeReferenceInvocation extends ComponentInvocation { - - public TypeReferenceInvocation(String invokedClass, int lineNumber) { - super(invokedClass, lineNumber); - } -} \ No newline at end of file diff --git a/clarpse/src/main/java/com/clarity/invocation/sources/MethodInvocationSourceImpl.java b/clarpse/src/main/java/com/clarity/invocation/sources/MethodInvocationSourceImpl.java index ff2eefd..f3a63ea 100644 --- a/clarpse/src/main/java/com/clarity/invocation/sources/MethodInvocationSourceImpl.java +++ b/clarpse/src/main/java/com/clarity/invocation/sources/MethodInvocationSourceImpl.java @@ -74,7 +74,9 @@ private List getMethodComponentMatches(Component containingClassCmp, // figure out the number of parameters for this method.. int methodParams = 0; for (final String methodChildCmp : methodCmp.children()) { - if (srcModel.getComponent(methodChildCmp).componentType() == ComponentType.METHOD_PARAMETER_COMPONENT) { + final Component methodChildComponent = srcModel.getComponent(methodChildCmp); + if (methodChildComponent != null + && methodChildComponent.componentType() == ComponentType.METHOD_PARAMETER_COMPONENT) { methodParams++; } } diff --git a/clarpse/src/main/java/com/clarity/listener/JavaTreeListener.java b/clarpse/src/main/java/com/clarity/listener/JavaTreeListener.java index a8abde8..dad4781 100644 --- a/clarpse/src/main/java/com/clarity/listener/JavaTreeListener.java +++ b/clarpse/src/main/java/com/clarity/listener/JavaTreeListener.java @@ -17,7 +17,7 @@ import com.clarity.invocation.TypeDeclaration; import com.clarity.invocation.TypeExtension; import com.clarity.invocation.TypeImplementation; -import com.clarity.invocation.TypeReferenceInvocation; +import com.clarity.invocation.TypeParameter; import com.clarity.invocation.sources.BindedInvocationSource; import com.clarity.invocation.sources.InvocationSource; import com.clarity.invocation.sources.InvocationSourceChain; @@ -34,7 +34,6 @@ import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.TypeParameter; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.ConstructorDeclaration; import com.github.javaparser.ast.body.EnumConstantDeclaration; @@ -52,6 +51,7 @@ import com.github.javaparser.ast.expr.NormalAnnotationExpr; import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.ast.type.ReferenceType; @@ -111,6 +111,16 @@ public void populateModel() throws IOException { private void completeComponent() { if (!componentStack.isEmpty()) { final Component completedCmp = componentStack.pop(); + // include the processed component's invocations into its parent + // components + final Iterator invocationIterator = completedCmp.invocations().iterator(); + for (final Component parentCmp : componentStack) { + + while (invocationIterator.hasNext()) { + + parentCmp.insertComponentInvocation(invocationIterator.next()); + } + } srcModel.insertComponent(completedCmp); final List blockedSources = blockedInvocationSources .get(completedCmp.uniqueName()); @@ -147,13 +157,15 @@ private Component createComponent(Node node, ComponentType componentType) { final Component newCmp = new Component(); newCmp.setPackageName(currentPkg); newCmp.setComponentType(componentType); + String comment = ""; if (node.getComment() != null) { - newCmp.setComment(node.getComment().getContent()); + newCmp.setComment(node.getComment().toString()); + comment = node.getComment().toString(); } newCmp.setStartLine(String.valueOf(node.getBegin().line)); newCmp.setEndLine(String.valueOf(node.getEnd().line)); newCmp.setSourceFilePath(file.name()); - newCmp.setCode(node.toStringWithoutComments()); + newCmp.setCode(comment + node.toStringWithoutComments()); return newCmp; } @@ -194,10 +206,14 @@ public final void visit(ClassOrInterfaceDeclaration ctx, Object arg) { cmp = createComponent(ctx, OOPSourceModelConstants.ComponentType.CLASS_COMPONENT); } + cmp.setCode(file.content()); cmp.setAccessModifiers(resolveJavaParserModifiers(ctx.getModifiers())); cmp.setComponentName(generateComponentName(ctx.getName())); cmp.setName(ctx.getName()); cmp.setImports(currentImports); + if (ctx.getJavaDoc() != null) { + cmp.setComment(ctx.getJavaDoc().toString()); + } pointParentsToGivenChild(cmp); if (ctx.getExtends() != null) { @@ -219,18 +235,24 @@ public final void visit(ClassOrInterfaceDeclaration ctx, Object arg) { } componentStack.push(cmp); - super.visit(ctx, arg); + for (final Node node : ctx.getChildrenNodes()) { + if (node instanceof FieldDeclaration || node instanceof Statement || node instanceof Expression + || node instanceof MethodDeclaration || node instanceof ConstructorDeclaration + || node instanceof ClassOrInterfaceDeclaration || node instanceof EnumDeclaration) { + node.accept(this, arg); + } + } completeComponent(); } @Override - public final void visit(TypeParameter ctx, Object arg) { + public final void visit(com.github.javaparser.ast.TypeParameter ctx, Object arg) { final Component currComponent = componentStack.pop(); if (ctx.getTypeBound() != null) { for (final ClassOrInterfaceType type : ctx.getTypeBound()) { for (final Type innerType : type.getTypeArgs()) { currComponent - .insertComponentInvocation(new TypeReferenceInvocation( + .insertComponentInvocation(new TypeParameter( resolveType(innerType .toStringWithoutComments()), type .getBegin().line)); @@ -275,12 +297,22 @@ public final void visit(EnumDeclaration ctx, Object arg) { enumCmp.setName(ctx.getName()); enumCmp.setAccessModifiers(resolveJavaParserModifiers(ctx .getModifiers())); + enumCmp.setCode(file.content()); pointParentsToGivenChild(enumCmp); + if (ctx.getJavaDoc() != null) { + enumCmp.setComment(ctx.getJavaDoc().toString()); + } for (final AnnotationExpr annot : ctx.getAnnotations()) { populateAnnotation(enumCmp, annot); } componentStack.push(enumCmp); - super.visit(ctx, arg); + for (final Node node : ctx.getChildrenNodes()) { + if (node instanceof FieldDeclaration || node instanceof MethodDeclaration + || node instanceof ConstructorDeclaration || node instanceof ClassOrInterfaceDeclaration + || node instanceof EnumDeclaration || node instanceof EnumConstantDeclaration) { + node.accept(this, arg); + } + } completeComponent(); } @@ -295,6 +327,9 @@ public final void visit(final EnumConstantDeclaration ctx, Object arg) { for (final AnnotationExpr annot : ctx.getAnnotations()) { populateAnnotation(enumConstCmp, annot); } + if (ctx.getJavaDoc() != null) { + enumConstCmp.setComment(ctx.getJavaDoc().toString()); + } componentStack.push(enumConstCmp); super.visit(ctx, arg); completeComponent(); @@ -312,6 +347,7 @@ public final void visit(final MethodDeclaration ctx, Object arg) { } else { currMethodCmp.setValue("void"); } + currMethodCmp.setDeclarationTypeSnippet(ctx.getType().toStringWithoutComments()); currMethodCmp.setAccessModifiers(resolveJavaParserModifiers(ctx .getModifiers())); String formalParametersString = "("; @@ -321,6 +357,9 @@ public final void visit(final MethodDeclaration ctx, Object arg) { } formalParametersString += ")"; + if (ctx.getJavaDoc() != null) { + currMethodCmp.setComment(ctx.getJavaDoc().toString()); + } for (final AnnotationExpr annot : ctx.getAnnotations()) { populateAnnotation(currMethodCmp, annot); } @@ -341,6 +380,7 @@ public final void visit(final MethodDeclaration ctx, Object arg) { param, OOPSourceModelConstants.ComponentType.METHOD_PARAMETER_COMPONENT); methodParamCmp.setName(param.getName()); + methodParamCmp.setDeclarationTypeSnippet(param.getType().toStringWithoutComments()); for (final AnnotationExpr annot : param.getAnnotations()) { populateAnnotation(methodParamCmp, annot); } @@ -390,6 +430,12 @@ public final void visit(final ConstructorDeclaration ctx, Object arg) { currMethodCmp.setAccessModifiers(resolveJavaParserModifiers(ctx .getModifiers())); + if (ctx.getJavaDoc() != null) { + currMethodCmp.setComment(ctx.getJavaDoc().toString()); + } + + currMethodCmp.setDeclarationTypeSnippet("void"); + String formalParametersString = "("; if (ctx.getParameters() != null) { formalParametersString += getFormalParameterTypesList(ctx @@ -417,6 +463,7 @@ public final void visit(final ConstructorDeclaration ctx, Object arg) { final Component methodParamCmp = createComponent( param, OOPSourceModelConstants.ComponentType.CONSTRUCTOR_PARAMETER_COMPONENT); + methodParamCmp.setDeclarationTypeSnippet(param.getType().toStringWithoutComments()); methodParamCmp.setName(param.getName()); for (final AnnotationExpr annot : param.getAnnotations()) { populateAnnotation(methodParamCmp, annot); @@ -480,6 +527,7 @@ public final void visit(VariableDeclarationExpr ctx, Object arg) { for (final AnnotationExpr annot : ctx.getAnnotations()) { populateAnnotation(cmp, annot); } + cmp.setAccessModifiers(resolveJavaParserModifiers(ctx.getModifiers())); cmp.setValue(ctx.getType().toStringWithoutComments()); final List vars = new ArrayList(); @@ -505,41 +553,47 @@ public final void visit(VariableDeclarationExpr ctx, Object arg) { @Override public final void visit(FieldDeclaration ctx, Object arg) { - final Component currCmp = componentStack.peek(); - final Component cmp; - if (currCmp - .componentType() - .equals(OOPSourceModelConstants - .getJavaComponentTypes() - .get(OOPSourceModelConstants.ComponentType.INTERFACE_COMPONENT))) { - cmp = createComponent( - ctx, - OOPSourceModelConstants.ComponentType.INTERFACE_CONSTANT_COMPONENT); - } else { - cmp = createComponent(ctx, - OOPSourceModelConstants.ComponentType.FIELD_COMPONENT); - } - for (final AnnotationExpr annot : ctx.getAnnotations()) { - populateAnnotation(cmp, annot); - } - cmp.setValue(ctx.getType().toStringWithoutComments()); - cmp.setAccessModifiers(resolveJavaParserModifiers(ctx.getModifiers())); - final List vars = new ArrayList(); - for (final VariableDeclarator copy : ctx.getVariables()) { - final Component tmp = new Component(cmp); - tmp.setName(copy.getId().getName()); - tmp.setComponentName(generateComponentName(copy.getId().getName())); - pointParentsToGivenChild(tmp); - vars.add(tmp); - } + if (!componentStack.isEmpty()) { + final Component currCmp = componentStack.peek(); + final Component cmp; + + if (currCmp + .componentType() + .equals(OOPSourceModelConstants + .getJavaComponentTypes() + .get(OOPSourceModelConstants.ComponentType.INTERFACE_COMPONENT))) { + cmp = createComponent( + ctx, + OOPSourceModelConstants.ComponentType.INTERFACE_CONSTANT_COMPONENT); + } else { + cmp = createComponent(ctx, + OOPSourceModelConstants.ComponentType.FIELD_COMPONENT); + } + for (final AnnotationExpr annot : ctx.getAnnotations()) { + populateAnnotation(cmp, annot); + } + if (ctx.getJavaDoc() != null) { + cmp.setComment(ctx.getJavaDoc().toString()); + } + cmp.setValue(ctx.getType().toStringWithoutComments()); + cmp.setAccessModifiers(resolveJavaParserModifiers(ctx.getModifiers())); + final List vars = new ArrayList(); + for (final VariableDeclarator copy : ctx.getVariables()) { + final Component tmp = new Component(cmp); + tmp.setName(copy.getId().getName()); + tmp.setComponentName(generateComponentName(copy.getId().getName())); + pointParentsToGivenChild(tmp); + vars.add(tmp); + } - for (final Component tmpCmp : vars) { - componentStack.push(tmpCmp); - } - super.visit(ctx, arg); + for (final Component tmpCmp : vars) { + componentStack.push(tmpCmp); + } + super.visit(ctx, arg); - for (final VariableDeclarator copy : ctx.getVariables()) { - completeComponent(); + for (final VariableDeclarator copy : ctx.getVariables()) { + completeComponent(); + } } } @@ -587,6 +641,12 @@ public final void visit(ClassOrInterfaceType ctx, Object arg) { final Component currCmp = componentStack.pop(); currCmp.insertComponentInvocation(new TypeDeclaration( resolveType(ctx.getName()), ctx.getBegin().line)); + if (ctx.getTypeArgs() != null) { + for (final Type type : ctx.getTypeArgs()) { + currCmp.insertComponentInvocation(new TypeDeclaration(resolveType(type.toStringWithoutComments()), + type.getBegin().line)); + } + } componentStack.push(currCmp); } } diff --git a/clarpse/src/main/java/com/clarity/sourcemodel/Component.java b/clarpse/src/main/java/com/clarity/sourcemodel/Component.java index 3b17c30..3d86dbf 100644 --- a/clarpse/src/main/java/com/clarity/sourcemodel/Component.java +++ b/clarpse/src/main/java/com/clarity/sourcemodel/Component.java @@ -30,7 +30,7 @@ public final class Component implements Serializable { * Short name. */ private String name; - private String comment; + private String comment = ""; private String code; /** * Source file path from which the component was derived. @@ -39,7 +39,7 @@ public final class Component implements Serializable { private List imports = new ArrayList(); private List modifiers = new ArrayList(); private ComponentType type; - private ArrayList invocations = new ArrayList(); + private List invocations = new ArrayList(); /** * Formed by chaining parent components' names separated by a period. * @@ -65,6 +65,7 @@ public Component(final Component component) { end = component.endLine(); sourceFile = component.sourceFile(); code = component.code(); + comment = component.comment(); } public Component() { @@ -117,11 +118,16 @@ public String declarationTypeSnippet() { return declarationTypeSnippet; } - public ArrayList invocations() { + public List invocations() { return invocations; } public void insertComponentInvocation(final ComponentInvocation ref) { + for (final ComponentInvocation invocation : invocations) { + if (invocation.invokedComponent().equals(ref.invokedComponent()) && invocation.getClass().isInstance(ref)) { + invocation.insertLineNums(ref.lines()); + } + } invocations.add(ref); } @@ -158,7 +164,7 @@ public List modifiers() { public void insertAccessModifier(final String modifier) { if (OOPSourceModelConstants.getJavaAccessModifierMap().containsValue( modifier)) { - modifiers.add(modifier); + modifiers.add(modifier.toLowerCase()); } } @@ -253,7 +259,9 @@ public void setSourceFilePath(final String sourceFilePath) { } public void setAccessModifiers(List list) { - modifiers = list; + for (final String modifier : list) { + modifiers.add(modifier.toLowerCase()); + } } diff --git a/clarpse/src/main/java/com/clarity/sourcemodel/OOPSourceModelConstants.java b/clarpse/src/main/java/com/clarity/sourcemodel/OOPSourceModelConstants.java index d01352e..4df493f 100644 --- a/clarpse/src/main/java/com/clarity/sourcemodel/OOPSourceModelConstants.java +++ b/clarpse/src/main/java/com/clarity/sourcemodel/OOPSourceModelConstants.java @@ -1,5 +1,6 @@ package com.clarity.sourcemodel; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -236,8 +237,8 @@ public static Map getJavaDefaultClasses() { public enum AccessModifiers { - FINAL(""), ABSTRACT(""), INTERFACE(""), NATIVE(""), PRIVATE("-"), PROTECTED("#"), PUBLIC("+"), STATIC(""), STRICTFP(""), SYNCHRONIZED( - ""), TRANSIENT(""), NONE("~"), VOLATILE(""); + FINAL(""), ABSTRACT(""), INTERFACE(""), NATIVE(""), PRIVATE("-"), PROTECTED("#"), PUBLIC("+"), STATIC(""), STRICTFP( + ""), SYNCHRONIZED(""), TRANSIENT(""), NONE("~"), VOLATILE(""); private String umlClassDigramSymbol = null; @@ -274,32 +275,26 @@ public Class getMatchingClass() { * @author Muntazir Fadhel * */ - public enum ComponentType { + public enum ComponentType implements Serializable { - CLASS_COMPONENT(true, false, false), INTERFACE_COMPONENT(true, false, false), INTERFACE_CONSTANT_COMPONENT(false, false, - true), ENUM_COMPONENT(true, false, false), ANNOTATION_COMPONENT(false, false, false), METHOD_COMPONENT(false, - true, false), CONSTRUCTOR_COMPONENT(false, true, false), ENUM_CONSTANT_COMPONENT(false, false, true), FIELD_COMPONENT( - false, false, true), METHOD_PARAMETER_COMPONENT(false, false, true), CONSTRUCTOR_PARAMETER_COMPONENT(false, - false, true), LOCAL_VARIABLE_COMPONENT(false, false, true); + CLASS_COMPONENT("class", true, false, false), INTERFACE_COMPONENT("interface", true, false, false), INTERFACE_CONSTANT_COMPONENT("interface_constant", false, false, + true), ENUM_COMPONENT("enum", true, false, false), ANNOTATION_COMPONENT("annotation", false, false, false), METHOD_COMPONENT("method", false, + true, false), CONSTRUCTOR_COMPONENT("method", false, true, false), ENUM_CONSTANT_COMPONENT("enum_constant", false, false, true), FIELD_COMPONENT( + "field_variable", false, false, true), METHOD_PARAMETER_COMPONENT("method_parameter", false, false, + true), CONSTRUCTOR_PARAMETER_COMPONENT("constructor_parameter", false, + false, true), LOCAL_VARIABLE_COMPONENT("local_variable", false, false, true); private final boolean isBaseComponent; private final boolean isMethodComponent; private final boolean isVariableComponent; + private final String value; - /** - * Constructor. - * - * @param isBaseComponent - * true when component is base component. - * @param isMethodComponent - * true when method is method component. - * @param isVariableComponent - * true when component is a variable type component. - */ - ComponentType(final boolean isBaseComponent, final boolean isMethodComponent, final boolean isVariableComponent) { + ComponentType(final String value, final boolean isBaseComponent, final boolean isMethodComponent, + final boolean isVariableComponent) { this.isBaseComponent = isBaseComponent; this.isMethodComponent = isMethodComponent; this.isVariableComponent = isVariableComponent; + this.value = value; } public boolean isBaseComponent() { @@ -313,6 +308,10 @@ public boolean isMethodComponent() { public boolean isVariableComponent() { return isVariableComponent; } + + public String getValue() { + return value; + } } private static final Map JAVA_ACCESS_MODIFIER_MAP = new HashMap(); diff --git a/clarpse/src/main/resources/clarityparsecheckstyleconfig.xml b/clarpse/src/main/resources/clarityparsecheckstyleconfig.xml index 38d49bb..00744f0 100644 --- a/clarpse/src/main/resources/clarityparsecheckstyleconfig.xml +++ b/clarpse/src/main/resources/clarityparsecheckstyleconfig.xml @@ -18,6 +18,7 @@ + @@ -82,7 +83,6 @@ - diff --git a/clarpse/src/test/java/com/clarity/java/ChildComponentsTest.java b/clarpse/src/test/java/com/clarity/java/ChildComponentsTest.java index 993d0b4..5378e6d 100644 --- a/clarpse/src/test/java/com/clarity/java/ChildComponentsTest.java +++ b/clarpse/src/test/java/com/clarity/java/ChildComponentsTest.java @@ -12,93 +12,105 @@ public class ChildComponentsTest { - @Test + @Test public void testClassHasMethodChild() throws Exception { final String code = "class Test { void method(){} }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("Test").children().get(0).equals("Test.method()")); } - - @Test + + @Test public void testClassHasFieldVarChild() throws Exception { final String code = "class Test { String fieldVar; }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("Test").children().get(0).equals("Test.fieldVar")); } - - @Test + + @Test public void testIntefaceHasMethodChild() throws Exception { final String code = "interface Test { void method(); }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("Test").children().get(0).equals("Test.method()")); } - - @Test + + @Test + public void testMethodeHasMethodParamChild() throws Exception { + + final String code = "class Test { void method(String str); }"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("Test.method(java.lang.String)").children().get(0) + .equals("Test.method(java.lang.String).str")); + } + + @Test public void testIntefaceHasConstantFieldChild() throws Exception { final String code = "interface Test { String NEAR_TO_QUERY; }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("Test").children().get(0).equals("Test.NEAR_TO_QUERY")); } - - @Test + + @Test public void testClassHasNestedIntefaceChild() throws Exception { final String code = "class TestA { interface TestB { }}"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("TestA").children().get(0).equals("TestA.TestB")); } - - @Test + + @Test public void testClassHasNestedEnumChild() throws Exception { final String code = "class TestA { enum TestB { }}"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("TestA").children().get(0).equals("TestA.TestB")); } - - @Test + + @Test public void testEnumHasNestedConstantsChild() throws Exception { final String code = " enum TestA { A,B,C; }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("TestA").children().get(0).equals("TestA.A")); assertTrue(generatedSourceModel.getComponent("TestA").children().get(1).equals("TestA.B")); assertTrue(generatedSourceModel.getComponent("TestA").children().get(2).equals("TestA.C")); } - - @Test + + @Test public void testClassWithMultipleChildren() throws Exception { final String code = " class TestA { String fieldVar; String method(){} interface TestB {}}"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2", code)); final ClarpseProject parseService = new ClarpseProject(rawData); - OOPSourceCodeModel generatedSourceModel = parseService.result(); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("TestA").children().get(0).equals("TestA.fieldVar")); assertTrue(generatedSourceModel.getComponent("TestA").children().get(1).equals("TestA.method()")); assertTrue(generatedSourceModel.getComponent("TestA").children().get(2).equals("TestA.TestB")); diff --git a/clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java b/clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java new file mode 100644 index 0000000..a47c621 --- /dev/null +++ b/clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java @@ -0,0 +1,103 @@ +package com.clarity.java; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.clarity.parser.ClarpseProject; +import com.clarity.parser.Lang; +import com.clarity.parser.ParseRequestContent; +import com.clarity.parser.RawFile; +import com.clarity.sourcemodel.OOPSourceCodeModel; + +public class CommentsParsingTest { + + @Test + public void testClassLevelComment() throws Exception { + + final String code = "package test; /** Licensing */ import lol; /**A \n comment*/ public class Test { }"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("test.Test").comment().equalsIgnoreCase("A \n comment")); + } + + @Test + public void testInterfaceLevelComment() throws Exception { + + final String code = "package test; import lol; /**A \n comment*/ public class Test { }"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("test.Test").comment().equalsIgnoreCase("A \n comment")); + } + + @Test + public void testEnumLevelComment() throws Exception { + + final String code = "package test; import lol; /**A \n comment*/ public enum Test { }"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("test.Test").comment().equalsIgnoreCase("A \n comment")); + } + + @Test + public void testNestedClassLevelComment() throws Exception { + + final String code = "package test; /** Licensing */ import lol; public class Test { /**A \n comment*/ class Base{} }"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("test.Test.Base").comment().equalsIgnoreCase("A \n comment")); + } + + @Test + public void testMethodLevelComment() throws Exception { + + final String code = "public class Test { String fieldVar; /**lolcakes*/ void test() {} }"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("Test.test()").comment().equalsIgnoreCase("lolcakes")); + } + + @Test + public void testInterfaceMethodLevelComment() throws Exception { + + final String code = "public interface Test { /**lolcakes*/abstract void test();}"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("Test.test()").comment().equalsIgnoreCase("lolcakes")); + } + + @Test + public void testFieldVarLevelComment() throws Exception { + + final String code = "/*lolcakesv2*/ public class Test { /**lolcakes*/ String fieldVar;}"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("Test.fieldVar").comment().equalsIgnoreCase("lolcakes")); + } + + @Test + public void testMethodParamLevelComment() throws Exception { + + final String code = "public class Test { void aMethod(/**lolcakes*/ String methodParam){}}"; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file2.java", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + final OOPSourceCodeModel generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("Test.aMethod(java.lang.String).methodParam").comment() + .equalsIgnoreCase("lolcakes")); + } +} diff --git a/clarpse/src/test/java/com/clarity/java/ComplexMethodInvocationsTest.java b/clarpse/src/test/java/com/clarity/java/ComplexMethodInvocationsTest.java index e077732..17fa6b1 100644 --- a/clarpse/src/test/java/com/clarity/java/ComplexMethodInvocationsTest.java +++ b/clarpse/src/test/java/com/clarity/java/ComplexMethodInvocationsTest.java @@ -5,9 +5,9 @@ import org.junit.Test; import com.clarity.ClarpseUtil; +import com.clarity.parser.ClarpseProject; import com.clarity.parser.Lang; import com.clarity.parser.ParseRequestContent; -import com.clarity.parser.ClarpseProject; import com.clarity.parser.RawFile; import com.clarity.sourcemodel.OOPSourceCodeModel; import com.clarity.sourcemodel.OOPSourceModelConstants.ComponentInvocations; @@ -121,6 +121,7 @@ public void testClassATopMethodInvokesCustomObjAStaticMethod() throws Exception .equals("com.CustomObjA.staticMethod()")); } + @Test public void testClassATopMethodInvokesCustomObjASecondStaticMethod() throws Exception { diff --git a/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java b/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java index 8f24b89..c764208 100644 --- a/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java +++ b/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java @@ -15,26 +15,27 @@ public class ComponentCodeTest { @Test public void testClassLevelCode() throws Exception { - final String code = "public class Test { @Override Test(String str) { Object localVar;} @Deprecated interface Cakes { abstract void tester(); } }"; + final String code = "/** lol */ package lol; import test; /** class comment */ public class Test { @Override Test(String str) { Object localVar;} @Deprecated interface Cakes { abstract void tester(); } }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("Test").code().trim().replaceAll("[\\n\\t\\r ]", "") + assertTrue(generatedSourceModel.getComponent("lol.Test").code().trim().replaceAll("[\\n\\t\\r ]", "") .equalsIgnoreCase(code.trim().replaceAll("[\\n\\t ]", ""))); } @Test public void testMethodLevelCode() throws Exception { - final String code = "public class Test { @Override Test(String str) { Object localVar;} @Deprecated interface Cakes { abstract void tester(); } }"; + final String code = "public class Test { /*lol*/@Override Test(String str) { Object localVar;} @Deprecated interface Cakes { abstract void tester(); } }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("Test.Test(java.lang.String)").code().trim() .replaceAll("[\\n\\t\\r ]", "") - .equalsIgnoreCase("@Override Test(String str) { Object localVar;}".trim().replaceAll("[\\n\\t ]", ""))); + .equalsIgnoreCase( + "/*lol*/@Override Test(String str) { Object localVar;}".trim().replaceAll("[\\n\\t ]", ""))); } @Test diff --git a/clarpse/src/test/java/com/clarity/java/SimpleMethodInvocationsTest.java b/clarpse/src/test/java/com/clarity/java/SimpleMethodInvocationsTest.java index c9c9865..1839734 100644 --- a/clarpse/src/test/java/com/clarity/java/SimpleMethodInvocationsTest.java +++ b/clarpse/src/test/java/com/clarity/java/SimpleMethodInvocationsTest.java @@ -18,10 +18,10 @@ */ public class SimpleMethodInvocationsTest { - private static String codeFile1 = "package com;" + "import java.util.List; import foo.customObjA; " + private static String codeFile1 = "package com;" + "import java.util.List; import java.io.IOException; import foo.customObjA; " + "public class ClassA { " + " private String fieldVar;" - + " public String topMethod(String s, int t) { " + + " public String topMethod(String s, int t) throws IOException { " + " bottomMethod(s,t);" + " noParamsMethod();" + " return \"foo\";" diff --git a/clarpse/src/test/java/com/clarity/java/TypeExtensionTest.java b/clarpse/src/test/java/com/clarity/java/TypeExtensionTest.java index 4c69be9..6024abf 100644 --- a/clarpse/src/test/java/com/clarity/java/TypeExtensionTest.java +++ b/clarpse/src/test/java/com/clarity/java/TypeExtensionTest.java @@ -3,12 +3,11 @@ import org.junit.Assert; import org.junit.Test; +import com.clarity.parser.ClarpseProject; import com.clarity.parser.Lang; import com.clarity.parser.ParseRequestContent; -import com.clarity.parser.ClarpseProject; import com.clarity.parser.RawFile; import com.clarity.sourcemodel.OOPSourceCodeModel; -import com.clarity.sourcemodel.OOPSourceModelConstants.ComponentInvocations; /** * Ensure component type extensions invocations are accurate. @@ -17,58 +16,58 @@ */ public class TypeExtensionTest { - @Test - public void testAccurateExtendedTypes() throws Exception { + @Test + public void testAccurateExtendedTypes() throws Exception { + + final String code = "package com; \n public class ClassA extends ClassD { }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations() + .get(0).invokedComponent().equals("com.ClassD")); + } - String code = "package com; \n public class ClassA extends ClassD { }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.EXTENSION) - .get(0).invokedComponent().equals("com.ClassD")); - } + @Test + public void testAccurateExtendedTypesSize() throws Exception { - @Test - public void testAccurateExtendedTypesSize() throws Exception { + final String code = "package com; \n public class ClassA extends ClassD { }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations() + .size() == 1); + } - String code = "package com; \n public class ClassA extends ClassD { }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.EXTENSION) - .size() == 1); - } + @Test + public void testAccurateExtendedTypesForNestedClass() throws Exception { - @Test - public void testAccurateExtendedTypesForNestedClass() throws Exception { + final String code = "package com; \n public class ClassA { public class ClassB extends ClassD{} }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations() + .get(0).invokedComponent().equals("com.ClassD")); - String code = "package com; \n public class ClassA { public class ClassB extends ClassD{} }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations(ComponentInvocations.EXTENSION) - .get(0).invokedComponent().equals("com.ClassD")); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations() + .size() == 1); + } - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations(ComponentInvocations.EXTENSION) - .size() == 1); - } - - @Test - public void testAccurateExtendedTypesSizeForNestedClass() throws Exception { + @Test + public void testAccurateExtendedTypesSizeForNestedClass() throws Exception { - String code = "package com; \n public class ClassA { public class ClassB extends ClassD{} }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations(ComponentInvocations.EXTENSION) - .size() == 1); - } + final String code = "package com; \n public class ClassA { public class ClassB extends ClassD{} }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations() + .size() == 1); + } } diff --git a/clarpse/src/test/java/com/clarity/java/TypeImplementationTest.java b/clarpse/src/test/java/com/clarity/java/TypeImplementationTest.java index 71f14e0..c794469 100644 --- a/clarpse/src/test/java/com/clarity/java/TypeImplementationTest.java +++ b/clarpse/src/test/java/com/clarity/java/TypeImplementationTest.java @@ -1,11 +1,13 @@ package com.clarity.java; +import static org.junit.Assert.assertTrue; + import org.junit.Assert; import org.junit.Test; +import com.clarity.parser.ClarpseProject; import com.clarity.parser.Lang; import com.clarity.parser.ParseRequestContent; -import com.clarity.parser.ClarpseProject; import com.clarity.parser.RawFile; import com.clarity.sourcemodel.OOPSourceCodeModel; import com.clarity.sourcemodel.OOPSourceModelConstants.ComponentInvocations; @@ -17,86 +19,88 @@ */ public class TypeImplementationTest { - @Test - public void testAccurateImplementedTypes() throws Exception { - - String code = "package com; \n public class ClassA implements ClassD { }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .get(0).invokedComponent().equals("com.ClassD")); - } - - @Test - public void testAccurateMultipleImplementedTypes() throws Exception { - - String code = "package com; \n public class ClassA implements ClassD, ClassE { }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .get(0).invokedComponent().equals("com.ClassD")); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .get(1).invokedComponent().equals("com.ClassE")); - } - - @Test - public void testAccurateImplementedTypesSize() throws Exception { - - String code = "package com; \n public class ClassA implements ClassD { }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .size() == 1); - } - - @Test - public void testAccurateMultipleImplementedTypesSize() throws Exception { - - String code = "package com; \n public class ClassA implements ClassD, ClassE { }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .size() == 2); - } - - @Test - public void testAccurateImplementedTypesForNestedClass() throws Exception { - - String code = "package com; \n public class ClassA { class ClassB implements ClassD{} }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .get(0).invokedComponent().equals("com.ClassD")); - - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .size() == 1); - } - - @Test - public void testAccurateImplementedTypesSizeForNestedClass() throws Exception { - - String code = "package com; \n public class ClassA { public class ClassB implements ClassD{} }"; - OOPSourceCodeModel generatedSourceModel; - final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); - rawData.insertFile(new RawFile("file1", code)); - final ClarpseProject parseService = new ClarpseProject(rawData); - generatedSourceModel = parseService.result(); - Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations(ComponentInvocations.IMPLEMENTATION) - .size() == 1); - } + @Test + public void testAccurateImplementedTypes() throws Exception { + + final String code = "package com; \n public class ClassA implements ClassD { }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations() + .get(0) + .invokedComponent().equals("com.ClassD")); + assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations().size() == 1); + } + + @Test + public void testAccurateMultipleImplementedTypes() throws Exception { + + final String code = "package com; \n public class ClassA implements ClassD, ClassE { }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.IMPLEMENTATION) + .get(0).invokedComponent().equals("com.ClassD")); + assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations(ComponentInvocations.IMPLEMENTATION) + .get(1).invokedComponent().equals("com.ClassE")); + } + + @Test + public void testAccurateImplementedTypesSize() throws Exception { + + final String code = "package com; \n public class ClassA implements ClassD { }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations() + .size() == 1); + } + + @Test + public void testAccurateMultipleImplementedTypesSize() throws Exception { + + final String code = "package com; \n public class ClassA implements ClassD, ClassE { }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA").componentInvocations() + .size() == 2); + } + + @Test + public void testAccurateImplementedTypesForNestedClass() throws Exception { + + final String code = "package com; \n public class ClassA { class ClassB implements ClassD{} }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations() + .get(0).invokedComponent().equals("com.ClassD")); + + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations() + .size() == 1); + } + + @Test + public void testAccurateImplementedTypesSizeForNestedClass() throws Exception { + + final String code = "package com; \n public class ClassA { public class ClassB implements ClassD{} }"; + OOPSourceCodeModel generatedSourceModel; + final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); + rawData.insertFile(new RawFile("file1", code)); + final ClarpseProject parseService = new ClarpseProject(rawData); + generatedSourceModel = parseService.result(); + Assert.assertTrue(generatedSourceModel.getComponent("com.ClassA.ClassB").componentInvocations() + .size() == 1); + } } From 331f1d0dc17892fd89fca0f6350a474737191979 Mon Sep 17 00:00:00 2001 From: Muntazir Fadhel Date: Sat, 3 Sep 2016 01:19:33 -0400 Subject: [PATCH 2/2] Increased component code and comment test coverage --- .../clarity/invocation/EmptyInvocation.java | 2 +- .../clarity/invocation/ThrownException.java | 2 +- .../clarity/invocation/TypeDeclaration.java | 2 +- clarpse/src/test/java/ClarpseTest.java | 6 ++++- .../com/clarity/java/CommentsParsingTest.java | 24 ++++++++++++------- .../com/clarity/java/ComponentCodeTest.java | 7 +++--- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java b/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java index 15e8270..905abbf 100644 --- a/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java +++ b/clarpse/src/main/java/com/clarity/invocation/EmptyInvocation.java @@ -3,7 +3,7 @@ import java.io.Serializable; import java.util.List; -public class EmptyInvocation extends ComponentInvocation implements Serializable{ +public class EmptyInvocation extends ComponentInvocation implements Serializable { private static final long serialVersionUID = -3058881761749807208L; public final String type = "empty"; diff --git a/clarpse/src/main/java/com/clarity/invocation/ThrownException.java b/clarpse/src/main/java/com/clarity/invocation/ThrownException.java index ec357f3..8028aaf 100644 --- a/clarpse/src/main/java/com/clarity/invocation/ThrownException.java +++ b/clarpse/src/main/java/com/clarity/invocation/ThrownException.java @@ -3,7 +3,7 @@ import java.io.Serializable; import java.util.List; -public class ThrownException extends ComponentInvocation implements Serializable{ +public class ThrownException extends ComponentInvocation implements Serializable { private static final long serialVersionUID = 3346563314076095662L; public final String type = "exception"; diff --git a/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java b/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java index b687bd9..a3c5e5d 100644 --- a/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java +++ b/clarpse/src/main/java/com/clarity/invocation/TypeDeclaration.java @@ -3,7 +3,7 @@ import java.io.Serializable; import java.util.List; -public class TypeDeclaration extends ComponentInvocation implements Serializable{ +public class TypeDeclaration extends ComponentInvocation implements Serializable { private static final long serialVersionUID = 7304258760520469246L; public final String type = "declaration"; diff --git a/clarpse/src/test/java/ClarpseTest.java b/clarpse/src/test/java/ClarpseTest.java index f89ccc7..92f1aba 100644 --- a/clarpse/src/test/java/ClarpseTest.java +++ b/clarpse/src/test/java/ClarpseTest.java @@ -4,7 +4,9 @@ import com.clarity.java.AccessModifiersTest; import com.clarity.java.AnnotationInvocationTest; import com.clarity.java.ChildComponentsTest; +import com.clarity.java.CommentsParsingTest; import com.clarity.java.ComplexMethodInvocationsTest; +import com.clarity.java.ComponentCodeTest; import com.clarity.java.ComponentExistTest; import com.clarity.java.PackageAttributeTest; import com.clarity.java.ComponentTypeTest; @@ -31,7 +33,9 @@ TypeImplementationTest.class, TypeDeclarationTest.class, ChildComponentsTest.class, - AccessModifiersTest.class + AccessModifiersTest.class, + CommentsParsingTest.class, + ComponentCodeTest.class }) public class ClarpseTest { diff --git a/clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java b/clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java index a47c621..22f6be4 100644 --- a/clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java +++ b/clarpse/src/test/java/com/clarity/java/CommentsParsingTest.java @@ -20,7 +20,8 @@ public void testClassLevelComment() throws Exception { rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("test.Test").comment().equalsIgnoreCase("A \n comment")); + assertTrue(generatedSourceModel.getComponent("test.Test").comment().replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**Acomment*/")); } @Test @@ -31,7 +32,8 @@ public void testInterfaceLevelComment() throws Exception { rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("test.Test").comment().equalsIgnoreCase("A \n comment")); + assertTrue(generatedSourceModel.getComponent("test.Test").comment().replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**Acomment*/")); } @Test @@ -42,7 +44,8 @@ public void testEnumLevelComment() throws Exception { rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("test.Test").comment().equalsIgnoreCase("A \n comment")); + assertTrue(generatedSourceModel.getComponent("test.Test").comment().replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**Acomment*/")); } @Test @@ -53,7 +56,8 @@ public void testNestedClassLevelComment() throws Exception { rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("test.Test.Base").comment().equalsIgnoreCase("A \n comment")); + assertTrue(generatedSourceModel.getComponent("test.Test.Base").comment().replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**Acomment*/")); } @Test @@ -64,7 +68,8 @@ public void testMethodLevelComment() throws Exception { rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("Test.test()").comment().equalsIgnoreCase("lolcakes")); + assertTrue(generatedSourceModel.getComponent("Test.test()").comment().replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**lolcakes*/")); } @Test @@ -75,7 +80,8 @@ public void testInterfaceMethodLevelComment() throws Exception { rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("Test.test()").comment().equalsIgnoreCase("lolcakes")); + assertTrue(generatedSourceModel.getComponent("Test.test()").comment().replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**lolcakes*/")); } @Test @@ -86,7 +92,8 @@ public void testFieldVarLevelComment() throws Exception { rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); - assertTrue(generatedSourceModel.getComponent("Test.fieldVar").comment().equalsIgnoreCase("lolcakes")); + assertTrue(generatedSourceModel.getComponent("Test.fieldVar").comment().replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**lolcakes*/")); } @Test @@ -98,6 +105,7 @@ public void testMethodParamLevelComment() throws Exception { final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel.getComponent("Test.aMethod(java.lang.String).methodParam").comment() - .equalsIgnoreCase("lolcakes")); + .replaceAll("[\\n\\t\\r ]", "") + .equalsIgnoreCase("/**lolcakes*/")); } } diff --git a/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java b/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java index c764208..d56fac5 100644 --- a/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java +++ b/clarpse/src/test/java/com/clarity/java/ComponentCodeTest.java @@ -53,18 +53,19 @@ public void testMethodParamLevelCode() throws Exception { @Test public void testInterfaceLevelCode() throws Exception { - final String code = "public class Test { @Override Test(String str) { Object localVar;} @Deprecated interface Cakes { abstract void tester(); } }"; + final String code = "@Deprecated public interface Cakes { abstract void tester(); }"; final ParseRequestContent rawData = new ParseRequestContent(Lang.JAVA); rawData.insertFile(new RawFile("file2.java", code)); final ClarpseProject parseService = new ClarpseProject(rawData); final OOPSourceCodeModel generatedSourceModel = parseService.result(); assertTrue(generatedSourceModel - .getComponent("Test.Cakes") + .getComponent("Cakes") .code() .trim() .replaceAll("[\\n\\t\\r ]", "") .equalsIgnoreCase( - "@Deprecated interface Cakes { abstract void tester(); }".trim().replaceAll("[\\n\\t ]", ""))); + "@Deprecated public interface Cakes { abstract void tester(); }".trim().replaceAll("[\\n\\t ]", + ""))); } @Test