From 056a8b34684552a9e53baa91742d3b9dcf9b83e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 7 Nov 2018 08:52:19 +0100 Subject: [PATCH] Add TODOs --- pmd-java/etc/grammar/Java.jjt | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index ad8cd1ec9e..b33a560efc 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1982,13 +1982,19 @@ void ReferenceType() #void: // TODO TypeVariable is ambiguous with ClassOrInterfaceType // but I think it would be good to have a node for it nevertheless // to help typeres, since TypeVariables have special types (intersection types) - // This could be handled in a rewrite phase, which is necessary for - // disambiguation. Since type parameters shadow anything, their disambiguation - // is stable regardless of classpath config. + // The implementation could use a small symbol table local to the parser, + // plus some rewrite phase (type parameters may forward-reference others, eg. + // class Foo, C>) ( PrimitiveType() Dims() ) #ArrayType | ( ClassOrInterfaceType() [ LOOKAHEAD(2) Dims() ] ) #ArrayType(>1) } + +/** + * Parses a ClassOrInterfaceType. + * TODO have a different node for ParameterizedType? Zero size overhead in the grammar, + * would allow us to specialize our API better. + */ void ClassOrInterfaceType() #void: { StringBuilder s = new StringBuilder(); @@ -1998,9 +2004,13 @@ void ClassOrInterfaceType() #void: ( ( t= { s.append(t.getImage()); } - // We gobble up all identifiers until we find + // FIXME We gobble up all identifiers until we find // either type arguments or annotations, because - // it may be a FQCN + // it may be a FQCN, e.g. java.util.List is a single node + // But java.util.Map.Entry should be two nodes ((java.util.Map).Entry) + // I would have said this doesn't matter but the other fixme comment just + // below shows we need a rewrite phase anyway + ( LOOKAHEAD("." ) "." t= { s.append('.').append(t.getImage()); } )* @@ -2012,6 +2022,14 @@ void ClassOrInterfaceType() #void: jjtree.peekNode().setImage(s.toString()); } + // Now if there are other segments, either the previous type specified formal parameters, + // or the next has an annotation. + // We parse the rest of the type recursively, to preserve the position of type params + // and annotations. + + // FIXME this doesn't account for annotated AND qualified types + // e.g. java.util.@Annot List, in which java.util should not be a ClassOrInterfaceType + // We can only fix that through rewrite, later on, with knowledge of the classpath. ( LOOKAHEAD(2) (