@@ -1869,9 +1869,13 @@ private void insideMemberSelect(Env env) throws IOException {
18691869 if (el != null && (el .getKind ().isClass () || el .getKind ().isInterface ())) {
18701870 if (parent .getKind () == Tree .Kind .NEW_CLASS && ((NewClassTree ) parent ).getIdentifier () == fa && prefix != null ) {
18711871 String typeName = controller .getElementUtilities ().getElementName (el , true ) + "." + prefix ; //NOI18N
1872- TypeMirror tm = controller .getTreeUtilities ().parseType (typeName , env .getScope (). getEnclosingClass () );
1872+ TypeMirror tm = controller .getTreeUtilities ().parseType (typeName , env .getScope ());
18731873 if (tm != null && tm .getKind () == TypeKind .DECLARED ) {
1874- addMembers (env , tm , ((DeclaredType ) tm ).asElement (), EnumSet .of (CONSTRUCTOR ), null , inImport , insideNew , false , false , switchItemAdder );
1874+ TypeElement te = (TypeElement ) ((DeclaredType ) tm ).asElement ();
1875+ addMembers (env , tm , te , EnumSet .of (CONSTRUCTOR ), null , inImport , insideNew , false , false , switchItemAdder );
1876+ if (shouldExcludeTypeInNewClass (te , env )) {
1877+ env .addToExcludes (te );
1878+ }
18751879 }
18761880 }
18771881 }
@@ -1917,9 +1921,13 @@ private void insideMemberSelect(Env env) throws IOException {
19171921 if (el != null && el .getKind () == PACKAGE ) {
19181922 if (parent .getKind () == Tree .Kind .NEW_CLASS && ((NewClassTree ) parent ).getIdentifier () == fa && prefix != null ) {
19191923 String typeName = controller .getElementUtilities ().getElementName (el , true ) + "." + prefix ; //NOI18N
1920- TypeMirror tm = controller .getTreeUtilities ().parseType (typeName , env .getScope (). getEnclosingClass () );
1924+ TypeMirror tm = controller .getTreeUtilities ().parseType (typeName , env .getScope ());
19211925 if (tm != null && tm .getKind () == TypeKind .DECLARED ) {
1922- addMembers (env , tm , ((DeclaredType ) tm ).asElement (), EnumSet .of (CONSTRUCTOR ), null , inImport , insideNew , false , false , switchItemAdder );
1926+ TypeElement te = (TypeElement ) ((DeclaredType ) tm ).asElement ();
1927+ addMembers (env , tm , te , EnumSet .of (CONSTRUCTOR ), null , inImport , insideNew , false , false , switchItemAdder );
1928+ if (shouldExcludeTypeInNewClass (te , env )) {
1929+ env .addToExcludes (te );
1930+ }
19231931 }
19241932 }
19251933 if (exs != null && !exs .isEmpty ()) {
@@ -2051,7 +2059,7 @@ private void insideMethodInvocation(Env env) throws IOException {
20512059 if (path .getParentPath ().getLeaf ().getKind () == Kind .CONSTANT_CASE_LABEL ) {
20522060 CompilationController controller = env .getController ();
20532061 controller .toPhase (Phase .RESOLVED );
2054- TypeMirror tm = controller .getTreeUtilities ().parseType (fullName (mi .getMethodSelect ()), env .getScope (). getEnclosingClass () );
2062+ TypeMirror tm = controller .getTreeUtilities ().parseType (fullName (mi .getMethodSelect ()), env .getScope ());
20552063 if (tm != null && tm .getKind () == TypeKind .DECLARED ) {
20562064 TypeElement te = (TypeElement ) ((DeclaredType ) tm ).asElement ();
20572065 if (te .getKind () == RECORD ) {
@@ -2062,7 +2070,7 @@ private void insideMethodInvocation(Env env) throws IOException {
20622070 if (ts != null && (ts .token ().id () == JavaTokenId .LPAREN || ts .token ().id () == JavaTokenId .COMMA )) {
20632071 if (componentType .getKind () == TypeKind .DECLARED ) {
20642072 if (prefix != null ) {
2065- TypeMirror ptm = controller .getTreeUtilities ().parseType (prefix , env .getScope (). getEnclosingClass () );
2073+ TypeMirror ptm = controller .getTreeUtilities ().parseType (prefix , env .getScope ());
20662074 if (ptm != null && ptm .getKind () == TypeKind .DECLARED ) {
20672075 TypeElement pte = (TypeElement ) ((DeclaredType ) ptm ).asElement ();
20682076 if (pte != null && pte .getKind () == RECORD ) {
@@ -2135,12 +2143,11 @@ private void insideNewClass(Env env) throws IOException {
21352143 ? controller .getTypes ().getDeclaredType (tel ) : null ;
21362144 TypeElement toExclude = null ;
21372145 if (nc .getIdentifier ().getKind () == Tree .Kind .IDENTIFIER && prefix != null ) {
2138- TypeMirror tm = controller .getTreeUtilities ().parseType (prefix , env .getScope (). getEnclosingClass () );
2146+ TypeMirror tm = controller .getTreeUtilities ().parseType (prefix , env .getScope ());
21392147 if (tm != null && tm .getKind () == TypeKind .DECLARED ) {
21402148 TypeElement te = (TypeElement ) ((DeclaredType ) tm ).asElement ();
21412149 addMembers (env , tm , te , EnumSet .of (CONSTRUCTOR ), base , false , true , false );
2142- if ((te .getTypeParameters ().isEmpty () || SourceVersion .RELEASE_5 .compareTo (controller .getSourceVersion ()) > 0 )
2143- && !hasAccessibleInnerClassConstructor (te , env .getScope (), controller .getTrees ())) {
2150+ if (shouldExcludeTypeInNewClass (te , env )) {
21442151 toExclude = te ;
21452152 }
21462153 }
@@ -2227,6 +2234,13 @@ private void insideNewClass(Env env) throws IOException {
22272234 }
22282235 }
22292236
2237+ private boolean shouldExcludeTypeInNewClass (TypeElement te , Env env ) throws IOException {
2238+ CompilationController controller = env .getController ();
2239+
2240+ return (te .getTypeParameters ().isEmpty () || SourceVersion .RELEASE_5 .compareTo (controller .getSourceVersion ()) > 0 )
2241+ && !hasAccessibleInnerClassConstructor (te , env .getScope (), controller .getTrees ());
2242+ }
2243+
22302244 private void insideTry (Env env ) throws IOException {
22312245 CompilationController controller = env .getController ();
22322246 TokenSequence <JavaTokenId > last = findLastNonWhitespaceToken (env , env .getPath ().getLeaf (), env .getOffset ());
@@ -2550,7 +2564,7 @@ private void insideCase(Env env) throws IOException {
25502564 } else {
25512565 if (env .getController ().getSourceVersion ().compareTo (RELEASE_21 ) >= 0 ) {
25522566 if (prefix != null ) {
2553- TypeMirror ptm = controller .getTreeUtilities ().parseType (prefix , env .getScope (). getEnclosingClass () );
2567+ TypeMirror ptm = controller .getTreeUtilities ().parseType (prefix , env .getScope ());
25542568 if (ptm != null && ptm .getKind () == TypeKind .DECLARED ) {
25552569 TypeElement pte = (TypeElement ) ((DeclaredType ) ptm ).asElement ();
25562570 if (pte != null && pte .getKind () == RECORD ) {
@@ -2754,7 +2768,7 @@ private void insideTypeCheck(Env env) throws IOException {
27542768 TokenSequence <JavaTokenId > ts = findLastNonWhitespaceToken (env , iot , env .getOffset ());
27552769 if (ts != null && ts .token ().id () == JavaTokenId .INSTANCEOF ) {
27562770 if (prefix != null && controller .getSourceVersion ().compareTo (RELEASE_21 ) >= 0 ) {
2757- TypeMirror tm = controller .getTreeUtilities ().parseType (prefix , env .getScope (). getEnclosingClass () );
2771+ TypeMirror tm = controller .getTreeUtilities ().parseType (prefix , env .getScope ());
27582772 if (tm != null && tm .getKind () == TypeKind .DECLARED ) {
27592773 TypeElement te = (TypeElement ) ((DeclaredType ) tm ).asElement ();
27602774 if (te != null && te .getKind () == RECORD ) {
@@ -3485,7 +3499,7 @@ private void insideDeconstructionRecordPattern(final Env env) throws IOException
34853499 TypeMirror componentType = recordComponents .get (size - 1 ).getAccessor ().getReturnType ();
34863500 if (componentType .getKind () == TypeKind .DECLARED ) {
34873501 if (prefix != null ) {
3488- TypeMirror ptm = controller .getTreeUtilities ().parseType (prefix , env .getScope (). getEnclosingClass () );
3502+ TypeMirror ptm = controller .getTreeUtilities ().parseType (prefix , env .getScope ());
34893503 if (ptm != null && ptm .getKind () == TypeKind .DECLARED ) {
34903504 TypeElement pte = (TypeElement ) ((DeclaredType ) ptm ).asElement ();
34913505 if (pte != null && pte .getKind () == RECORD ) {
@@ -4088,6 +4102,9 @@ private void addMembers(final Env env, final TypeMirror type, final Element elem
40884102 ElementUtilities .ElementAcceptor acceptor = new ElementUtilities .ElementAcceptor () {
40894103 @ Override
40904104 public boolean accept (Element e , TypeMirror t ) {
4105+ if (env .getExcludes () != null && env .getExcludes ().contains (e )) {
4106+ return false ;
4107+ }
40914108 switch (simplifyElementKind (e .getKind ())) {
40924109 case FIELD :
40934110 if (!startsWith (env , e .getSimpleName ().toString ())) {
@@ -4876,7 +4893,6 @@ public boolean accept(Element e, TypeMirror t) {
48764893 private void addAttributeValues (Env env , Element element , AnnotationMirror annotation , ExecutableElement member ) throws IOException {
48774894 CompilationController controller = env .getController ();
48784895 TreeUtilities tu = controller .getTreeUtilities ();
4879- ElementUtilities eu = controller .getElementUtilities ();
48804896 for (javax .annotation .processing .Completion completion : SourceUtils .getAttributeValueCompletions (controller , element , annotation , member , env .getPrefix ())) {
48814897 String value = completion .getValue ().trim ();
48824898 if (value .length () > 0 && startsWith (env , value )) {
@@ -4889,7 +4905,7 @@ private void addAttributeValues(Env env, Element element, AnnotationMirror annot
48894905 CharSequence fqn = ((TypeElement ) ((DeclaredType ) type ).asElement ()).getQualifiedName ();
48904906 if (JAVA_LANG_CLASS .contentEquals (fqn )) {
48914907 String name = value .endsWith (".class" ) ? value .substring (0 , value .length () - 6 ) : value ; //NOI18N
4892- TypeMirror tm = tu .parseType (name , eu . outermostTypeElement ( element ));
4908+ TypeMirror tm = tu .parseType (name , env . getScope ( ));
48934909 typeElement = tm != null && tm .getKind () == TypeKind .DECLARED ? (TypeElement ) ((DeclaredType ) tm ).asElement () : null ;
48944910 if (typeElement != null && startsWith (env , typeElement .getSimpleName ().toString ())) {
48954911 env .addToExcludes (typeElement );
0 commit comments