Austin Stephens created NETBEANS-1937:
-----------------------------------------

             Summary: Import on code paste error
                 Key: NETBEANS-1937
                 URL: https://issues.apache.org/jira/browse/NETBEANS-1937
             Project: NetBeans
          Issue Type: Bug
          Components: java - Source
    Affects Versions: 10.0
         Environment: Mac
JDK 10
            Reporter: Austin Stephens


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

 
{code:java}
    @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.
            }
        };
    }
{code}
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.

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to