org.sonar.api.resources
Class JavaFile

java.lang.Object
  extended by org.sonar.api.resources.Resource<JavaPackage>
      extended by org.sonar.api.resources.JavaFile

public class JavaFile
extends Resource<JavaPackage>

A class that represents a Java class. This class can either be a Test class or source class

Since:
1.10

Field Summary
 
Fields inherited from class org.sonar.api.resources.Resource
QUALIFIER_CLASS, QUALIFIER_DIRECTORY, QUALIFIER_FIELD, QUALIFIER_FILE, QUALIFIER_LIB, QUALIFIER_METHOD, QUALIFIER_MODULE, QUALIFIER_PACKAGE, QUALIFIER_PROJECT, QUALIFIER_PROJECT_BRANCH, QUALIFIER_PROJECT_TRUNK, QUALIFIER_SUBVIEW, QUALIFIER_UNIT_TEST_CLASS, QUALIFIER_VIEW, SCOPE_DIRECTORY, SCOPE_ENTITY, SCOPE_FILE, SCOPE_PROJECT, SCOPE_SET, SCOPE_SPACE
 
Constructor Summary
JavaFile(String key)
          Creates a source file from its key
JavaFile(String key, boolean unitTest)
          Creates any JavaFile from its key
JavaFile(String packageName, String className)
          Creates a JavaFile that is not a class of test based on package and file names
JavaFile(String packageKey, String className, boolean unitTest)
          Creates a JavaFile that can be of any type based on package and file names
 
Method Summary
static JavaFile fromAbsolutePath(String path, List<File> sourceDirs, boolean unitTest)
          Shortcut to fromIOFile with an abolute path
static JavaFile fromIOFile(File file, List<File> sourceDirs, boolean unitTest)
          Creates a JavaFile from a file in the source directories
 String getDescription()
           
 Language getLanguage()
           
 String getLongName()
          
 String getName()
          
 JavaPackage getParent()
          The parent is used to build the resources tree, for example for relations between classes, packages and projects.
 String getQualifier()
           
 String getScope()
           
 boolean isUnitTest()
           
 boolean matchFilePattern(String antPattern)
          Check resource against an Ant pattern, like mypackag?/*Foo.java.
 String toString()
           
 
Methods inherited from class org.sonar.api.resources.Resource
equals, getEffectiveKey, getId, getKey, hashCode, isExcluded, setEffectiveKey, setExcluded, setId, setKey
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JavaFile

public JavaFile(String packageName,
                String className)
Creates a JavaFile that is not a class of test based on package and file names


JavaFile

public JavaFile(String packageKey,
                String className,
                boolean unitTest)
Creates a JavaFile that can be of any type based on package and file names

Parameters:
unitTest - whether it is a unit test file or a source file

JavaFile

public JavaFile(String key)
Creates a source file from its key


JavaFile

public JavaFile(String key,
                boolean unitTest)
Creates any JavaFile from its key

Parameters:
unitTest - whether it is a unit test file or a source file
Method Detail

getParent

public JavaPackage getParent()
The parent is used to build the resources tree, for example for relations between classes, packages and projects.

Return null if the parent is the project.

Specified by:
getParent in class Resource<JavaPackage>

getDescription

public String getDescription()
Specified by:
getDescription in class Resource<JavaPackage>
Returns:
null

getLanguage

public Language getLanguage()
Specified by:
getLanguage in class Resource<JavaPackage>
Returns:
Java

getName

public String getName()

Specified by:
getName in class Resource<JavaPackage>
Returns:
the resource name

getLongName

public String getLongName()

Specified by:
getLongName in class Resource<JavaPackage>
Returns:
the resource long name

getScope

public String getScope()
Specified by:
getScope in class Resource<JavaPackage>
Returns:
SCOPE_ENTITY

getQualifier

public String getQualifier()
Specified by:
getQualifier in class Resource<JavaPackage>
Returns:
QUALIFIER_UNIT_TEST_CLASS or QUALIFIER_CLASS depending whether it is a unit test class

isUnitTest

public boolean isUnitTest()
Returns:
whether the JavaFile is a unit test class or not

matchFilePattern

public boolean matchFilePattern(String antPattern)
Check resource against an Ant pattern, like mypackag?/*Foo.java. It's used for example to match resource exclusions.

Specified by:
matchFilePattern in class Resource<JavaPackage>
Parameters:
antPattern - Ant-like pattern (with **, * and ?). It includes file suffixes.
Returns:
true if the resource matches the Ant pattern

fromIOFile

public static JavaFile fromIOFile(File file,
                                  List<File> sourceDirs,
                                  boolean unitTest)
Creates a JavaFile from a file in the source directories

Returns:
the JavaFile created if exists, null otherwise

fromAbsolutePath

public static JavaFile fromAbsolutePath(String path,
                                        List<File> sourceDirs,
                                        boolean unitTest)
Shortcut to fromIOFile with an abolute path


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009-2010 SonarSource. All Rights Reserved.