Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubunit #3

Merged
merged 34 commits into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a91de3a
Added support for the legacy stub files that contains leading imports…
Bohdankm22 Jun 25, 2017
d4b2a75
- Added implementation to the accept methods in StubUnit in the way a…
Bohdankm22 Jun 25, 2017
6b3a405
- Added support of multiple static class and interface declarations i…
Bohdankm22 Jun 26, 2017
3693d79
Implemented PrettyPringVisitor for StubUnit.
Bohdankm22 Jun 29, 2017
5b05fd1
Implemented visit method in CloneVisitor for StubUnit.
Bohdankm22 Jun 30, 2017
ea8a216
Changed GenericListVisitorAdapter visit method on StubUnit to throw a…
Bohdankm22 Jul 3, 2017
8ef4562
- Transplanted SimpleVoidVisitor from the stubparser and adjusted for…
Bohdankm22 Jul 6, 2017
765aa12
- adjusted parsing annotations that could belong to the package in st…
Bohdankm22 Jul 6, 2017
17bbc8b
- Fixed the problem with annotations list assigned null. Instead assi…
Bohdankm22 Jul 6, 2017
c3e8b10
Changes in java.jj file:
Bohdankm22 Jul 12, 2017
47fa716
- Redesigned the way of reading StubUnits. Now it is possible that Co…
Bohdankm22 Jul 13, 2017
5249bd7
- Added required for the Checker Framework visit method on ReferenceType
Bohdankm22 Jul 13, 2017
93f1cd3
Merge branch 'stubunit' of https://github.com/Bohdankm22/javaparser i…
Bohdankm22 Jul 17, 2017
484f7af
- Remove redundant code.
Bohdankm22 Jul 19, 2017
76a553c
- Fixed issue with LOOKAHEAD on PackageDeclaration. Changed to check …
Bohdankm22 Jul 20, 2017
57c9f84
- Added receiver annotations to the MethodDeclaration;
Bohdankm22 Jul 24, 2017
a2b09f3
- Removing receiver parameter from method declaration as it should on…
Bohdankm22 Jul 24, 2017
4ab8b8f
Merge branch 'master' of https://github.com/javaparser/javaparser int…
Bohdankm22 Jul 25, 2017
978ba7d
- Fixed the problem with NullPointerException in method findNodeListN…
Bohdankm22 Jul 26, 2017
20d0c83
- Changed to make a first package declaration not required. This chan…
Bohdankm22 Jul 26, 2017
c4eb808
- Added toString to the NodeList class.
Bohdankm22 Jul 26, 2017
be3c7aa
Merge branch 'master' of https://github.com/javaparser/javaparser int…
Bohdankm22 Jul 27, 2017
6442670
Merge branch 'master' into stubunit
Bohdankm22 Jul 27, 2017
632f551
- Added merge fixes.
Bohdankm22 Jul 27, 2017
5b58958
- Moved receiverAnnotations list to the CallableDeclaration from Meth…
Bohdankm22 Jul 27, 2017
d448f61
- In case of absence of receiver annotations changed to set the empty…
Bohdankm22 Jul 27, 2017
79b328b
- Removed redundant variable declaration;
Bohdankm22 Jul 28, 2017
e80acd2
- Reformatted a java.jj file
Bohdankm22 Jul 28, 2017
fb40bd0
- Removed ability to have top-level static classes/interfaces.
Bohdankm22 Jul 28, 2017
6667c9a
- Added support of getting annotations for particular level of array …
Bohdankm22 Aug 1, 2017
936b8ca
Tweak comments
mernst Aug 2, 2017
257bf40
Don't refer to section number, which might change.
mernst Aug 2, 2017
279dcd6
Tweak comment
mernst Aug 2, 2017
8451c98
- Addressed requested changes in the pull request #3.
Bohdankm22 Aug 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,11 @@ private void setAsParentNodeOf(Node childNode) {
childNode.setParentNode(getParentNodeForChildren());
}
}

@Override
public String toString() {
return "NodeList{" +
"innerList=" + innerList +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ public StubUnit setStorage(Path path) {
return this;
}

//TODO implement this method
@Override
public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
throw new RuntimeException("The method is not implemented!");
//v.visit(this, arg);
return v.visit(this, arg);
}

