Checking if a class is from a test package

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Checking if a class is from a test package

Gayan Perera
Hi all,

How to check a given class is in side test source folder or production source folder. I want to check this so i can avoid running codemining provider if they are part of production code since my minining are only applicable for test classes. 

Br,
Gayan

_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Checking if a class is from a test package

Mickael Istria-5


On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <[hidden email]> wrote:
How to check a given class is in side test source folder or production source folder.

Something like:
Arrays.stream(((IPackageFragmentRoot)javaProject.findElement(folder.getPath()).getParent()).getRawClasspathEntry().getExtraAttributes()).anyMatch(att -> "test".equals(att.getName()) && Boolean.parseBoolean(att.getValue()))
might work.

HTH

_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Checking if a class is from a test package

Sarika Sinha
If Java Build Path "Source folder" is set to "Contains test Sources", this property can also be used to identify.
 
Thanks & Regards,
Sarika
 
----- Original message -----
From: Mickael Istria <[hidden email]>
Sent by: [hidden email]
To: "Eclipse JDT general developers list." <[hidden email]>
Cc:
Subject: Re: [jdt-dev] Checking if a class is from a test package
Date: Fri, Apr 3, 2020 5:37 PM
 
 
 
On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <[hidden email]> wrote:
How to check a given class is in side test source folder or production source folder.
 
Something like:
 
Arrays.stream(((IPackageFragmentRoot)javaProject.findElement(folder.getPath()).getParent()).getRawClasspathEntry().getExtraAttributes()).anyMatch(att -> "test".equals(att.getName()) && Boolean.parseBoolean(att.getValue()))
might work.
 
HTH
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
 


_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Checking if a class is from a test package

Daniel Megert
Another thing you could do is to test for JUnit being on the class path.

Dani



From:        "Sarika Sinha" <[hidden email]>
To:        [hidden email]
Date:        03.04.2020 14:29
Subject:        [EXTERNAL] Re: [jdt-dev] Checking if a class is from a test package
Sent by:        [hidden email]




If Java Build Path "Source folder" is set to "Contains test Sources", this property can also be used to identify.
 
Thanks & Regards,
Sarika
 
----- Original message -----
From: Mickael Istria <[hidden email]>
Sent by: [hidden email]
To: "Eclipse JDT general developers list." <[hidden email]>
Cc:
Subject: Re: [jdt-dev] Checking if a class is from a test package
Date: Fri, Apr 3, 2020 5:37 PM
 

 
 
On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <gayanper@...> wrote:
How to check a given class is in side test source folder or production source folder.
 
Something like:
 
Arrays.stream(((IPackageFragmentRoot)javaProject.findElement(folder.getPath()).getParent()).getRawClasspathEntry().getExtraAttributes()).anyMatch(att -> "test".equals(att.getName()) && Boolean.parseBoolean(att.getValue()))
might work.
 
HTH
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-dev
 
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-dev




_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Checking if a class is from a test package

Gayan Perera
Hi daniel,

My requirment is to check if my project class file is a test class file or a production class file. So i can my test only codemining provider on those classes. 

Br,
Gayan

On Fri, 3 Apr 2020 at 15:10, Daniel Megert <[hidden email]> wrote:
Another thing you could do is to test for JUnit being on the class path.

Dani



From:        "Sarika Sinha" <[hidden email]>
To:        [hidden email]
Date:        03.04.2020 14:29
Subject:        [EXTERNAL] Re: [jdt-dev] Checking if a class is from a test package
Sent by:        [hidden email]




If Java Build Path "Source folder" is set to "Contains test Sources", this property can also be used to identify.
 
Thanks & Regards,
Sarika
 
----- Original message -----
From: Mickael Istria <[hidden email]>
Sent by: [hidden email]
To: "Eclipse JDT general developers list." <[hidden email]>
Cc:
Subject: Re: [jdt-dev] Checking if a class is from a test package
Date: Fri, Apr 3, 2020 5:37 PM
 

 
 
On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <[hidden email]> wrote:
How to check a given class is in side test source folder or production source folder.
 
Something like:
 
Arrays.stream(((IPackageFragmentRoot)javaProject.findElement(folder.getPath()).getParent()).getRawClasspathEntry().getExtraAttributes()).anyMatch(att -> "test".equals(att.getName()) && Boolean.parseBoolean(att.getValue()))
might work.
 
