org.sonar.api.resources
Class File

java.lang.Object
  extended by org.sonar.api.resources.File
All Implemented Interfaces:
Resource<Directory>

public class File
extends Object
implements Resource<Directory>

This class is an implementation of a resource of type FILE

Since:
1.10

Field Summary
 
Fields inherited from interface org.sonar.api.resources.Resource
QUALIFIER_CLASS, QUALIFIER_DIRECTORY, QUALIFIER_FILE, 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
File(Language language, String key)
          Creates a File from its language and its key
File(Language language, String directory, String filename)
          Creates a File from language, directory and filename
File(String key)
          File in project.
File(String directory, String filename)
          Creates a file from its containing directory and name
 
Method Summary
 boolean equals(Object obj)
           
static File fromIOFile(File file, List<File> sourceDirs)
          Creates a File from an io.file and a list of sources directories
static File fromIOFile(File file, Project project)
          Creates a File from its name and a project
 String getDescription()
          
 String getKey()
          
 Language getLanguage()
          
 String getLongName()
          
 String getName()
          
 Directory getParent()
          The parent is used to build the resources tree, for example for relations between classes, packages and projects.
 String getQualifier()
           
 String getScope()
           
 int hashCode()
           
 boolean matchFilePattern(String antPattern)
          Check resource against an Ant pattern, like mypackag?/*Foo.java.
 void setLanguage(Language language)
          Sets the language of the file
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

File

public File(String key)
File in project. Key is the path relative to project source directories. It is not the absolute path and it does not include the path to source directories. Example : new File("org/sonar/foo.sql"). The absolute path may be c:/myproject/src/main/sql/org/sonar/foo.sql. Project root is c:/myproject and source dir is src/main/sql.


File

public File(String directory,
            String filename)
Creates a file from its containing directory and name


File

public File(Language language,
            String key)
Creates a File from its language and its key


File

public File(Language language,
            String directory,
            String filename)
Creates a File from language, directory and filename

Method Detail

getParent

public Directory 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 interface Resource<Directory>
See Also:
Resource.getParent()

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 interface Resource<Directory>
Parameters:
antPattern - Ant-like pattern (with **, * and ?). It includes file suffixes.
Returns:
true if the resource matches the Ant pattern
See Also:
Resource.matchFilePattern(String)

fromIOFile

public static File fromIOFile(File file,
                              List<File> sourceDirs)
Creates a File from an io.file and a list of sources directories


fromIOFile

public static File fromIOFile(File file,
                              Project project)
Creates a File from its name and a project


getKey

public String getKey()

Specified by:
getKey in interface Resource<Directory>
Returns:
the resource key
See Also:
Resource.getKey()

getName

public String getName()

Specified by:
getName in interface Resource<Directory>
Returns:
the resource name
See Also:
Resource.getName()

getLongName

public String getLongName()

Specified by:
getLongName in interface Resource<Directory>
Returns:
the resource long name
See Also:
Resource.getLongName()

getDescription

public String getDescription()

Specified by:
getDescription in interface Resource<Directory>
Returns:
the resource description
See Also:
Resource.getDescription()

getLanguage

public Language getLanguage()

Specified by:
getLanguage in interface Resource<Directory>
Returns:
the language
See Also:
Resource.getLanguage()

setLanguage

public void setLanguage(Language language)
Sets the language of the file


getScope

public String getScope()
Specified by:
getScope in interface Resource<Directory>
Returns:
SCOPE_ENTITY

getQualifier

public String getQualifier()
Specified by:
getQualifier in interface Resource<Directory>
Returns:
QUALIFIER_FILE

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009 SonarSource SA. All Rights Reserved.