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

Redone work on adding IndexUnit (Tests and Travis job passed) #2

Merged
merged 16 commits into from
Jun 25, 2017

Conversation

Bohdankm22
Copy link
Collaborator

  • created IndexUnit class that contains only field List
  • changed java.jj file to read the stubfiles and generate the IndexUnit object
  • created JavaParser.class parseIndex and parseResourceIndex that are the copy of the parse and parseResource respectively with the difference in the return type (IndexUnit vs CompilationUnit).

Maven test and Travis job passed
https://travis-ci.org/Bohdankm22/javaparser/builds/243882845

- created IndexUnit class that contains only field List<CompilationUnit>
- changed java.jj file to read the stubfiles and generate the IndexUnit object
- created JavaParser.class parseIndex and parseResourceIndex that are the copy of the parse and parseResource respectively with the difference in the return type (IndexUnit vs CompilationUnit).
Copy link
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

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

This design is much better! I have a few comments.

@@ -42,7 +43,6 @@
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.TreeSet;
Copy link
Member

Choose a reason for hiding this comment

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

I would not remove this line (even though it wasn't used in the original file).
The reason is that doing so increases the size of the diff and increases the possibility for merge conflicts in the future.

@@ -295,6 +295,148 @@ public static CompilationUnit parse(String code) {
return simplifiedParse(COMPILATION_UNIT, provider(code));
}

public static IndexUnit parseIndexUnit(final InputStream in, Charset encoding) {
Copy link
Member

Choose a reason for hiding this comment

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

Please write a Javadoc comment for every method and field.

* Note: Uses UTF-8 encoding
*
* @param path path to a resource containing Java source code. As resource is accessed through a class loader, a
* leading "/" is not allowed in pathToResource
Copy link
Member

Choose a reason for hiding this comment

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

Minor: add period at end of sentence.


/**
* Parses the Java code contained in a resource and returns a
* {@link IndexUnit} that represents it.<br>
Copy link
Member

Choose a reason for hiding this comment

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

The trailing <br> is not necessary.

* {@link IndexUnit} that represents it.<br>
*
* @param path path to a resource containing Java source code. As resource is accessed through a class loader, a
* leading "/" is not allowed in pathToResource
Copy link
Member

Choose a reason for hiding this comment

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

Missing period. (The same comment applies a few other places below.)

@@ -672,6 +672,74 @@ TOKEN :
/*
* Program structuring syntax follows.
*/
IndexUnit IndexUnit():
Copy link
Member

Choose a reason for hiding this comment

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

Since this is an addition and not part of the Java language, there should be a comment. The comment should also point at a user-visible description of what may appear in an IndexUnit.

@@ -672,6 +672,74 @@ TOKEN :
/*
* Program structuring syntax follows.
*/
IndexUnit IndexUnit():
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for the name IndexUnit? I would have expected a name that uses the word Stub, which is what is used in the Checker Framework documentation.

NodeList<CompilationUnit> compilationUnits = emptyList();
CompilationUnit cu;

/* Parsing the compilation unit itself */
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this comment.

Maybe you mean that the above two variables are the representation of the object being parsed, and the remaining variables are temporary variables that will be used during parsing. Whether or not my guess is right, please clarify.

)

[ LOOKAHEAD(PackageDeclaration()) pakage = PackageDeclaration() ]
(
Copy link
Member

Choose a reason for hiding this comment

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

Why does this repeat the identical text (but with different indentation!) as "A A*" rather than using the "A+" syntax? That is, can you use Kleene Plus here instead of Kleene Star? If not, explain why not.

)
)
{
cu = new CompilationUnit(range(token_source.getHomeToken(), token()), pakage, imports, types, module);
Copy link
Member

Choose a reason for hiding this comment

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

This seems to require a correct, complete compilation unit. Is it your plan in the future to relax this restriction so that various parts (such as method bodies) can be omitted? That's fine, but the scope of this particular pull request wasn't clear from the description.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that is right. I will work on relaxing restrictions later.

Added throwing the RuntimeException instead of returning the null value.
- Added comments of the fields declarations and stub files reading
- Added using of A+ syntax instead of A A* syntax
… in ObservableProperties and ModifierVisitor
…throw a RuntimeException with a message that the method is not implemented
Copy link
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

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

Looks good overall. Thanks! Please address my comments and then merge.

@@ -43,7 +44,6 @@
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.TreeSet;

Copy link
Member

Choose a reason for hiding this comment

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

Please avoid whitespace changes. (Even if they are good, they can lead to merge conflicts.)

/**
* <p>
* This class represents a stub file. The stub file is a Java file, but with the optionally omitted
* information that is not relevant to pluggable type-checking; this makes the stub file smaller
Copy link
Member

Choose a reason for hiding this comment

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

Add a cross-reference to the full definition of a stub file. (You may need to update that definition as the project proceeds.)


/**
* <p>
* This class represents a stub file. The stub file is a Java file, but with the optionally omitted
Copy link
Member

Choose a reason for hiding this comment

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

A stub file isn't just a Java file with some information omitted. It's a concatenation of multiple Java files.
Without this information, "the list of compilation units" below is confusing.

public class StubUnit extends Node {

/**
* The field represents a list of compilations units.
Copy link
Member

Choose a reason for hiding this comment

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

The field doesn't represent a list of compilation units; it is a list of compilation units. Make the comment give information beyond the type if possible.

(Typo: "compilations units" should be "compilation unit".)

private StubUnit.Storage storage;

/**
* The constructor that takes the tokenRange and just pass it to the super method {@link Node}.
Copy link
Member

Choose a reason for hiding this comment

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

Internal implementation details don't belong in Javadoc. It's better to say what the TokenRange is or represents or how it is used, if possible.

Also, Javadoc should say what the method does, not what it is. Rather than, "the constructor that...", write something like "Constructs a StubUnit from a list of tokens".

* Represents the particular compilation unit components in each iteration of
* reading compilation units from the stub file
*/
PackageDeclaration pakage = null;
Copy link
Member

Choose a reason for hiding this comment

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

There is still inconsistent use of tabs vs. spaces in this file.
(The lines that start with * aren't properly indented either.)

CompilationUnit cu;

/*
* Represents the particular compilation unit components in each iteration of
Copy link
Member

Choose a reason for hiding this comment

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

What are the "particular" ones?

( LOOKAHEAD(2) ";" )*
(
/*
* Reading the particular compilation unit in the stub file
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by "particular" compilation units? Do you just mean the ones in the file?
Minor (but aids readability): end a sentence with punctuation rather than making the reader guess where sentences end and start.

(
/*
* Reading the particular compilation unit in the stub file
* Number of compilation units could be 1+
Copy link
Member

Choose a reason for hiding this comment

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

Not "could be" but "is".

cu = new CompilationUnit(range(token_source.getHomeToken(), token()), pakage, imports, types, module);
compilationUnits.add(cu);
}
)
Copy link
Member

Choose a reason for hiding this comment

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

You have made a design choice to remove the * that appears at this location in CompilationUnit. That affects how a file is split up: you split it up into the largest possible number of CompilationUnits as opposed to the smallest possible number. That's fine, but perhaps worth commenting about.

- Moving reading package declaration (at the begin of the stub file is required);
- Reading additional package declarations later in the stub file (not required by the stub file format);
- Reading imports (not required by the stub file format);
- Constructors and method bodies could be omitted for the stub files;
- Number of compilation units could be 1+ according to the stub file structure;
- Added comments in java.jj file.
Maven test is successful. Tested on the flow.astub file (need to move package declaration to the beginning of the file).
- Reformatted changes done in java.jj file to be consistent;
- Added fixes to the comments
@Bohdankm22
Copy link
Collaborator Author

@mernst I have finished work on your suggestions. However, I have also added one important commit with changes in the way compiler is going to read the stub files.
734ebb8
I tested parsing stub files on the flow.astub (moved package declaration to the beginning of the file) and got a good result.

@mernst
Copy link
Member

mernst commented Jun 24, 2017

What is your plan for merging this pull request? Once a pull request has been reviewed and approved, it's generally best to merge it. Otherwise, if you continue to make changes, then the whole pull request has to be re-reviewed.

@mernst
Copy link
Member

mernst commented Jun 24, 2017

I tried to fix some English errors myself, but I don't seem to have permission to push to your repository. Could you please grant me that permission?

@Bohdankm22
Copy link
Collaborator Author

@mernst, got it.
I have finished work on this pull request. I am not going to add anything else here. Once you approve it I will merge it.
Thank you!

@Bohdankm22 Bohdankm22 merged commit 7fa2c15 into master Jun 25, 2017
@Bohdankm22 Bohdankm22 deleted the index_new branch June 25, 2017 16:41
mernst referenced this pull request in mernst/stubparser Jan 7, 2019
smillst referenced this pull request in smillst/stubparser Apr 12, 2020
* Add Grammar for Javadoc
* Integrate into main parser

We are currently able to parse the Javadoc comment, but cannot construct an object from it as of yet. Everything else is finished.

Co-authored-by: yiiju <yijuhung0129@gmail.com>
mernst referenced this pull request in mernst/stubparser Nov 11, 2020
Updating with changes from javaparser repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants