Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Ragdoc Builder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
Ragdoc Builder
Commits
8cb83dcd
Commit
8cb83dcd
authored
4 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
Add option to exclude generated elements.
parent
257d1286
No related branches found
No related tags found
No related merge requests found
Pipeline
#8742
passed
4 years ago
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/extendj/ragdoc/JsonBuilder.java
+37
-2
37 additions, 2 deletions
src/main/java/org/extendj/ragdoc/JsonBuilder.java
src/main/java/org/extendj/ragdoc/RagDocBuilder.java
+3
-1
3 additions, 1 deletion
src/main/java/org/extendj/ragdoc/RagDocBuilder.java
with
40 additions
and
3 deletions
src/main/java/org/extendj/ragdoc/JsonBuilder.java
+
37
−
2
View file @
8cb83dcd
...
@@ -78,11 +78,13 @@ public class JsonBuilder {
...
@@ -78,11 +78,13 @@ public class JsonBuilder {
private
static
final
String
[]
MEMBER_KINDS
=
{
"constr"
,
"attr"
,
"rel"
,
"field"
,
"method"
};
private
static
final
String
[]
MEMBER_KINDS
=
{
"constr"
,
"attr"
,
"rel"
,
"field"
,
"method"
};
private
final
File
rootDir
;
private
final
File
rootDir
;
private
final
boolean
excludeGenerated
;
private
java
.
util
.
List
<
String
>
ragRoot
=
new
java
.
util
.
LinkedList
<>();
private
java
.
util
.
List
<
String
>
ragRoot
=
new
java
.
util
.
LinkedList
<>();
public
Map
<
String
,
File
>
sourceFiles
=
new
HashMap
<>();
public
Map
<
String
,
File
>
sourceFiles
=
new
HashMap
<>();
public
JsonBuilder
(
File
rootDir
)
{
public
JsonBuilder
(
File
rootDir
,
boolean
excludeGenerated
)
{
this
.
rootDir
=
rootDir
;
this
.
rootDir
=
rootDir
;
this
.
excludeGenerated
=
excludeGenerated
;
ragRoot
=
RelativePath
.
buildPathList
(
rootDir
);
ragRoot
=
RelativePath
.
buildPathList
(
rootDir
);
typenames
.
add
(
"packages"
);
// Reserve packages as JSON filename.
typenames
.
add
(
"packages"
);
// Reserve packages as JSON filename.
}
}
...
@@ -111,6 +113,9 @@ public class JsonBuilder {
...
@@ -111,6 +113,9 @@ public class JsonBuilder {
JsonArray
array
=
new
JsonArray
();
JsonArray
array
=
new
JsonArray
();
do
{
do
{
ParameterDeclaration
param
=
iter
.
next
();
ParameterDeclaration
param
=
iter
.
next
();
if
(
matchesGenerated
(
param
.
name
()))
{
continue
;
}
JsonObject
pobj
=
new
JsonObject
();
JsonObject
pobj
=
new
JsonObject
();
pobj
.
add
(
"t"
,
typeRef
(
param
.
type
()));
pobj
.
add
(
"t"
,
typeRef
(
param
.
type
()));
pobj
.
add
(
"n"
,
param
.
name
());
pobj
.
add
(
"n"
,
param
.
name
());
...
@@ -135,7 +140,7 @@ public class JsonBuilder {
...
@@ -135,7 +140,7 @@ public class JsonBuilder {
JsonObject
doc
=
method
.
jsonDocObject
();
JsonObject
doc
=
method
.
jsonDocObject
();
// System.out.println("" + method.type() + ": " + method + ", kind=" + method.objectKind());
// System.out.println("" + method.type() + ": " + method + ", kind=" + method.objectKind());
// System.out.println("`-> doc=" + doc + " doc.get(relation)=" + (doc != null ? doc.get("relation") : "/"));
// System.out.println("`-> doc=" + doc + " doc.get(relation)=" + (doc != null ? doc.get("relation") : "/"));
if
(
shouldDocument
(
method
,
doc
))
{
if
(
shouldDocument
(
method
,
doc
)
&&
!
matchesGenerated
(
method
.
name
())
)
{
JsonObject
obj
=
new
JsonObject
();
JsonObject
obj
=
new
JsonObject
();
obj
.
add
(
"name"
,
Json
.
of
(
method
.
name
()));
obj
.
add
(
"name"
,
Json
.
of
(
method
.
name
()));
JsonArray
modifiers
=
method
.
getModifiers
().
toJson
();
JsonArray
modifiers
=
method
.
getModifiers
().
toJson
();
...
@@ -220,6 +225,13 @@ public class JsonBuilder {
...
@@ -220,6 +225,13 @@ public class JsonBuilder {
&&
!
typeDecl
.
isTypeVariable
()
&&
typeDecl
.
compilationUnit
().
fromSource
();
&&
!
typeDecl
.
isTypeVariable
()
&&
typeDecl
.
compilationUnit
().
fromSource
();
}
}
/**
* Check if name contains "_internal_" or "_impl_" and if it should be excluded (based on constructor argument)
*/
private
boolean
matchesGenerated
(
String
name
)
{
return
this
.
excludeGenerated
&&
(
name
.
contains
(
"_internal_"
)
||
name
.
contains
(
"_impl_"
)
||
name
.
contains
(
"$"
));
}
// TODO: inner class names.
// TODO: inner class names.
/**
/**
...
@@ -255,6 +267,9 @@ public class JsonBuilder {
...
@@ -255,6 +267,9 @@ public class JsonBuilder {
JsonObject
doc
=
field
.
jsonDocObject
();
JsonObject
doc
=
field
.
jsonDocObject
();
if
(
shouldDocument
(
field
,
doc
))
{
if
(
shouldDocument
(
field
,
doc
))
{
for
(
Declarator
declarator
:
field
.
getDeclaratorList
())
{
for
(
Declarator
declarator
:
field
.
getDeclaratorList
())
{
if
(!
matchesGenerated
(
declarator
.
name
()))
{
continue
;
}
JsonObject
obj
=
new
JsonObject
();
JsonObject
obj
=
new
JsonObject
();
obj
.
add
(
"name"
,
Json
.
of
(
declarator
.
name
()));
obj
.
add
(
"name"
,
Json
.
of
(
declarator
.
name
()));
obj
.
add
(
"type"
,
typeRef
(
declarator
.
type
()));
obj
.
add
(
"type"
,
typeRef
(
declarator
.
type
()));
...
@@ -404,13 +419,29 @@ public class JsonBuilder {
...
@@ -404,13 +419,29 @@ public class JsonBuilder {
}
}
doc
.
set
(
"astdecl"
,
decl
);
doc
.
set
(
"astdecl"
,
decl
);
JsonArray
array
=
decl
.
get
(
"c"
).
array
();
JsonArray
array
=
decl
.
get
(
"c"
).
array
();
// objects to keep are non-generated parameters
List
<
JsonObject
>
objectsToKeep
=
new
ArrayList
<>();
boolean
removeSomeObjects
=
false
;
for
(
JsonValue
c
:
array
)
{
for
(
JsonValue
c
:
array
)
{
JsonObject
comp
=
c
.
object
();
JsonObject
comp
=
c
.
object
();
if
(
matchesGenerated
(
comp
.
get
(
"n"
).
stringValue
(
""
)))
{
removeSomeObjects
=
true
;
}
else
{
objectsToKeep
.
add
(
comp
);
}
if
(!
comp
.
get
(
"e"
).
stringValue
(
""
).
isEmpty
())
{
if
(!
comp
.
get
(
"e"
).
stringValue
(
""
).
isEmpty
())
{
comp
.
set
(
"e"
,
comp
.
set
(
"e"
,
typeRef
(
safeLookupType
(
type
,
stripGenericPart
(
comp
.
get
(
"e"
).
stringValue
(
""
)))));
typeRef
(
safeLookupType
(
type
,
stripGenericPart
(
comp
.
get
(
"e"
).
stringValue
(
""
)))));
}
}
}
}
// recreate the array with only those object to keep
if
(
removeSomeObjects
)
{
array
=
new
JsonArray
();
for
(
JsonObject
comp
:
objectsToKeep
)
{
array
.
add
(
comp
);
}
decl
.
set
(
"c"
,
array
);
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
catch
(
JsonParser
.
SyntaxError
syntaxError
)
{
}
catch
(
JsonParser
.
SyntaxError
syntaxError
)
{
...
@@ -439,6 +470,10 @@ public class JsonBuilder {
...
@@ -439,6 +470,10 @@ public class JsonBuilder {
return
obj
;
return
obj
;
}
}
private
void
excludeGeneratedFromProduction
(
JsonObject
decl
)
{
}
private
TypeDecl
safeLookupType
(
TypeDecl
parent
,
String
name
)
{
private
TypeDecl
safeLookupType
(
TypeDecl
parent
,
String
name
)
{
SimpleSet
<
TypeDecl
>
types
=
parent
.
lookupType
(
name
);
SimpleSet
<
TypeDecl
>
types
=
parent
.
lookupType
(
name
);
if
(
types
.
isEmpty
())
{
if
(
types
.
isEmpty
())
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/extendj/ragdoc/RagDocBuilder.java
+
3
−
1
View file @
8cb83dcd
...
@@ -187,6 +187,7 @@ public class RagDocBuilder extends Frontend {
...
@@ -187,6 +187,7 @@ public class RagDocBuilder extends Frontend {
@Override
protected
void
initOptions
()
{
@Override
protected
void
initOptions
()
{
super
.
initOptions
();
super
.
initOptions
();
program
.
options
().
addKeyValueOption
(
"-ragroot"
);
program
.
options
().
addKeyValueOption
(
"-ragroot"
);
program
.
options
().
addKeyOption
(
"-excludeGenerated"
);
}
}
@Override
protected
int
processArgs
(
String
[]
args
)
{
@Override
protected
int
processArgs
(
String
[]
args
)
{
...
@@ -206,7 +207,8 @@ public class RagDocBuilder extends Frontend {
...
@@ -206,7 +207,8 @@ public class RagDocBuilder extends Frontend {
}
}
}
}
System
.
out
.
println
(
"Using ragroot directory: "
+
ragRoot
.
getAbsolutePath
());
System
.
out
.
println
(
"Using ragroot directory: "
+
ragRoot
.
getAbsolutePath
());
jsonBuilder
=
new
JsonBuilder
(
ragRoot
);
boolean
excludeGenerated
=
program
.
options
().
hasOption
(
"-excludeGenerated"
);
jsonBuilder
=
new
JsonBuilder
(
ragRoot
,
excludeGenerated
);
ASTNode
.
jsonBuilder
=
jsonBuilder
;
ASTNode
.
jsonBuilder
=
jsonBuilder
;
}
}
return
result
;
return
result
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment