Class Text

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Text CONSTANT_EMPTY  
      private java.io.File file  
      private java.lang.String text  
    • Constructor Summary

      Constructors 
      Constructor Description
      Text​(boolean modifiable)
      Creates a new empty textual representation.
      Text​(java.io.File file, boolean modifiable)
      Creates a new textual representation from file.
      Text​(java.lang.String text, boolean modifiable)
      Creates a new textual representation from text.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Text append​(java.lang.String text)
      Appends the given text.
      Text append​(Text text)
      Appends the textual representation of another artifact.
      void artifactChanged​(java.lang.Object cause)
      Is called when the artifact was changed, e.g., to trigger a reanalysis of substructures.
      private boolean containsRegex​(java.lang.String regex)
      Returns whether this textual representation contains a match for the given regex.
      private int getRegexMatchLength​(java.lang.String regex)
      Calculates the length of the first string in the text that matches the given regular expression.
      java.lang.String getStringValue​(IStringValueProvider.StringComparator comparator)
      Returns the string value of this object.
      java.lang.String getText()
      Returns the actual text.
      int indexOf​(java.lang.String search)
      Returns the index of the first occurrence of the given string.
      int indexOf​(java.lang.String search, int fromIndex)
      Returns the index of the first occurrence of the given string, starting the search at the specified index.
      int indexOf​(Text search)
      Returns the index of the first occurrence of the given textual representation of another artifact.
      int indexOf​(Text search, int fromIndex)
      Returns the index of the first occurrence of the given textual representation of another artifact, starting the search at the specified index.
      private int indexOfRegex​(java.lang.String regex)
      Returns the index of the first match of the given regular expression.
      private int indexOfRegex​(java.lang.String regex, int fromIndex)
      Returns the index of the first match of the given regular expression, starting the search at the specified index.
      Text insert​(int index, java.lang.String insertion)
      Inserts the given string at the given index.
      Text insert​(int index, Text insertion)
      Inserts the textual representation of another artifact at the given index.
      boolean isEmpty()
      Returns whether this artifact representation is empty.
      boolean matches​(java.lang.String regex)
      Returns whether this textual representation matches the given regex.
      Text prepend​(java.lang.String text)
      Prepends the given text.
      Text prepend​(Text text)
      Prepends the textual representation of another artifact.
      Text remove​(java.lang.String part)
      Removes the the first occurrence of the given string in this.
      Text remove​(Text part)
      Removes the the first occurrence of the given textual representation of another artifact in this.
      Text removeAll​(java.lang.String part)
      Removes all occurrences of the given string in this.
      Text removeAll​(Text part)
      Removes all occurrences of the given textual representation of another artifact in this.
      private void removeRegex​(java.lang.String regex)
      Removes the first string in this that matches the given regular expression.
      Text replace​(java.lang.String search, java.lang.String replacement)
      Replaces all occurrences of search by replacement.
      void setText​(java.lang.String text)
      Changes the entire text of this artifact.
      Text substitute​(java.lang.String regex, java.lang.String replacement)
      Substitutes all parts matching the regular expression regex by replacement.
      void updateContents()
      Updates the contents.
      void write​(java.io.Writer out)
      Writes the data to the given output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CONSTANT_EMPTY

        public static final Text CONSTANT_EMPTY
      • text

        private java.lang.String text
      • file

        private java.io.File file
    • Constructor Detail

      • Text

        public Text​(boolean modifiable)
        Creates a new empty textual representation.
        Parameters:
        modifiable - whether this representation shall be modifiable
      • Text

        public Text​(java.io.File file,
                    boolean modifiable)
             throws VilException
        Creates a new textual representation from file.
        Parameters:
        file - the file to be considered as input
        modifiable - whether this representation shall be modifiable
        Throws:
        VilException - in case that reading fails for some reason
      • Text

        public Text​(java.lang.String text,
                    boolean modifiable)
             throws VilException
        Creates a new textual representation from text.
        Parameters:
        text - the text to be considered as input
        modifiable - whether this representation shall be modifiable
        Throws:
        VilException - in case that reading fails for some reason
    • Method Detail

      • substitute

        public Text substitute​(java.lang.String regex,
                               java.lang.String replacement)
                        throws VilException
        Substitutes all parts matching the regular expression regex by replacement.
        Parameters:
        regex - the regular expression to search for
        replacement - the replacement
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • matches

        public boolean matches​(java.lang.String regex)
                        throws VilException
        Returns whether this textual representation matches the given regex.
        Parameters:
        regex - the regular expression to be matched
        Returns:
        true if regex matches this textual representation, false else
        Throws:
        VilException - if the pattern is invalid
      • replace

        public Text replace​(java.lang.String search,
                            java.lang.String replacement)
                     throws VilException
        Replaces all occurrences of search by replacement.
        Parameters:
        search - the string to search for
        replacement - the replacement string
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • append

        public Text append​(java.lang.String text)
                    throws VilException
        Appends the given text.
        Parameters:
        text - the text to be appended
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • prepend

        public Text prepend​(java.lang.String text)
                     throws VilException
        Prepends the given text.
        Parameters:
        text - the text to be prepended
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • append

        public Text append​(Text text)
                    throws VilException
        Appends the textual representation of another artifact.
        Parameters:
        text - the text to be appended
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • prepend

        public Text prepend​(Text text)
                     throws VilException
        Prepends the textual representation of another artifact.
        Parameters:
        text - the text to be prepended
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • insert

        public Text insert​(int index,
                           Text insertion)
                    throws VilException
        Inserts the textual representation of another artifact at the given index.
        Parameters:
        index - the index in this
        insertion - the text to be inserted
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • insert

        public Text insert​(int index,
                           java.lang.String insertion)
                    throws VilException
        Inserts the given string at the given index.
        Parameters:
        index - the index in this
        insertion - the string to be inserted
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • indexOf

        public int indexOf​(Text search)
        Returns the index of the first occurrence of the given textual representation of another artifact.
        Parameters:
        search - the textual representation of another artifact
        Returns:
        the index of search in this, or -1 if the text does not occur
      • indexOf

        public int indexOf​(java.lang.String search)
        Returns the index of the first occurrence of the given string.
        Parameters:
        search - the string to be searched for
        Returns:
        the index of search in this, or -1 if the string does not occur
      • indexOfRegex

        private int indexOfRegex​(java.lang.String regex)
        Returns the index of the first match of the given regular expression.
        Parameters:
        regex - the regular expression to search for
        Returns:
        the index of regex in this, or -1 if no match was found
      • indexOf

        public int indexOf​(Text search,
                           int fromIndex)
        Returns the index of the first occurrence of the given textual representation of another artifact, starting the search at the specified index.
        Parameters:
        search - the textual representation of another artifact
        fromIndex - the index to start the search from
        Returns:
        the index of search in this, or -1 if the text does not occur
      • indexOf

        public int indexOf​(java.lang.String search,
                           int fromIndex)
        Returns the index of the first occurrence of the given string, starting the search at the specified index.
        Parameters:
        search - the string to be searched for
        fromIndex - the index to start the search from
        Returns:
        the index of search in this, or -1 if the string does not occur
      • indexOfRegex

        private int indexOfRegex​(java.lang.String regex,
                                 int fromIndex)
        Returns the index of the first match of the given regular expression, starting the search at the specified index.
        Parameters:
        regex - the regular expression to search for
        fromIndex - the index to start the search from
        Returns:
        the index of regex in this, or -1 if no match was found
      • remove

        public Text remove​(Text part)
                    throws VilException
        Removes the the first occurrence of the given textual representation of another artifact in this.
        Parameters:
        part - the textual representation of another artifact to be removed
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - ArtifactException in case that listener updates fail
      • remove

        public Text remove​(java.lang.String part)
                    throws VilException
        Removes the the first occurrence of the given string in this.
        Parameters:
        part - the string to be removed
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - ArtifactException in case that listener updates fail
      • removeRegex

        private void removeRegex​(java.lang.String regex)
        Removes the first string in this that matches the given regular expression.
        Parameters:
        regex - the regular expression with which a match shall be found
      • getRegexMatchLength

        private int getRegexMatchLength​(java.lang.String regex)
        Calculates the length of the first string in the text that matches the given regular expression.
        Parameters:
        regex - the regular expression with which a match shall be found
        Returns:
        the length of the match in the text, or -1 if no match was found.
      • removeAll

        public Text removeAll​(Text part)
                       throws VilException
        Removes all occurrences of the given textual representation of another artifact in this.
        Parameters:
        part - the textual representation of another artifact to be removed
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - ArtifactException in case that listener updates fail
      • removeAll

        public Text removeAll​(java.lang.String part)
                       throws VilException
        Removes all occurrences of the given string in this.
        Parameters:
        part - the string to be removed
        Returns:
        this (for concatenated operations)
        Throws:
        VilException - in case that listener updates fail
      • containsRegex

        private boolean containsRegex​(java.lang.String regex)
        Returns whether this textual representation contains a match for the given regex.
        Parameters:
        regex - the regular expression to be matched
        Returns:
        true if this textual representation contains a match for regex, false else
      • getText

        public java.lang.String getText()
        Returns the actual text.
        Returns:
        the actual text
      • artifactChanged

        public void artifactChanged​(java.lang.Object cause)
                             throws VilException
        Description copied from interface: IArtifactChangedListener
        Is called when the artifact was changed, e.g., to trigger a reanalysis of substructures.
        Specified by:
        artifactChanged in interface IArtifactChangedListener
        Parameters:
        cause - the cause for the change, e.g., an artifact representation
        Throws:
        VilException - in case that the required operations fail for some reason
      • setText

        public void setText​(java.lang.String text)
        Changes the entire text of this artifact.
        Parameters:
        text - the text to be changed
      • write

        public void write​(java.io.Writer out)
                   throws java.io.IOException
        Writes the data to the given output stream.
        Parameters:
        out - the target output stream
        Throws:
        java.io.IOException - in case of I/O problems
      • getStringValue

        public java.lang.String getStringValue​(IStringValueProvider.StringComparator comparator)
        Description copied from interface: IStringValueProvider
        Returns the string value of this object.
        Specified by:
        getStringValue in interface IStringValueProvider
        Parameters:
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value