Class NamespaceDeclaration

java.lang.Object
de.fraunhofer.aisec.cpg.graph.Node
de.fraunhofer.aisec.cpg.graph.declarations.Declaration
de.fraunhofer.aisec.cpg.graph.declarations.NamespaceDeclaration
All Implemented Interfaces:
DeclarationHolder, Persistable, StatementHolder, IVisitable<de.fraunhofer.aisec.cpg.graph.Node>

public class NamespaceDeclaration
extends Declaration
implements DeclarationHolder, StatementHolder
Declares the scope of a namespace and appends its own name to the current namespace-prefix to form a new namespace prefix. While RecordDeclarations in C++ and Java have their own namespace, namespace declarations can be declared multiple times. At the beginning of a Java-file, a namespace declaration is used to represent the package name as namespace. In its explicit appearance a namespace declaration can contain FunctionDeclaration, FieldDeclaration and RecordDeclaration similar to a RecordDeclaration and the semantic difference between NamespaceDeclaration and RecordDeclaration lies in the non-instantiabillity of a namespace.

The name property of this node need to be a FQN for propery resolution.

  • Nested Class Summary

    Nested classes/interfaces inherited from class de.fraunhofer.aisec.cpg.graph.Node

    de.fraunhofer.aisec.cpg.graph.Node.Companion
  • Field Summary

    Fields inherited from class de.fraunhofer.aisec.cpg.graph.Node

    Companion, EMPTY_NAME, TO_STRING_STYLE
  • Constructor Summary

    Constructors
    Constructor Description
    NamespaceDeclaration()  
  • Method Summary

    Modifier and Type Method Description
    void addDeclaration​(@NonNull Declaration declaration)
    Adds the specified declaration to this declaration holder.
    boolean equals​(java.lang.Object o)  
    <T> T getDeclarationAs​(int i, java.lang.Class<T> clazz)  
    java.util.List<Declaration> getDeclarations()  
    <T extends Declaration>
    @NonNull java.util.Set<T>
    getDeclarationsByName​(@NonNull java.lang.String name, @NonNull java.lang.Class<T> clazz)
    Returns a non-null, possibly empty Set of the declaration of a specified type and clazz.
    java.util.List<FieldDeclaration> getFields()  
    java.util.List<FunctionDeclaration> getFunctions()  
    java.util.List<NamespaceDeclaration> getNamespaces()  
    java.util.List<RecordDeclaration> getRecords()  
    @NonNull java.util.List<de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge<Statement>> getStatementEdges()
    Getter to be implemented by implementing classes to gain read access to the classes member.
    int hashCode()  
    void setStatementEdges​(@NonNull java.util.List<de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge<Statement>> statements)  

    Methods inherited from class de.fraunhofer.aisec.cpg.graph.Node

    addAnnotations, addNextDFG, addNextEOG, addPrevDFG, addPrevEOG, addTypedef, clearNextEOG, disconnectFromGraph, getAnnotations, getArgumentIndex, getCode, getComment, getFile, getId, getLocation, getName, getNextDFG, getNextEOG, getNextEOGEdges, getPrevDFG, getPrevEOG, getPrevEOGEdges, getTypedefs, isImplicit, isInferred, removeNextDFG, removePrevDFG, removePrevEOGEntry, setAnnotations, setArgumentIndex, setCode, setComment, setFile, setId, setImplicit, setInferred, setLocation, setName, setNextDFG, setNextEOG, setNextEOGEdges, setPrevDFG, setPrevEOG, setPrevEOGEdges, setTypedefs, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface de.fraunhofer.aisec.cpg.graph.DeclarationHolder

    addIfNotContains, addIfNotContains, addIfNotContains

    Methods inherited from interface de.fraunhofer.aisec.cpg.processing.IVisitable

    accept

    Methods inherited from interface de.fraunhofer.aisec.cpg.graph.StatementHolder

    addStatement, getStatements, getStatementsPropertyEdge, setStatements
  • Constructor Details

    • NamespaceDeclaration

      public NamespaceDeclaration()
  • Method Details

    • getFields

      public java.util.List<FieldDeclaration> getFields()
    • getFunctions

      public java.util.List<FunctionDeclaration> getFunctions()
    • getRecords

      public java.util.List<RecordDeclaration> getRecords()
    • getNamespaces

      public java.util.List<NamespaceDeclaration> getNamespaces()
    • getDeclarations

      @NotNull public java.util.List<Declaration> getDeclarations()
      Specified by:
      getDeclarations in interface DeclarationHolder
    • getDeclarationsByName

      public <T extends Declaration> @NonNull java.util.Set<T> getDeclarationsByName​(@NonNull java.lang.String name, @NonNull java.lang.Class<T> clazz)
      Returns a non-null, possibly empty Set of the declaration of a specified type and clazz.
      Type Parameters:
      T - the type of the declaration
      Parameters:
      name - the name to search for
      clazz - the declaration class, such as FunctionDeclaration.
      Returns:
      a Set containing the declarations, if any.
    • getDeclarationAs

      public <T> T getDeclarationAs​(int i, java.lang.Class<T> clazz)
    • getStatementEdges

      public @NonNull java.util.List<de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge<Statement>> getStatementEdges()
      Description copied from interface: StatementHolder
      Getter to be implemented by implementing classes to gain read access to the classes member.
      Specified by:
      getStatementEdges in interface StatementHolder
      Returns:
      List of property Edge statements
    • setStatementEdges

      public void setStatementEdges​(@NonNull java.util.List<de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge<Statement>> statements)
      Specified by:
      setStatementEdges in interface StatementHolder
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class de.fraunhofer.aisec.cpg.graph.Node
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class de.fraunhofer.aisec.cpg.graph.Node
    • addDeclaration

      public void addDeclaration​(@NonNull Declaration declaration)
      Description copied from interface: DeclarationHolder
      Adds the specified declaration to this declaration holder. Ideally, the declaration holder should use the DeclarationHolder.addIfNotContains(Collection, Declaration) method to consistently add declarations.
      Specified by:
      addDeclaration in interface DeclarationHolder
      Parameters:
      declaration - the declaration