Class JavaFileArtifact

    • Field Detail

      • file

        private java.io.File file
      • unitNode

        private org.eclipse.jdt.core.dom.CompilationUnit unitNode
      • classList

        private java.util.List<JavaClass> classList
      • changed

        private boolean changed
    • Constructor Detail

      • JavaFileArtifact

        JavaFileArtifact​(java.io.File file,
                         ArtifactModel model)
        Creates a new class file artifact.
        Parameters:
        file - the file to read the artifact contents from
        model - the artifact model to create this folder artifact within
    • Method Detail

      • annotationValue

        public java.lang.String annotationValue​(java.lang.String annotation,
                                                java.lang.String field)
        Returns the annotation value.
        Parameters:
        annotation - the name of the annotation type
        field - the field to be returned
        Returns:
        the field or null if not found
      • hasAnnotation

        public boolean hasAnnotation​(java.lang.String annotation,
                                     java.lang.String field,
                                     java.lang.String value)
        Return whether one of the classes, the methods or attributes has this annotation.
        Parameters:
        annotation - the (qualified) name of the annotation
        field - the name of the annotation field (if null or empty the default name "value" is used
        value - the name of the annotation value
        Returns:
        true if this annotation is present, false else
      • checkAnnotation

        private boolean checkAnnotation​(java.lang.String annotation,
                                        java.lang.String field,
                                        java.lang.String value,
                                        boolean hasAnnotation,
                                        Set<JavaAnnotation> annotations)
        Checks if a Set of JavaAnnotations contains a specific annotation.
        Parameters:
        annotation - The annotation name
        field - the name of the field
        value - The annotation value
        hasAnnotation - indicates if annotation is present
        annotations - Set with JavaAnnotations
        Returns:
        hasAnnotation true of false
      • classes

        public Set<JavaClass> classes()
        Returns the classes of this java file.
        Returns:
        the annotations
      • getClassByName

        public JavaClass getClassByName​(java.lang.String name)
        Returns the specified classes of this java file.
        Parameters:
        name - the name of the class
        Returns:
        the specified class or null
      • getDefaultClass

        public JavaClass getDefaultClass()
        Returns the default class of this Java File artifact, i.e., the class corresponding to the name of this artifact.
        Returns:
        the default class or null if there is none
      • initialize

        private void initialize()
        Initializes the parse tree / classes from file.
      • initialize

        private void initialize​(char[] data)
        Initializes the parse tree / classes.
        Parameters:
        data - the data to initialize from (source code as characters)
      • printWarnings

        private void printWarnings​(boolean isClasspathFromScript)
        Check for problems but only if the classpath was set via VIL.
        Parameters:
        isClasspathFromScript - flag that indicates if the classpath was set via VIL
      • readFileToString

        public static java.lang.String readFileToString​(java.io.File filePath)
        Reads a file to String.
        Parameters:
        filePath - The file path as String.
        Returns:
        File as String.
      • notifyChildChanged

        public void notifyChildChanged​(FragmentArtifact child)
        Description copied from interface: IJavaParent
        Notifies the parent that one of its childs changed.
        Specified by:
        notifyChildChanged in interface IJavaParent
        Parameters:
        child - the child which changed
      • imports

        public Set<JavaImport> imports()
        Returns all imports.
        Returns:
        all imports
      • javaPackage

        public JavaPackage javaPackage()
        Returns the package declaration.
        Returns:
        JavaPackage representing the package declaration
      • qualifiedNames

        public Set<JavaQualifiedName> qualifiedNames()
        Returns all qualified names.
        Returns:
        all qualified names.
      • modifyNamespace

        public void modifyNamespace​(java.lang.String oldName,
                                    java.lang.String newName)
        Renames all (qualified) package names, imports and packages in this Java artifact from oldName to newName. Nothing happens, if oldName cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        oldName - the old package name
        newName - the new package name
      • modifiyNamespace

        public void modifiyNamespace​(java.util.Map<java.lang.String,​java.lang.String> nameMapping)
        Renames all (qualified) package names, imports and packages in this Java artifact as stated by nameMapping. Nothing happens, if oldName cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        nameMapping - pairs of old and new package names (key = old, value = new)
      • renamePackages

        public void renamePackages​(java.lang.String oldName,
                                   java.lang.String newName)
                            throws VilException
        Renames all (qualified) package names in this Java artifact from oldName to newName. Nothing happens, if oldName cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        oldName - the old package name
        newName - the new package name
        Throws:
        VilException - in case that the operation cannot be executed due to syntax or I/O problems
      • renamePackages

        public void renamePackages​(java.util.Map<java.lang.String,​java.lang.String> nameMapping)
                            throws VilException
        Renames all (qualified) package names in this Java artifact as stated by nameMapping. Nothing happens, if package names cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        nameMapping - pairs of old and new package names (key = old, value = new)
        Throws:
        VilException - in case that the operation cannot be executed due to syntax or I/O problems
      • renameImports

        public void renameImports​(java.lang.String oldName,
                                  java.lang.String newName)
                           throws VilException
        Renames all imports in this Java artifact from oldName to newName. Nothing happens, if oldName cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        oldName - the old import name
        newName - the new import name
        Throws:
        VilException - in case that the operation cannot be executed due to syntax or I/O problems
      • renameImports

        public void renameImports​(java.util.Map<java.lang.String,​java.lang.String> nameMapping)
                           throws VilException
        Renames all imports in this Java artifact as stated by nameMapping. Nothing happens, if package names cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        nameMapping - pairs of old and new import names (key = old, value = new)
        Throws:
        VilException - in case that the operation cannot be executed due to syntax or I/O problems
      • renameQualifiedNames

        public void renameQualifiedNames​(java.lang.String oldName,
                                         java.lang.String newName)
                                  throws VilException
        Renames all qualified names in this Java artifact from oldName to newName. Nothing happens, if oldName cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        oldName - the old qualified name
        newName - the new qualified name
        Throws:
        VilException - in case that the operation cannot be executed due to syntax or I/O problems
      • renameQualifiedNames

        public void renameQualifiedNames​(java.util.Map<java.lang.String,​java.lang.String> nameMapping)
                                  throws VilException
        Renames all qualified names in this Java artifact as stated by nameMapping. Nothing happens, if package names cannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.
        Parameters:
        nameMapping - pairs of old and new qualified names (key = old, value = new)
        Throws:
        VilException - in case that the operation cannot be executed due to syntax or I/O problems
      • convert

        public static JavaFileArtifact convert​(IFileSystemArtifact val)
        Conversion operation.
        Parameters:
        val - the value to be converted
        Returns:
        the converted value or null
      • convert

        public static JavaFileArtifact convert​(java.lang.String val)
                                        throws VilException
        Conversion operation.
        Parameters:
        val - the value to be converted
        Returns:
        the converted value
        Throws:
        VilException - in case that creating the artifact fails
      • convert

        public static JavaFileArtifact convert​(Path path)
                                        throws VilException
        Conversion operation.
        Parameters:
        path - the path to be converted
        Returns:
        the converted value
        Throws:
        VilException - in case that creating the artifact fails