You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2019/05/09 04:50:01 UTC

[jira] [Updated] (NETBEANS-1937) Import on code paste error

     [ https://issues.apache.org/jira/browse/NETBEANS-1937?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ASF GitHub Bot updated NETBEANS-1937:
-------------------------------------
    Labels: pull-request-available  (was: )

> 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
>            Priority: Major
>              Labels: pull-request-available
>
> 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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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