Class JavaFileArtifact

  • All Implemented Interfaces:
    net.ssehub.easy.instantiation.core.model.artifactModel.IArtifact, net.ssehub.easy.instantiation.core.model.artifactModel.IArtifactChangedListener, net.ssehub.easy.instantiation.core.model.artifactModel.IFileSystemArtifact, net.ssehub.easy.instantiation.core.model.vilTypes.IActualValueProvider, net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider, net.ssehub.easy.instantiation.core.model.vilTypes.IVilType, IJavaParent

    public class JavaFileArtifact
    extends net.ssehub.easy.instantiation.core.model.artifactModel.FileArtifact
    implements IJavaParent
    Represents a Java source code file artifact.
    Author:
    Holger Eichelberger, Sass
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider

        net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider.StringComparator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean changed  
      private java.util.List<JavaClass> classList  
      private java.io.File file  
      private static net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger logger  
      private org.eclipse.jdt.core.dom.CompilationUnit unitNode  
      • Fields inherited from class net.ssehub.easy.instantiation.core.model.artifactModel.FileArtifact

        DEFAULT
    • Constructor Summary

      Constructors 
      Constructor Description
      JavaFileArtifact​(java.io.File file, net.ssehub.easy.instantiation.core.model.artifactModel.ArtifactModel model)
      Creates a new class file artifact.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String annotationValue​(java.lang.String annotation, java.lang.String field)
      Returns the annotation value.
      void artifactChanged​(java.lang.Object cause)  
      private boolean checkAnnotation​(java.lang.String annotation, java.lang.String field, java.lang.String value, boolean hasAnnotation, net.ssehub.easy.instantiation.core.model.vilTypes.Set<JavaAnnotation> annotations)
      Checks if a Set of JavaAnnotations contains a specific annotation.
      net.ssehub.easy.instantiation.core.model.vilTypes.Set<JavaClass> classes()
      Returns the classes of this java file.
      static JavaFileArtifact convert​(java.lang.String val)
      Conversion operation.
      static JavaFileArtifact convert​(net.ssehub.easy.instantiation.core.model.artifactModel.IFileSystemArtifact val)
      Conversion operation.
      static JavaFileArtifact convert​(net.ssehub.easy.instantiation.core.model.artifactModel.Path path)
      Conversion operation.
      void deleteChild​(net.ssehub.easy.instantiation.core.model.artifactModel.FragmentArtifact child)
      Notifies the parent that the given child shall be deleted.
      JavaClass getClassByName​(java.lang.String name)
      Returns the specified classes of this java file.
      JavaClass getDefaultClass()
      Returns the default class of this Java File artifact, i.e., the class corresponding to the name of this artifact.
      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.
      net.ssehub.easy.instantiation.core.model.vilTypes.Set<JavaImport> imports()
      Returns all imports.
      private void initialize()
      Initializes the parse tree / classes from file.
      private void initialize​(char[] data)
      Initializes the parse tree / classes.
      JavaPackage javaPackage()
      Returns the package declaration.
      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.
      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.
      void notifyChildChanged​(net.ssehub.easy.instantiation.core.model.artifactModel.FragmentArtifact child)
      Notifies the parent that one of its childs changed.
      private void printWarnings​(boolean isClasspathFromScript)
      Check for problems but only if the classpath was set via VIL.
      net.ssehub.easy.instantiation.core.model.vilTypes.Set<JavaQualifiedName> qualifiedNames()
      Returns all qualified names.
      static java.lang.String readFileToString​(java.io.File filePath)
      Reads a file to String.
      void renameImports​(java.lang.String oldName, java.lang.String newName)
      Renames all imports in this Java artifact from oldName to newName.
      void renameImports​(java.util.Map<java.lang.String,​java.lang.String> nameMapping)
      Renames all imports in this Java artifact as stated by nameMapping.
      void renamePackages​(java.lang.String oldName, java.lang.String newName)
      Renames all (qualified) package names in this Java artifact from oldName to newName.
      void renamePackages​(java.util.Map<java.lang.String,​java.lang.String> nameMapping)
      Renames all (qualified) package names in this Java artifact as stated by nameMapping.
      void renameQualifiedNames​(java.lang.String oldName, java.lang.String newName)
      Renames all qualified names in this Java artifact from oldName to newName.
      void renameQualifiedNames​(java.util.Map<java.lang.String,​java.lang.String> nameMapping)
      Renames all qualified names in this Java artifact as stated by nameMapping.
      void store()
      Stores the artifact / fragment.
      • Methods inherited from class net.ssehub.easy.instantiation.core.model.artifactModel.FileArtifact

        accept, convert, copy, create, createBinary, createText, delete, determineActualValue, exists, getArtifactModel, getName, getPath, getPathSegments, getPlainName, getStringValue, isTemporary, lastModification, move, rename, selectAll, setExecutable, substituteExtension
      • Methods inherited from class net.ssehub.easy.instantiation.core.model.artifactModel.CompositeArtifact

        getBinary, getBinaryInstance, getRepresentationChanged, getText, getTextInstance, update
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface net.ssehub.easy.instantiation.core.model.artifactModel.IArtifact

        getBinary, getText, update
    • Field Detail

      • logger

        private static net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger logger
      • 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,
                         net.ssehub.easy.instantiation.core.model.artifactModel.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,
                                        net.ssehub.easy.instantiation.core.model.vilTypes.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
      • artifactChanged

        public void artifactChanged​(java.lang.Object cause)
                             throws net.ssehub.easy.instantiation.core.model.common.VilException
        Specified by:
        artifactChanged in interface net.ssehub.easy.instantiation.core.model.artifactModel.IArtifactChangedListener
        Overrides:
        artifactChanged in class net.ssehub.easy.instantiation.core.model.artifactModel.CompositeArtifact
        Throws:
        net.ssehub.easy.instantiation.core.model.common.VilException
      • store

        public void store()
                   throws net.ssehub.easy.instantiation.core.model.common.VilException
        Description copied from interface: IJavaParent
        Stores the artifact / fragment.
        Specified by:
        store in interface net.ssehub.easy.instantiation.core.model.artifactModel.IArtifact
        Specified by:
        store in interface IJavaParent
        Overrides:
        store in class net.ssehub.easy.instantiation.core.model.artifactModel.FileArtifact
        Throws:
        net.ssehub.easy.instantiation.core.model.common.VilException - in case that storing fails
      • classes

        public net.ssehub.easy.instantiation.core.model.vilTypes.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​(net.ssehub.easy.instantiation.core.model.artifactModel.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
      • deleteChild

        public void deleteChild​(net.ssehub.easy.instantiation.core.model.artifactModel.FragmentArtifact child)
                         throws net.ssehub.easy.instantiation.core.model.common.VilException
        Description copied from interface: IJavaParent
        Notifies the parent that the given child shall be deleted. The parent is notified implicitly about the "change" so that IJavaParent.notifyChildChanged(FragmentArtifact) is not needed
        Specified by:
        deleteChild in interface IJavaParent
        Parameters:
        child - the child to be deleted
        Throws:
        net.ssehub.easy.instantiation.core.model.common.VilException - in case that deletion fails
      • imports

        public net.ssehub.easy.instantiation.core.model.vilTypes.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 net.ssehub.easy.instantiation.core.model.vilTypes.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 net.ssehub.easy.instantiation.core.model.common.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:
        net.ssehub.easy.instantiation.core.model.common.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 net.ssehub.easy.instantiation.core.model.common.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:
        net.ssehub.easy.instantiation.core.model.common.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 net.ssehub.easy.instantiation.core.model.common.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:
        net.ssehub.easy.instantiation.core.model.common.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 net.ssehub.easy.instantiation.core.model.common.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:
        net.ssehub.easy.instantiation.core.model.common.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 net.ssehub.easy.instantiation.core.model.common.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:
        net.ssehub.easy.instantiation.core.model.common.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 net.ssehub.easy.instantiation.core.model.common.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:
        net.ssehub.easy.instantiation.core.model.common.VilException - in case that the operation cannot be executed due to syntax or I/O problems
      • convert

        public static JavaFileArtifact convert​(net.ssehub.easy.instantiation.core.model.artifactModel.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 net.ssehub.easy.instantiation.core.model.common.VilException
        Conversion operation.
        Parameters:
        val - the value to be converted
        Returns:
        the converted value
        Throws:
        net.ssehub.easy.instantiation.core.model.common.VilException - in case that creating the artifact fails
      • convert

        public static JavaFileArtifact convert​(net.ssehub.easy.instantiation.core.model.artifactModel.Path path)
                                        throws net.ssehub.easy.instantiation.core.model.common.VilException
        Conversion operation.
        Parameters:
        path - the path to be converted
        Returns:
        the converted value
        Throws:
        net.ssehub.easy.instantiation.core.model.common.VilException - in case that creating the artifact fails