This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 262139
Collapse All | Expand All

(-)a/java.source.base/src/org/netbeans/api/java/source/ElementHandle.java (-9 / +36 lines)
Lines 57-62 Link Here
57
import javax.lang.model.element.Element;
57
import javax.lang.model.element.Element;
58
import javax.lang.model.element.ElementKind;
58
import javax.lang.model.element.ElementKind;
59
import javax.lang.model.element.ExecutableElement;
59
import javax.lang.model.element.ExecutableElement;
60
import javax.lang.model.element.NestingKind;
60
import javax.lang.model.element.PackageElement;
61
import javax.lang.model.element.PackageElement;
61
import javax.lang.model.element.TypeElement;
62
import javax.lang.model.element.TypeElement;
62
import javax.lang.model.element.TypeParameterElement;
63
import javax.lang.model.element.TypeParameterElement;
Lines 113-125 Link Here
113
    }
114
    }
114
    
115
    
115
    private final ElementKind kind;
116
    private final ElementKind kind;
117
    private final NestingKind nestingKind;
116
    private final String[] signatures;
118
    private final String[] signatures;
117
        
119
        
118
       
120
       
119
    private ElementHandle(final ElementKind kind, String... signatures) {
121
    private ElementHandle(final ElementKind kind, NestingKind netsingKind, String... signatures) {
120
        assert kind != null;
122
        assert kind != null;
121
        assert signatures != null;
123
        assert signatures != null;
122
        this.kind = kind;
124
        this.kind = kind;
125
        this.nestingKind = netsingKind;
123
        this.signatures = signatures;
126
        this.signatures = signatures;
124
    }
127
    }
125
    
128
    
Lines 380-385 Link Here
380
    public @NonNull ElementKind getKind () {
383
    public @NonNull ElementKind getKind () {
381
        return this.kind;
384
        return this.kind;
382
    }
385
    }
386
387
    /**
388
     * Returns the {@link NestingKind} of this element handle,
389
     * it is the nesting kind of the {@link TypeElement} from which the handle
390
     * was created.
391
     * @return {@link NestingKind} or null
392
     *
393
     */
394
    public NestingKind getNestingKind() {
395
        return nestingKind;
396
    }
383
    
397
    
384
    private static final WeakSet<ElementHandle<?>> NORMALIZATION_CACHE = new WeakSet<ElementHandle<?>>();
398
    private static final WeakSet<ElementHandle<?>> NORMALIZATION_CACHE = new WeakSet<ElementHandle<?>>();
385
399
Lines 410-416 Link Here
410
    public static ElementHandle<PackageElement> createPackageElementHandle (
424
    public static ElementHandle<PackageElement> createPackageElementHandle (
411
        @NonNull final String packageName) {
425
        @NonNull final String packageName) {
412
        Parameters.notNull("packageName", packageName); //NOI18N
426
        Parameters.notNull("packageName", packageName); //NOI18N
413
        return new ElementHandle<PackageElement>(ElementKind.PACKAGE, packageName);
427
        return new ElementHandle<PackageElement>(ElementKind.PACKAGE, null, packageName);
414
    }
428
    }
415
    
429
    
