Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-1937

Import on code paste error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 10.0
    • None
    • java - Source
    • Mac
      JDK 10

    Description

      Create a class file named "IterableUtil.java" and paste the following into the class:

       

          @Deprecated
          public static <T> Iterable<T> cast(final Iterable<?> source){
              return () -> new Iterator<T>() {
                  final Iterator<?> iterator = source.iterator();
                  @Override
                  public boolean hasNext() {
                      return iterator.hasNext();
                  }
                  
                  @Override
                  @SuppressWarnings("unchecked")
                  public T next() {
                      return (T)iterator.next();
                  }
      
                  @Override
                  public void remove() {
                      iterator.remove();
                  }
              };
          }
      
          public static <T,E> ListIterator<T> cast(final ListIterator<E> source,
                  final Class<E> clazz){
              return new ListIterator<T>() {
      
                  @Override
                  public boolean hasNext() {
                      return source.hasNext();
                  }
      
                  @Override
                  @SuppressWarnings("unchecked")
                  public T next() {
                      return (T)source.next();
                  }
      
                  @Override
                  public boolean hasPrevious() {
                      return source.hasPrevious();
                  }
      
                  @Override
                  @SuppressWarnings("unchecked")
                  public T previous() {
                      return (T)source.previous();
                  }
      
                  @Override
                  public int nextIndex() {
                      return source.nextIndex();
                  }
      
                  @Override
                  public int previousIndex() {
                      return source.nextIndex();
                  }
      
                  @Override
                  public void remove() {
                      source.remove();
                  }
      
                  @Override
                  public void set(T e) {
                      source.set(clazz.cast(e));
                  }
      
                  @Override
                  public void add(T e) {
                      source.add(clazz.cast(e));
                  }
              };
          }
          
          /**
           *
           * @param <T>
           * @param collection
           * @return
           * @deprecated Does not truly do the conversion.
           */
          @Deprecated
          public static <T> Iterable<T> enumerationToIterable(final Enumeration<T> collection){
              return () -> enumerationToIterator(collection);
          }
      
          public static <T> Iterator<T> enumerationToIterator(
                  final Enumeration<T> collection) {
              return new Iterator<T>() {
      
                  @Override
                  public boolean hasNext() {
                      return collection.hasMoreElements();
                  }
      
                  @Override
                  public T next() {
                      return collection.nextElement();
                  }
      
                  @Override
                  public void remove() {
                      throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
                  }
              };
          }
      

      The IDE will ask if you would like it to resolve imports. Click "ok". The resulting code will now have `return new IteratorIterator<T>(){` and `return new ListIteratorListIterator<T>() {`, which is wrong.

       

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              Sir Intellegence Austin Stephens
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m