HTH
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-dev
 
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-dev



_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev

_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Checking if a class is from a test package

Gayan Perera
Thanks all,

Mickael suggestion actuall worked for me.

Br,
Gayan.

On Fri, Apr 3, 2020 at 3:12 PM Gayan Perera <[hidden email]> wrote:
Hi daniel,

My requirment is to check if my project class file is a test class file or a production class file. So i can my test only codemining provider on those classes. 

Br,
Gayan

On Fri, 3 Apr 2020 at 15:10, Daniel Megert <[hidden email]> wrote:
Another thing you could do is to test for JUnit being on the class path.

Dani



From:        "Sarika Sinha" <[hidden email]>
To:        [hidden email]
Date:        03.04.2020 14:29
Subject:        [EXTERNAL] Re: [jdt-dev] Checking if a class is from a test package
Sent by:        [hidden email]




If Java Build Path "Source folder" is set to "Contains test Sources", this property can also be used to identify.
 
Thanks & Regards,
Sarika
 
----- Original message -----
From: Mickael Istria <[hidden email]>
Sent by: [hidden email]
To: "Eclipse JDT general developers list." <[hidden email]>
Cc:
Subject: Re: [jdt-dev] Checking if a class is from a test package
Date: Fri, Apr 3, 2020 5:37 PM
 

 
 
On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <[hidden email]> wrote:
How to check a given class is in side test source folder or production source folder.
 
Something like:
 
Arrays.stream(((IPackageFragmentRoot)javaProject.findElement(folder.getPath()).getParent()).getRawClasspathEntry().getExtraAttributes()).anyMatch(att -> "test".equals(att.getName()) && Boolean.parseBoolean(att.getValue()))
might work.
 
HTH
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-dev
 
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-dev



_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev

_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Checking if a class is from a test package

Till Brychcy
In reply to this post by Mickael Istria-5
As Mickael wrote, you have to find the classpathEntry, but then you don’t have to iterate the attributes yourself, but can
use org.eclipse.jdt.core.IClasspathEntry.isTest().

How to get the classpathEntry depends on what object you are starting with.

I’d suggest to look at existing usages of  org.eclipse.jdt.core.IClasspathEntry.isTest() to find code that is most similar.


Am 03.04.2020 um 14:06 schrieb Mickael Istria <[hidden email]>:



On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <[hidden email]> wrote:
How to check a given class is in side test source folder or production source folder.

Something like:
Arrays.stream(((IPackageFragmentRoot)javaProject.findElement(folder.getPath()).getParent()).getRawClasspathEntry().getExtraAttributes()).anyMatch(att -> "test".equals(att.getName()) && Boolean.parseBoolean(att.getValue()))
might work.

HTH
_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev


_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Checking if a class is from a test package

Milles, Eric (TR Technology & Ops)

You can check for a given IJavaElement using:

 

((IPackageFragmentRoot) javaElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT)).getResolvedClasspathEntry().isTest()

 

 

From: [hidden email] <[hidden email]> On Behalf Of Till Brychcy
Sent: Friday, April 3, 2020 11:37 AM
To: Eclipse JDT general developers list. <[hidden email]>
Subject: Re: [jdt-dev] Checking if a class is from a test package

 

As Mickael wrote, you have to find the classpathEntry, but then you don’t have to iterate the attributes yourself, but can

use org.eclipse.jdt.core.IClasspathEntry.isTest().

 

How to get the classpathEntry depends on what object you are starting with.

 

I’d suggest to look at existing usages of  org.eclipse.jdt.core.IClasspathEntry.isTest() to find code that is most similar.

 



Am 03.04.2020 um 14:06 schrieb Mickael Istria <[hidden email]>:

 

 

 

On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <[hidden email]> wrote:

How to check a given class is in side test source folder or production source folder.

 

Something like:

Arrays.stream(((IPackageFragmentRoot)javaProject.findElement(folder.getPath()).getParent()).getRawClasspathEntry().getExtraAttributes()).anyMatch(att -> "test".equals(att.getName()) && Boolean.parseBoolean(att.getValue()))

might work.

 

HTH

_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev

 


_______________________________________________
jdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev