Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] Checking if a class is from a test package
  • From: "Milles, Eric (TR Tech, Content & Ops)" <eric.milles@xxxxxxxxxxxxxxxxxx>
  • Date: Fri, 3 Apr 2020 17:26:27 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=thomsonreuters.com; dmarc=pass action=none header.from=thomsonreuters.com; dkim=pass header.d=thomsonreuters.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mooyg8slf3/33d0EkBj09SCE5Z5m3YgXbsxjibG/vI0=; b=WsryPf0sZoqe3R1DG/L9i2U9pIMCn/j8mBxRyiSUZkNTY6tjc5YDWAHCmx+ZYzcMal2wi4g6gN/C6dGJOgdaY4wofpVgiWQ2V5+l3FjKDhDZFwtzLlB+b9upSWWzJy6fZqaygICvw3trB71WweE0lBhg+CMHBmQ6ySI/8F7JdPCSChSBgG9lFZcQzrPHzxygCAvrTZ3s22J8Wl7HlsY95eVG7htfHp8GdoDfBauABih9LfZ2zPFDn9sb4rOdT3qXBIeLVF95YrqLAd8V/rpAeaMyK3+Q/mj268hP53ySFiIG4pvwVFl4XN0Uzp8aTPlzlehkSIsnaPYVDRqaASvIyA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e8ZEV0kQ7ZiAt8pXPbE3o66OfG8bm5I8Uag4EBxLTuwcoesewQinZYO2ndT+ZvJvROLEFSEUYYlGmZUoIILldiAofTIDd9zG8Y5Xicx6/TQqnSTSXlROD2eJ73M94rDBLQj7g5KKx0aEU1vrkhEBhCRef+IkKkcNvBtRYCM0QL1yZbpIEQRxdazldiZzaQJgRclVuiqYtskOg+z+zcM445y0GLHmponrSJBsYM9mBz4igo44XIeKUjtTBS6ktwr3ROgPIvn6SbLl9fk3/KN3LMZrw9qYifVs/g3moLggEe2j8chWy11mS7qgZohnNMZO9JYWlBHIkYn8s1MzAQLbrQ==
  • Delivered-to: jdt-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jdt-dev>
  • List-help: <mailto:jdt-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jdt-dev>, <mailto:jdt-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jdt-dev>, <mailto:jdt-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHWCaT4n+tRmRAzhEGf4lLE3BTh/ahnTUoAgABLgICAAAy9QA==
  • Thread-topic: [jdt-dev] Checking if a class is from a test package

You can check for a given IJavaElement using:

 

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

 

 

From: jdt-dev-bounces@xxxxxxxxxxx <jdt-dev-bounces@xxxxxxxxxxx> On Behalf Of Till Brychcy
Sent: Friday, April 3, 2020 11:37 AM
To: Eclipse JDT general developers list. <jdt-dev@xxxxxxxxxxx>
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 <mistria@xxxxxxxxxx>:

 

 

 

On Fri, Apr 3, 2020 at 12:45 PM Gayan Perera <gayanper@xxxxxxxxx> 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
jdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev

 


Back to the top