Re: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package
My advice is to go with the explicit version where one has to add the @SuppressWarnings("unchecked"). Dani From: Markus Keller/Zurich/IBM@IBMCH To: Cross project issues , "General development mailing list of the Eclipse project." Date: 20.02.2015 18:23 Subject: Re: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package Sent by:cross-project-issues-dev-boun...@eclipse.org Yeah, this basically hides the unsafe cast in the implementation of Class#cast(..). It has its advantages and disadvantages: Pro: Performs an additional dynamic Class#isInstance(..) check that throws a CCE at the place where the unsafe cast happens => fail-fast is good (although the cast at the caller side also won't be far away; and that's how it used to work in the past). Contra: Is less explicit than the SuppressWarnings version, since the type safety problem is not immediately visible at the code location where the unchecked cast happens. => adapter.cast(..) is OK for me, but not a must. Markus From:"Andrey Loskutov" To:cross-project-issues-dev@eclipse.org Cc:"General development mailing list of the Eclipse project." , Cross project issues Date: 2015-02-20 15:35 Subject:Re: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package Sent by:cross-project-issues-dev-boun...@eclipse.org Hi, Before everyone starts to change getAdapter() implementation, please consider to user warning-free alternative: Instead of writing: @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return (T) getCompilationUnit(); return null; } use Class.cast() API: public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return adapter.cast(getCompilationUnit()); return null; } Kind regards, Andrey Loskutov http://google.com/+AndreyLoskutov Gesendet: Freitag, 20. Februar 2015 um 15:21 Uhr Von: "Thomas Watson" An: "Cross project issues" , "General development mailing list of the Eclipse project." Betreff: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021 Markus Keller wrote up an nice summary of what consumers should do to fix any warnings that may be caused by this change at https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021#c25 Here is a copy of the recommendations if you are going to compile against the latest version of org.eclipse.equinox.common: 1. In MANIFEST.MF, update your Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)", or org.eclipse.equinox.common;bundle-version="[3.7.0,4.0.0)", or update your Import-Package: org.eclipse.core.runtime; version="[3.5,4.0)" 2. If your bundle re-exports one of these bundles, then you also have to make sure the minor version is incremented. 3. Remove unnecessary casts (Clean Up, or Problems view > Quick Fix > Select All) 4. Update implementations of IAdaptable#getAdapter(Class), unless you override another implementation of that method that still uses the old signature. Typical change: Old: public Object getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return getCompilationUnit(); return null; } New: @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return (T) getCompilationUnit(); return null; } 5. Update implementations of IAdapterFactory Hint for 4. & 5.: - Open Type Hierarchy on IAdaptable, etc. - In the view menu, select a working set that contains your projects - In the methods list of the Type Hierarchy view, select the methods, and then click the first toolbar button (Lock View and Show Members in Hierarchy) Tom ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev ___
Re: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package
Yeah, this basically hides the unsafe cast in the implementation of Class#cast(..). It has its advantages and disadvantages: Pro: Performs an additional dynamic Class#isInstance(..) check that throws a CCE at the place where the unsafe cast happens => fail-fast is good (although the cast at the caller side also won't be far away; and that's how it used to work in the past). Contra: Is less explicit than the SuppressWarnings version, since the type safety problem is not immediately visible at the code location where the unchecked cast happens. => adapter.cast(..) is OK for me, but not a must. Markus From: "Andrey Loskutov" To: cross-project-issues-dev@eclipse.org Cc: "General development mailing list of the Eclipse project." , Cross project issues Date: 2015-02-20 15:35 Subject: Re: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package Sent by:cross-project-issues-dev-boun...@eclipse.org Hi, Before everyone starts to change getAdapter() implementation, please consider to user warning-free alternative: Instead of writing: @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return (T) getCompilationUnit(); return null; } use Class.cast() API: public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return adapter.cast(getCompilationUnit()); return null; } Kind regards, Andrey Loskutov http://google.com/+AndreyLoskutov Gesendet: Freitag, 20. Februar 2015 um 15:21 Uhr Von: "Thomas Watson" An: "Cross project issues" , "General development mailing list of the Eclipse project." Betreff: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021 Markus Keller wrote up an nice summary of what consumers should do to fix any warnings that may be caused by this change at https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021#c25 Here is a copy of the recommendations if you are going to compile against the latest version of org.eclipse.equinox.common: 1. In MANIFEST.MF, update your Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)", or org.eclipse.equinox.common;bundle-version="[3.7.0,4.0.0)", or update your Import-Package: org.eclipse.core.runtime; version="[3.5,4.0)" 2. If your bundle re-exports one of these bundles, then you also have to make sure the minor version is incremented. 3. Remove unnecessary casts (Clean Up, or Problems view > Quick Fix > Select All) 4. Update implementations of IAdaptable#getAdapter(Class), unless you override another implementation of that method that still uses the old signature. Typical change: Old: public Object getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return getCompilationUnit(); return null; } New: @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return (T) getCompilationUnit(); return null; } 5. Update implementations of IAdapterFactory Hint for 4. & 5.: - Open Type Hierarchy on IAdaptable, etc. - In the view menu, select a working set that contains your projects - In the methods list of the Type Hierarchy view, select the methods, and then click the first toolbar button (Lock View and Show Members in Hierarchy) Tom ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev
Re: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package
Hi, Before everyone starts to change getAdapter() implementation, please consider to user warning-free alternative: Instead of writing: @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return (T) getCompilationUnit(); return null; } use Class.cast() API: public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return adapter.cast(getCompilationUnit()); return null; } Kind regards, Andrey Loskutov http://google.com/+AndreyLoskutov Gesendet: Freitag, 20. Februar 2015 um 15:21 Uhr Von: "Thomas Watson" An: "Cross project issues" , "General development mailing list of the Eclipse project." Betreff: [cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021 Markus Keller wrote up an nice summary of what consumers should do to fix any warnings that may be caused by this change at https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021#c25 Here is a copy of the recommendations if you are going to compile against the latest version of org.eclipse.equinox.common: 1. In MANIFEST.MF, update your Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)", or org.eclipse.equinox.common;bundle-version="[3.7.0,4.0.0)", or update your Import-Package: org.eclipse.core.runtime; version="[3.5,4.0)" 2. If your bundle re-exports one of these bundles, then you also have to make sure the minor version is incremented. 3. Remove unnecessary casts (Clean Up, or Problems view > Quick Fix > Select All) 4. Update implementations of IAdaptable#getAdapter(Class), unless you override another implementation of that method that still uses the old signature. Typical change: Old: public Object getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return getCompilationUnit(); return null; } New: @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return (T) getCompilationUnit(); return null; } 5. Update implementations of IAdapterFactory Hint for 4. & 5.: - Open Type Hierarchy on IAdaptable, etc. - In the view menu, select a working set that contains your projects - In the methods list of the Type Hierarchy view, select the methods, and then click the first toolbar button (Lock View and Show Members in Hierarchy) Tom ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev
[cross-project-issues-dev] org.eclipse.equinox.common has added generics to API in org.eclipse.core.runtime package
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021 Markus Keller wrote up an nice summary of what consumers should do to fix any warnings that may be caused by this change at https://bugs.eclipse.org/bugs/show_bug.cgi?id=442021#c25 Here is a copy of the recommendations if you are going to compile against the latest version of org.eclipse.equinox.common: 1. In MANIFEST.MF, update your Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)", or org.eclipse.equinox.common;bundle-version="[3.7.0,4.0.0)", or update your Import-Package: org.eclipse.core.runtime; version="[3.5,4.0)" 2. If your bundle re-exports one of these bundles, then you also have to make sure the minor version is incremented. 3. Remove unnecessary casts (Clean Up, or Problems view > Quick Fix > Select All) 4. Update implementations of IAdaptable#getAdapter(Class), unless you override another implementation of that method that still uses the old signature. Typical change: Old: public Object getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return getCompilationUnit(); return null; } New: @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICompilationUnit.class.equals(adapter)) return (T) getCompilationUnit(); return null; } 5. Update implementations of IAdapterFactory Hint for 4. & 5.: - Open Type Hierarchy on IAdaptable, etc. - In the view menu, select a working set that contains your projects - In the methods list of the Type Hierarchy view, select the methods, and then click the first toolbar button (Lock View and Show Members in Hierarchy) Tom ___ cross-project-issues-dev mailing list cross-project-issues-dev@eclipse.org To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cross-project-issues-dev