//TODO implement this method
@Override
public <A> void accept(VoidVisitor<A> v, A arg) {
throw new RuntimeException("The method is not implemented!");
// v.visit(this, arg);
v.visit(this, arg);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public abstract class CallableDeclaration<T extends CallableDeclaration<?>> exte

private NodeList<ReferenceType> thrownExceptions;

private NodeList<AnnotationExpr> receiverAnnotations;

@AllFieldsConstructor
public CallableDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions) {
this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions);
Expand Down Expand Up @@ -129,6 +131,12 @@ public NodeList<Parameter> getParameters() {
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public T setParameters(final NodeList<Parameter> parameters) {
assertNotNull(parameters);
if (parameters.size() > 0 && parameters.get(0).getNameAsString().equals("this")) {
setReceiverAnnotations(parameters.get(0).getAnnotations());
parameters.remove(0);
} else {
setReceiverAnnotations(new NodeList<>());
}
if (parameters == this.parameters) {
return (T) this;
}
Expand All @@ -140,6 +148,15 @@ public T setParameters(final NodeList<Parameter> parameters) {
return (T) this;
}

public CallableDeclaration<T> setReceiverAnnotations(NodeList<AnnotationExpr> receiverAnnotations) {
this.receiverAnnotations = receiverAnnotations;
return this;
}

public NodeList<AnnotationExpr> getReceiverAnnotations() {
return receiverAnnotations;
}

@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public NodeList<ReferenceType> getThrownExceptions() {
return thrownExceptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ public MethodDeclaration setName(final SimpleName name) {
return super.setName(name);
}

@Override
public MethodDeclaration setParameters(final NodeList<Parameter> parameters) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this code deleted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was added before to handle receiver annotations. Then it was moved to the super class setParameters method.

return super.setParameters(parameters);
}

@Override
public MethodDeclaration setThrownExceptions(final NodeList<ReferenceType> thrownExceptions) {
return super.setThrownExceptions(thrownExceptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ public ArrayType setComponentType(final Type componentType) {
*/
@SafeVarargs
public static Type wrapInArrayTypes(Type type, List<ArrayBracketPair>... arrayBracketPairLists) {
List<ArrayBracketPair> arrayAnnotations = new ArrayList<>();
for (int i = arrayBracketPairLists.length - 1; i >= 0; i--) {
final List<ArrayBracketPair> arrayBracketPairList = arrayBracketPairLists[i];
if (arrayBracketPairList != null) {
arrayAnnotations.addAll(arrayBracketPairList);
for (int j = arrayBracketPairList.size() - 1; j >= 0; j--) {
ArrayBracketPair pair = arrayBracketPairList.get(j);
TokenRange tokenRange = null;
Expand All @@ -118,6 +120,10 @@ public static Type wrapInArrayTypes(Type type, List<ArrayBracketPair>... arrayBr
}
}
}
// The above code concatenates the arrayBracketPairLists, because they represent different
// parts of the array rather than two sources of information about the same parts of the
// array.
type.setArrayBracketPairs(arrayAnnotations);
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@
import com.github.javaparser.metamodel.JavaParserMetaModel;
import com.github.javaparser.metamodel.TypeMetaModel;
import static com.github.javaparser.utils.Utils.assertNotNull;

import javax.annotation.Generated;
import com.github.javaparser.TokenRange;

import java.util.List;

/**
* Base class for types.
*
* @author Julio Vilmar Gesser
*/
public abstract class Type extends Node {

private List<ArrayType.ArrayBracketPair> arrayBracketPairs;

private NodeList<AnnotationExpr> annotations;

/**
Expand Down Expand Up @@ -146,4 +151,36 @@ public boolean replace(Node node, Node replacementNode) {
}
return super.replace(node, replacementNode);
}

/**
* Finds the list of annotations at the particular array level of the type and returns it.
* Throws the IllegalArgumentException if specified level is greater then maximal level
* of the array in this type or less then 0.
* @param level the array level which annotations should be returned.
* @return the annotations at the particular array level.
*/
public List<AnnotationExpr> getAnnotationsAtLevel(int level) {
if (level >= getArrayCount() || level < 0) {
throw new IllegalArgumentException("The level argument should be greater then 0 and" +
"less then the array count (" + getArrayCount() + "). Specified level is " + level);
}
return arrayBracketPairs.get(level).getAnnotations();
}

public List<ArrayType.ArrayBracketPair> getArrayBracketPairs() {
return arrayBracketPairs;
}

public Type setArrayBracketPairs(List<ArrayType.ArrayBracketPair> arrayBracketPairs) {
this.arrayBracketPairs = arrayBracketPairs;
return this;
}

/**
* Checks and returns the maximum level of the array.
* If the type is not array it should return 0.
*/
public int getArrayCount() {
return arrayBracketPairs == null ? 0 : arrayBracketPairs.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ public Visitable visit(CompilationUnit n, Object arg) {
return r;
}

// TODO Implement clone visitor for the StubUnit
@Override
@Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
public Visitable visit(StubUnit n, Object arg) {
/*NodeList<ImportDeclaration> imports = cloneList(n.getImports(), arg);
ModuleDeclaration module = cloneNode(n.getModule(), arg);
PackageDeclaration packageDeclaration = cloneNode(n.getPackageDeclaration(), arg);
NodeList<TypeDeclaration<?>> types = cloneList(n.getTypes(), arg);
Comment comment = cloneNode(n.getComment(), arg);
StubUnit r = new StubUnit(n.getTokenRange().orElse(null), packageDeclaration, imports, types, module);
r.setComment(comment);*/
throw new RuntimeException("The method is not implemented!");
NodeList<CompilationUnit> compilationUnits = new NodeList<>();
n.getCompilationUnits().forEach(cu -> compilationUnits.add(cloneNode(cu, arg)));
StubUnit su = new StubUnit(compilationUnits);
return su;
}

@Override
Expand Down Expand Up @@ -288,6 +283,7 @@ public Visitable visit(ArrayType n, Object arg) {
Comment comment = cloneNode(n.getComment(), arg);
ArrayType r = new ArrayType(n.getTokenRange().orElse(null), componentType, annotations);
r.setComment(comment);
r.setArrayBracketPairs(n.getArrayBracketPairs());
return r;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public List<R> visit(CompilationUnit n, A arg) {
// TODO Implement GenericListVisitorAdapter # visit on StubUnit
@Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
public List<R> visit(StubUnit n, A arg) {
return null;
throw new RuntimeException("The method is not implemented!");
}

@Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
Expand Down
Loading