416
    /**
430
    /**
Lines 432-443 Link Here
432
        if (!kind.isClass() && !kind.isInterface()) {
446
        if (!kind.isClass() && !kind.isInterface()) {
433
            throw new IllegalArgumentException(kind.toString());
447
            throw new IllegalArgumentException(kind.toString());
434
        }
448
        }
435
        return new ElementHandle<TypeElement>(kind, binaryName);
449
        return new ElementHandle<TypeElement>(kind, null, binaryName);
436
    }
450
    }
437
451
438
    private static @NonNull <T extends Element> ElementHandle<T> createImpl (@NonNull final T element) throws IllegalArgumentException {
452
    private static @NonNull <T extends Element> ElementHandle<T> createImpl (@NonNull final T element) throws IllegalArgumentException {
439
        Parameters.notNull("element", element);
453
        Parameters.notNull("element", element);
440
        ElementKind kind = element.getKind();
454
        ElementKind kind = element.getKind();
455
        NestingKind nestingKind = null;
441
        String[] signatures;
456
        String[] signatures;
442
        switch (kind) {
457
        switch (kind) {
443
            case PACKAGE:
458
            case PACKAGE:
Lines 449-454 Link Here
449
            case ENUM:
464
            case ENUM:
450
            case ANNOTATION_TYPE:
465
            case ANNOTATION_TYPE:
451
                assert element instanceof TypeElement;
466
                assert element instanceof TypeElement;
467
                nestingKind = ((TypeElement) element).getNestingKind();
452
                signatures = new String[] {ClassFileUtil.encodeClassNameOrArray((TypeElement)element)};
468
                signatures = new String[] {ClassFileUtil.encodeClassNameOrArray((TypeElement)element)};
453
                break;
469
                break;
454
            case METHOD:
470
            case METHOD:
Lines 456-466 Link Here
456
            case INSTANCE_INIT:
472
            case INSTANCE_INIT:
457
            case STATIC_INIT:
473
            case STATIC_INIT:
458
                assert element instanceof ExecutableElement;
474
                assert element instanceof ExecutableElement;
475
                nestingKind = getEnclosingElementNestingKind(element);
459
                signatures = ClassFileUtil.createExecutableDescriptor((ExecutableElement)element);
476
                signatures = ClassFileUtil.createExecutableDescriptor((ExecutableElement)element);
460
                break;
477
                break;
461
            case FIELD:
478
            case FIELD:
462
            case ENUM_CONSTANT:
479
            case ENUM_CONSTANT:
463
                assert element instanceof VariableElement;
480
                assert element instanceof VariableElement;
481
                nestingKind = getEnclosingElementNestingKind(element);
464
                signatures = ClassFileUtil.createFieldDescriptor((VariableElement)element);
482
                signatures = ClassFileUtil.createFieldDescriptor((VariableElement)element);
465
                break;
483
                break;
466
            case TYPE_PARAMETER:
484
            case TYPE_PARAMETER:
Lines 470-481 Link Here
470
                ElementKind gek = ge.getKind();
488
                ElementKind gek = ge.getKind();
471
                if (gek.isClass() || gek.isInterface()) {
489
                if (gek.isClass() || gek.isInterface()) {
472
                    assert ge instanceof TypeElement;
490
                    assert ge instanceof TypeElement;
491
                    nestingKind = ((TypeElement) ge).getNestingKind();
473
                    signatures = new String[2];
492
                    signatures = new String[2];
474
                    signatures[0] = ClassFileUtil.encodeClassNameOrArray((TypeElement)ge);
493
                    signatures[0] = ClassFileUtil.encodeClassNameOrArray((TypeElement)ge);
475
                    signatures[1] = tpe.getSimpleName().toString();
494
                    signatures[1] = tpe.getSimpleName().toString();
476
                }
495
                }
477
                else if (gek == ElementKind.METHOD || gek == ElementKind.CONSTRUCTOR) {
496
                else if (gek == ElementKind.METHOD || gek == ElementKind.CONSTRUCTOR) {
478
                    assert ge instanceof ExecutableElement;
497
                    assert ge instanceof ExecutableElement;
498
                    nestingKind = getEnclosingElementNestingKind(ge);
479
                    String[] _sigs = ClassFileUtil.createExecutableDescriptor((ExecutableElement)ge);
499
                    String[] _sigs = ClassFileUtil.createExecutableDescriptor((ExecutableElement)ge);
480
                    signatures = new String[_sigs.length + 1];
500
                    signatures = new String[_sigs.length + 1];
481
                    System.arraycopy(_sigs, 0, signatures, 0, _sigs.length);
501
                    System.arraycopy(_sigs, 0, signatures, 0, _sigs.length);
Lines 488-494 Link Here
488
            default:
508
            default:
489
                throw new IllegalArgumentException(kind.toString());
509
                throw new IllegalArgumentException(kind.toString());
490
        }
510
        }
491
        return new ElementHandle<T> (kind, signatures);
511
        return new ElementHandle<T> (kind, nestingKind, signatures);
512
    }
513
    
514
    private static NestingKind getEnclosingElementNestingKind(Element element) {
515
        if (element.getEnclosingElement() instanceof TypeElement) {
516
            return ((TypeElement) element.getEnclosingElement()).getNestingKind();
517
        }
518
        return null;
492
    }
519
    }
493
    
520
    
494
    /**
521
    /**
Lines 563-569 Link Here
563
                    if (descriptors.length != 1) {
590
                    if (descriptors.length != 1) {
564
                        throw new IllegalArgumentException ();
591
                        throw new IllegalArgumentException ();
565
                    }
592
                    }
566
                    return new ElementHandle<PackageElement> (kind, descriptors);
593
                    return new ElementHandle<PackageElement> (kind, null, descriptors);
567
                case CLASS:
594
                case CLASS:
568
                case INTERFACE:
595
                case INTERFACE:
569
                case ENUM:
596
                case ENUM:
Lines 572-596 Link Here
572
                    if (descriptors.length != 1) {
599
                    if (descriptors.length != 1) {
573
                        throw new IllegalArgumentException ();
600
                        throw new IllegalArgumentException ();
574
                    }
601
                    }
575
                    return new ElementHandle<TypeElement> (kind, descriptors);
602
                    return new ElementHandle<TypeElement> (kind, null, descriptors);
576
                case METHOD:
603
                case METHOD:
577
                case CONSTRUCTOR:                
604
                case CONSTRUCTOR:                
578
                    if (descriptors.length != 3) {
605
                    if (descriptors.length != 3) {
579
                        throw new IllegalArgumentException ();
606
                        throw new IllegalArgumentException ();
580
                    }
607
                    }
581
                    return new ElementHandle<ExecutableElement> (kind, descriptors);
608
                    return new ElementHandle<ExecutableElement> (kind, null, descriptors);
582
                case INSTANCE_INIT:
609
                case INSTANCE_INIT:
583
                case STATIC_INIT:
610
                case STATIC_INIT:
584
                    if (descriptors.length != 2) {
611
                    if (descriptors.length != 2) {
585
                        throw new IllegalArgumentException ();
612
                        throw new IllegalArgumentException ();
586
                    }
613
                    }
587
                    return new ElementHandle<ExecutableElement> (kind, descriptors);
614
                    return new ElementHandle<ExecutableElement> (kind, null, descriptors);
588
                case FIELD:
615
                case FIELD:
589
                case ENUM_CONSTANT:
616
                case ENUM_CONSTANT:
590
                    if (descriptors.length != 3) {
617
                    if (descriptors.length != 3) {
591
                        throw new IllegalArgumentException ();
618
                        throw new IllegalArgumentException ();
592
                    }
619
                    }
593
                    return new ElementHandle<VariableElement> (kind, descriptors);
620
                    return new ElementHandle<VariableElement> (kind, null, descriptors);
594
                default:
621
                default:
595
                    throw new IllegalArgumentException ();
622
                    throw new IllegalArgumentException ();
596
            }            
623
            }            
(-)a/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java (-2 / +5 lines)
Lines 529-535 Link Here
529
                    return folders.isEmpty() ? pair.first() : folders.get(0);
529
                    return folders.isEmpty() ? pair.first() : folders.get(0);
530
                } else {               
530
                } else {               
531
                    final boolean caseSensitive = isCaseSensitive ();
531
                    final boolean caseSensitive = isCaseSensitive ();
532
                    final Object fnames = getSourceFileNames (className);
532
                    final Object fnames = getSourceFileNames (className, handle.getNestingKind());
533
                    folders.addFirst(pair.first());
533
                    folders.addFirst(pair.first());
534
                    if (fnames instanceof String) {
534
                    if (fnames instanceof String) {
535
                        FileObject match = findMatchingChild((String)fnames, folders, caseSensitive);
535
                        FileObject match = findMatchingChild((String)fnames, folders, caseSensitive);
Lines 1038-1049 Link Here
1038
     * a String (top-level class, no $) or List&lt;String> as the JLS permits $ in
1038
     * a String (top-level class, no $) or List&lt;String> as the JLS permits $ in
1039
     * class names. 
1039
     * class names. 
1040
     */
1040
     */
1041
    private static Object getSourceFileNames (String classFileName) {
1041
    private static Object getSourceFileNames (String classFileName, NestingKind nestingKind) {
1042
        int max = classFileName.length() - 1;
1042
        int max = classFileName.length() - 1;
1043
        int index = classFileName.indexOf('$');
1043
        int index = classFileName.indexOf('$');
1044
        if (index == -1) {
1044
        if (index == -1) {
1045
            return classFileName;
1045
            return classFileName;
1046
        }
1046
        }
1047
        if (nestingKind == NestingKind.TOP_LEVEL) {
1048
            return classFileName;
1049
        }
1047
        List<String> ll = new ArrayList<>(3);
1050
        List<String> ll = new ArrayList<>(3);
1048
        do {
1051
        do {
1049
            ll.add(classFileName.substring(0, index));
1052
            ll.add(classFileName.substring(0, index));

Return to bug 262139