Class SourceFileScope
- java.lang.Object
-
- net.sourceforge.pmd.lang.symboltable.AbstractScope
-
- net.sourceforge.pmd.lang.java.symboltable.AbstractJavaScope
-
- net.sourceforge.pmd.lang.java.symboltable.SourceFileScope
-
- All Implemented Interfaces:
net.sourceforge.pmd.lang.symboltable.Scope
public class SourceFileScope extends AbstractJavaScope
This scope is the outer most scope of a Java file. A Source File can contain one ore more classes.
-
-
Constructor Summary
Constructors Constructor Description SourceFileScope(java.lang.ClassLoader classLoader)
SourceFileScope(java.lang.ClassLoader classLoader, java.lang.String packageImage)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration declaration)
void
configureImports(java.util.List<ASTImportDeclaration> imports)
Configures the type resolution for the symbol table.ClassNameDeclaration
findClassNameDeclaration(java.lang.String name)
protected java.util.Set<net.sourceforge.pmd.lang.symboltable.NameDeclaration>
findVariableHere(JavaNameOccurrence occ)
java.util.Map<ClassNameDeclaration,java.util.List<net.sourceforge.pmd.lang.symboltable.NameOccurrence>>
getClassDeclarations()
Convenience method that casts the declarations toClassNameDeclaration
s.java.util.Set<java.lang.String>
getExplicitImports()
java.lang.String
getPackageName()
java.util.Map<java.lang.String,net.sourceforge.pmd.lang.ast.Node>
getQualifiedTypeNames()
Returns a set of all types defined within this source file.boolean
hasAuxclasspath()
Whether an auxclasspath has been configured or not.java.lang.Class<?>
resolveType(java.lang.String name)
Tries to resolve a class by name.java.lang.String
toString()
-
Methods inherited from class net.sourceforge.pmd.lang.java.symboltable.AbstractJavaScope
checkForDuplicatedNameDeclaration, contains, glomNames
-
-
-
-
Method Detail
-
configureImports
public void configureImports(java.util.List<ASTImportDeclaration> imports)
Configures the type resolution for the symbol table.- Parameters:
imports
- the import declarations
-
getExplicitImports
public java.util.Set<java.lang.String> getExplicitImports()
-
hasAuxclasspath
public boolean hasAuxclasspath()
Whether an auxclasspath has been configured or not. This can be used to enable/disable more detailed symbol table analysis and type resolution can be used - or to fall back to more simple implementation.- Returns:
true
if the auxclasspath is configured and types can be resolved reliably.- See Also:
resolveType(String)
-
resolveType
public java.lang.Class<?> resolveType(java.lang.String name)
Tries to resolve a class by name.- Parameters:
name
- the name of the class- Returns:
- the class or
null
if no class could be found
-
getPackageName
public java.lang.String getPackageName()
-
addDeclaration
public void addDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration declaration)
- Specified by:
addDeclaration
in interfacenet.sourceforge.pmd.lang.symboltable.Scope
- Overrides:
addDeclaration
in classAbstractJavaScope
- Throws:
java.lang.IllegalArgumentException
- if declaration is not aClassNameDeclaration
-
getClassDeclarations
public java.util.Map<ClassNameDeclaration,java.util.List<net.sourceforge.pmd.lang.symboltable.NameOccurrence>> getClassDeclarations()
Convenience method that casts the declarations toClassNameDeclaration
s.- Returns:
- all class name declarations
- See Also:
AbstractScope.getDeclarations()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
findClassNameDeclaration
public ClassNameDeclaration findClassNameDeclaration(java.lang.String name)
-
findVariableHere
protected java.util.Set<net.sourceforge.pmd.lang.symboltable.NameDeclaration> findVariableHere(JavaNameOccurrence occ)
- Specified by:
findVariableHere
in classAbstractJavaScope
-
getQualifiedTypeNames
public java.util.Map<java.lang.String,net.sourceforge.pmd.lang.ast.Node> getQualifiedTypeNames()
Returns a set of all types defined within this source file. This includes all top-level types and nested types.- Returns:
- set of all types in this source file.
-
-