Class JavaFileArtifact
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.artifactModel.CompositeArtifact
-
- net.ssehub.easy.instantiation.core.model.artifactModel.FileArtifact
-
- net.ssehub.easy.instantiation.java.artifacts.JavaFileArtifact
-
- All Implemented Interfaces:
IArtifact,IArtifactChangedListener,IFileSystemArtifact,IActualValueProvider,IStringValueProvider,IVilType,IJavaParent
public class JavaFileArtifact extends 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
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description private booleanchangedprivate java.util.List<JavaClass>classListprivate java.io.Filefileprivate static EASyLoggerFactory.EASyLoggerloggerprivate org.eclipse.jdt.core.dom.CompilationUnitunitNode-
Fields inherited from class net.ssehub.easy.instantiation.core.model.artifactModel.FileArtifact
DEFAULT
-
-
Constructor Summary
Constructors Constructor Description JavaFileArtifact(java.io.File file, 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.StringannotationValue(java.lang.String annotation, java.lang.String field)Returns the annotation value.voidartifactChanged(java.lang.Object cause)Is called when the artifact was changed, e.g., to trigger a reanalysis of substructures.private booleancheckAnnotation(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.Set<JavaClass>classes()Returns the classes of this java file.static JavaFileArtifactconvert(java.lang.String val)Conversion operation.static JavaFileArtifactconvert(IFileSystemArtifact val)Conversion operation.static JavaFileArtifactconvert(Path path)Conversion operation.voiddeleteChild(FragmentArtifact child)Notifies the parent that the given child shall be deleted.JavaClassgetClassByName(java.lang.String name)Returns the specified classes of this java file.JavaClassgetDefaultClass()Returns the default class of this Java File artifact, i.e., the class corresponding to the name of this artifact.booleanhasAnnotation(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.Set<JavaImport>imports()Returns all imports.private voidinitialize()Initializes the parse tree / classes fromfile.private voidinitialize(char[] data)Initializes the parse tree / classes.JavaPackagejavaPackage()Returns the package declaration.voidmodifiyNamespace(java.util.Map<java.lang.String,java.lang.String> nameMapping)Renames all (qualified) package names, imports and packages in this Java artifact as stated bynameMapping.voidmodifyNamespace(java.lang.String oldName, java.lang.String newName)Renames all (qualified) package names, imports and packages in this Java artifact fromoldNametonewName.voidnotifyChildChanged(FragmentArtifact child)Notifies the parent that one of its childs changed.private voidprintWarnings(boolean isClasspathFromScript)Check for problems but only if the classpath was set via VIL.Set<JavaQualifiedName>qualifiedNames()Returns all qualified names.static java.lang.StringreadFileToString(java.io.File filePath)Reads a file to String.voidrenameImports(java.lang.String oldName, java.lang.String newName)Renames all imports in this Java artifact fromoldNametonewName.voidrenameImports(java.util.Map<java.lang.String,java.lang.String> nameMapping)Renames all imports in this Java artifact as stated bynameMapping.voidrenamePackages(java.lang.String oldName, java.lang.String newName)Renames all (qualified) package names in this Java artifact fromoldNametonewName.voidrenamePackages(java.util.Map<java.lang.String,java.lang.String> nameMapping)Renames all (qualified) package names in this Java artifact as stated bynameMapping.voidrenameQualifiedNames(java.lang.String oldName, java.lang.String newName)Renames all qualified names in this Java artifact fromoldNametonewName.voidrenameQualifiedNames(java.util.Map<java.lang.String,java.lang.String> nameMapping)Renames all qualified names in this Java artifact as stated bynameMapping.voidstore()Stores this artifact in case of changes.-
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
-
Methods inherited from interface net.ssehub.easy.instantiation.java.artifacts.IJavaParent
getArtifactModel
-
-
-
-
Field Detail
-
logger
private static 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, ArtifactModel model)Creates a new class file artifact.- Parameters:
file- the file to read the artifact contents frommodel- 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 typefield- 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 annotationfield- the name of the annotation field (if null or empty thedefault name "value"is usedvalue- the name of the annotation value- Returns:
trueif this annotation is present,falseelse
-
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 namefield- the name of the fieldvalue- The annotation valuehasAnnotation- indicates if annotation is presentannotations- Set with JavaAnnotations- Returns:
- hasAnnotation true of false
-
artifactChanged
public void artifactChanged(java.lang.Object cause) throws VilExceptionDescription copied from interface:IArtifactChangedListenerIs called when the artifact was changed, e.g., to trigger a reanalysis of substructures.- Specified by:
artifactChangedin interfaceIArtifactChangedListener- Overrides:
artifactChangedin classCompositeArtifact- Parameters:
cause- the cause for the change, e.g., an artifact representation- Throws:
VilException- in case that the required operations fail for some reason
-
store
public void store() throws VilExceptionDescription copied from interface:IArtifactStores this artifact in case of changes.- Specified by:
storein interfaceIArtifact- Specified by:
storein interfaceIJavaParent- Overrides:
storein classFileArtifact- Throws:
VilException- in case of problems storing this artifact
-
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 fromfile.
-
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:IJavaParentNotifies the parent that one of its childs changed.- Specified by:
notifyChildChangedin interfaceIJavaParent- Parameters:
child- the child which changed
-
deleteChild
public void deleteChild(FragmentArtifact child) throws VilException
Description copied from interface:IJavaParentNotifies the parent that the given child shall be deleted. The parent is notified implicitly about the "change" so thatIJavaParent.notifyChildChanged(FragmentArtifact)is not needed- Specified by:
deleteChildin interfaceIJavaParent- Parameters:
child- the child to be deleted- Throws:
VilException- in case that deletion fails
-
imports
public Set<JavaImport> imports()
Returns all imports.- Returns:
- all imports
-
javaPackage
public JavaPackage javaPackage()
Returns the package declaration.- Returns:
JavaPackagerepresenting 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 fromoldNametonewName. Nothing happens, ifoldNamecannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.- Parameters:
oldName- the old package namenewName- 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 bynameMapping. Nothing happens, ifoldNamecannot 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 VilExceptionRenames all (qualified) package names in this Java artifact fromoldNametonewName. Nothing happens, ifoldNamecannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.- Parameters:
oldName- the old package namenewName- 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 VilExceptionRenames all (qualified) package names in this Java artifact as stated bynameMapping. 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 VilExceptionRenames all imports in this Java artifact fromoldNametonewName. Nothing happens, ifoldNamecannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.- Parameters:
oldName- the old import namenewName- 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 VilExceptionRenames all imports in this Java artifact as stated bynameMapping. 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 VilExceptionRenames all qualified names in this Java artifact fromoldNametonewName. Nothing happens, ifoldNamecannot be found. However, the caller is responsible for potential name clashes due to the execution of this operation.- Parameters:
oldName- the old qualified namenewName- 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 VilExceptionRenames all qualified names in this Java artifact as stated bynameMapping. 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
-
-