java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.util.Util

public class Util extends Object
Provides convenient utility methods to other types in this package.
  • Methodendetails

    • arrayConcat

      public static final String[] arrayConcat(String[] first, String second)
      Returns a new array adding the second array at the end of first array. It answers null if the first and second are null. If the first array is null or if it is empty, then a new array is created with second. If the second array is null, then the first array is returned.

      For example:
      1.     first = null
            second = "a"
            => result = {"a"}
         
      2.     first = {"a"}
            second = null
            => result = {"a"}
         
      3.     first = {"a"}
            second = {"b"}
            => result = {"a", "b"}
         
      Parameter:
      first - the first array to concatenate
      second - the array to add at the end of the first array
      Gibt zurück:
      a new array adding the second array at the end of first array, or null if the two arrays are null.
    • combineHashCodes

      public static int combineHashCodes(int hashCode1, int hashCode2)
      Combines two hash codes to make a new one.
    • compare

      public static int compare(byte[] a, byte[] b)
      Compares two byte arrays. Returns Ungültige Eingabe: "<"0 if a byte in a is less than the corresponding byte in b, or if a is shorter, or if a is null. Returns >0 if a byte in a is greater than the corresponding byte in b, or if a is longer, or if b is null. Returns 0 if they are equal or both null.
    • compare

      public static int compare(char[] str1, char[] str2)
      Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings.
      Gibt zurück:
      the value 0 if the str1 is equal to str2; a value less than 0 if str1 is lexicographically less than str2; and a value greater than 0 if str1 is lexicographically greater than str2.
    • concatCompoundNameToCharArray

      public static char[] concatCompoundNameToCharArray(String[] compoundName)
      Concatenate a String[] compound name to a continuous char[].
    • concatenateName

      public static String concatenateName(String name1, String name2, char separator)
    • concatWith

      public static final String concatWith(String[] array, char separator)
      Returns the concatenation of the given array parts using the given separator between each part.

      For example:
      1.     array = {"a", "b"}
            separator = '.'
            => result = "a.b"
         
      2.     array = {}
            separator = '.'
            => result = ""
         
      Parameter:
      array - the given array
      separator - the given separator
      Gibt zurück:
      the concatenation of the given array parts using the given separator between each part
    • concatWith

      public static final String concatWith(String[] array, String name, char separator)
      Returns the concatenation of the given array parts using the given separator between each part and appending the given name at the end.

      For example:
      1.     name = "c"
            array = { "a", "b" }
            separator = '.'
            => result = "a.b.c"
         
      2.     name = null
            array = { "a", "b" }
            separator = '.'
            => result = "a.b"
         
      3.     name = " c"
            array = null
            separator = '.'
            => result = "c"
         
      Parameter:
      array - the given array
      name - the given name
      separator - the given separator
      Gibt zurück:
      the concatenation of the given array parts using the given separator between each part and appending the given name at the end
    • concat

      public static final char[] concat(char[] first, char[] second)
    • convertTypeSignature

      public static String convertTypeSignature(char[] sig, int start, int length)
      Converts a type signature from the IBinaryType representation to the DC representation.
    • defaultJavaExtension

      public static String defaultJavaExtension()
    • editedString

      public static final String editedString(String original, org.eclipse.text.edits.TextEdit edit)
      Apply the given edit on the given string and return the updated string. Return the given string if anything wrong happen while applying the edit.
      Parameter:
      original - the given string
      edit - the given edit
      Gibt zurück:
      the updated string
    • endsWithIgnoreCase

      public static final boolean endsWithIgnoreCase(String str, String end)
      Returns true iff str.toLowerCase().endsWith(end.toLowerCase()) implementation is not creating extra strings.
    • equalArrays

      public static boolean equalArrays(Object[] a, Object[] b, int len)
      Compares two arrays using equals() on the elements. Neither can be null. Only the first len elements are compared. Return false if either array is shorter than len.
    • equalArraysOrNull

      public static boolean equalArraysOrNull(int[] a, int[] b)
      Compares two arrays using equals() on the elements. Either or both arrays may be null. Returns true if both are null. Returns false if only one is null. If both are arrays, returns true iff they have the same length and all elements are equal.
    • equalArraysOrNull

      public static boolean equalArraysOrNull(Object[] a, Object[] b)
      Compares two arrays using equals() on the elements. Either or both arrays may be null. Returns true if both are null. Returns false if only one is null. If both are arrays, returns true iff they have the same length and all elements compare true with equals.
    • equalArraysOrNullSortFirst

      public static boolean equalArraysOrNullSortFirst(Util.Comparable[] a, Util.Comparable[] b)
      Compares two arrays using equals() on the elements. The arrays are first sorted. Either or both arrays may be null. Returns true if both are null. Returns false if only one is null. If both are arrays, returns true iff they have the same length and iff, after sorting both arrays, all elements compare true with equals. The original arrays are left untouched.
    • equalArraysOrNullSortFirst

      public static boolean equalArraysOrNullSortFirst(String[] a, String[] b)
      Compares two String arrays using equals() on the elements. The arrays are first sorted. Either or both arrays may be null. Returns true if both are null. Returns false if only one is null. If both are arrays, returns true iff they have the same length and iff, after sorting both arrays, all elements compare true with equals. The original arrays are left untouched.
    • equalOrNull

      public static boolean equalOrNull(Object a, Object b)
      Compares two objects using equals(). Either or both array may be null. Returns true if both are null. Returns false if only one is null. Otherwise, return the result of comparing with equals().
    • equalsIgnoreJavaLikeExtension

      public static boolean equalsIgnoreJavaLikeExtension(String fileName, String string)
    • extractLastName

      public static String extractLastName(String qualifiedName)
      Given a qualified name, extract the last component. If the input is not qualified, the same string is answered.
    • extractParameterTypes

      public static String[] extractParameterTypes(char[] sig)
      Extracts the parameter types from a method signature.
    • extractReturnType

      public static String extractReturnType(String sig)
      Extracts the return type from a method signature.
    • findLineSeparator

      public static String findLineSeparator(char[] text)
      Finds the first line separator used by the given text.
      Gibt zurück:
      "\n" or "\r" or "\r\n", or null if none found
    • getAttribute

      public static IClassFileAttribute getAttribute(IClassFileReader classFileReader, char[] attributeName)
    • getAttribute

      public static IClassFileAttribute getAttribute(ICodeAttribute codeAttribute, char[] attributeName)
    • getAttribute

      public static IClassFileAttribute getAttribute(IFieldInfo fieldInfo, char[] attributeName)
    • getAttribute

      public static IClassFileAttribute getAttribute(IComponentInfo componentInfo, char[] attributeName)
    • getAttribute

      public static IClassFileAttribute getAttribute(IMethodInfo methodInfo, char[] attributeName)
    • getJavaLikeExtensions

      public static char[][] getJavaLikeExtensions()
      Returns the registered Java like extensions.
    • getJdkLevel

      public static long getJdkLevel(Object targetLibrary)
      Get the jdk level of this root. The value can be:
      • majorUngültige Eingabe: "<"Ungültige Eingabe: "<"16 + minor : see predefined constants on ClassFileConstants
      • 0 if the root is a source package fragment root or if a Java model exception occured
      Returns the jdk level
    • getNameWithoutJavaLikeExtension

      public static String getNameWithoutJavaLikeExtension(String fileName)
      Returns the substring of the given file name, ending at the start of a Java like extension. The entire file name is returned if it doesn't end with a Java like extension.
    • getLineSeparator

      public static String getLineSeparator(String text, IJavaProject project)
      Returns the line separator found in the given text. If it is null, or not found return the line delimiter for the given project. If the project is null, returns the line separator for the workspace. If still null, return the system line separator.
    • getPackageFragment

      public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator)
    • getParameterCount

      public static int getParameterCount(char[] sig)
      Returns the number of parameter types in a method signature.
    • getProblemArgumentsForMarker

      public static String getProblemArgumentsForMarker(String[] arguments)
      Put all the arguments in one String.
    • getProblemArgumentsFromMarker

      public static String[] getProblemArgumentsFromMarker(String argumentsString)
      Separate all the arguments of a String made by getProblemArgumentsForMarker
    • getResourceContentsAsByteArray

      public static byte[] getResourceContentsAsByteArray(org.eclipse.core.resources.IFile file) throws JavaModelException
      Returns the given file's contents as a byte array.
      Löst aus:
      JavaModelException
    • getResourceContentsAsCharArray

      public static char[] getResourceContentsAsCharArray(org.eclipse.core.resources.IFile file) throws JavaModelException
      Returns the given file's contents as a character array.
      Löst aus:
      JavaModelException
    • getResourceContentsAsCharArray

      public static char[] getResourceContentsAsCharArray(org.eclipse.core.resources.IFile file, String encoding) throws JavaModelException
      Löst aus:
      JavaModelException
    • getSignature

      public static String getSignature(Type type)
    • getSourceAttachmentProperty

      public static String getSourceAttachmentProperty(org.eclipse.core.runtime.IPath path) throws JavaModelException
      Löst aus:
      JavaModelException
    • setSourceAttachmentProperty

      public static void setSourceAttachmentProperty(org.eclipse.core.runtime.IPath path, String property)
    • getDeclaringTypeSignature

      public static String getDeclaringTypeSignature(String key)
    • getTrimmedSimpleNames

      public static String[] getTrimmedSimpleNames(String name)
      Returns a trimmed version the simples names returned by Signature.
    • getUnresolvedJavaElement

      public static JavaElement getUnresolvedJavaElement(FieldBinding binding, WorkingCopyOwner workingCopyOwner, Util.BindingsToNodesMap bindingsToNodes)
      Return the java element corresponding to the given compiler binding.
    • getUnresolvedJavaElement

      public static JavaElement getUnresolvedJavaElement(RecordComponentBinding binding, WorkingCopyOwner workingCopyOwner, Util.BindingsToNodesMap bindingsToNodes)
      Return the java element corresponding to the given compiler binding.
    • getUnresolvedJavaElement

      public static JavaElement getUnresolvedJavaElement(int localSourceStart, int localSourceEnd, JavaElement type)
      Returns the IInitializer that contains the given local variable in the given type
    • getUnresolvedJavaElement

      public static JavaElement getUnresolvedJavaElement(MethodBinding methodBinding, WorkingCopyOwner workingCopyOwner, Util.BindingsToNodesMap bindingsToNodes)
      Return the java element corresponding to the given compiler binding.
    • getUnresolvedJavaElement

      public static JavaElement getUnresolvedJavaElement(TypeBinding typeBinding, WorkingCopyOwner workingCopyOwner, Util.BindingsToNodesMap bindingsToNodes)
      Return the java element corresponding to the given compiler binding.
    • indexOfEnclosingPath

      public static int indexOfEnclosingPath(org.eclipse.core.runtime.IPath checkedPath, org.eclipse.core.runtime.IPath[] paths, int pathCount)
    • indexOfJavaLikeExtension

      public static int indexOfJavaLikeExtension(String fileName)
    • indexOfMatchingPath

      public static int indexOfMatchingPath(org.eclipse.core.runtime.IPath checkedPath, org.eclipse.core.runtime.IPath[] paths, int pathCount)
    • indexOfNestedPath

      public static int indexOfNestedPath(org.eclipse.core.runtime.IPath checkedPath, org.eclipse.core.runtime.IPath[] paths, int pathCount)
    • isAttributeSupported

      protected static boolean isAttributeSupported(int attribute)
      Returns whether the local file system supports accessing and modifying the given attribute.
    • isReadOnly

      public static boolean isReadOnly(org.eclipse.core.resources.IResource resource)
      Returns whether the given resource is read-only or not.
      Parameter:
      resource -
      Gibt zurück:
      true if the resource is read-only, false if it is not or if the file system does not support the read-only attribute.
    • isReadOnlySupported

      public static boolean isReadOnlySupported()
      Returns whether the local file system supports accessing and modifying the read only flag.
    • isExcluded

      public static final boolean isExcluded(IJavaElement element)
    • isExcluded

      public static final boolean isExcluded(org.eclipse.core.runtime.IPath resourcePath, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean isFolderPath)
    • isExcluded

      public static final boolean isExcluded(org.eclipse.core.resources.IResource resource, char[][] inclusionPatterns, char[][] exclusionPatterns)
    • isValidClassFileName

      public static boolean isValidClassFileName(String name, String sourceLevel, String complianceLevel)
      Validate the given .class file name. A .class file name must obey the following rules:
      • it must not be null
      • it must include the ".class" suffix
      • its prefix must be a valid identifier

      Parameter:
      name - the name of a .class file
      sourceLevel - the source level
      complianceLevel - the compliance level
      Gibt zurück:
      a status object with code IStatus.OK if the given name is valid as a .class file name, otherwise a status object indicating what is wrong with the name
    • isValidCompilationUnitName

      public static boolean isValidCompilationUnitName(String name, String sourceLevel, String complianceLevel)
      Validate the given compilation unit name. A compilation unit name must obey the following rules:
      • it must not be null
      • it must include the ".java" suffix
      • its prefix must be a valid identifier

      Parameter:
      name - the name of a compilation unit
      sourceLevel - the source level
      complianceLevel - the compliance level
      Gibt zurück:
      a status object with code IStatus.OK if the given name is valid as a compilation unit name, otherwise a status object indicating what is wrong with the name
    • isValidFolderNameForPackage

      public static boolean isValidFolderNameForPackage(String folderName, String sourceLevel, String complianceLevel)
      Returns true if the given folder name is valid for a package, false if it is not.
      Parameter:
      folderName - the name of the folder
      sourceLevel - the source level
      complianceLevel - the compliance level
    • isValidMethodSignature

      public static boolean isValidMethodSignature(String sig)
      Returns true if the given method signature is valid, false if it is not.
    • isValidTypeSignature

      public static boolean isValidTypeSignature(String sig, boolean allowVoid)
      Returns true if the given type signature is valid, false if it is not.
    • localTypeName

      public static String localTypeName(String binaryTypeName, int lastDollar, int end)
    • log

      public static void log(Throwable e, String message)
    • logRepeatedMessage

      public static void logRepeatedMessage(String key, Exception e)
      Log a message that is potentially repeated in the same session. The first time this method is called with a given exception, the exception stack trace is written to the log.

      Only intended for use in debug statements.

      Parameter:
      key - the given key
      e - the given exception
      Löst aus:
      IllegalArgumentException - if the given key is null
    • logRepeatedMessage

      public static void logRepeatedMessage(String key, int statusErrorID, String message)
    • log

      public static void log(int statusErrorID, String message)
    • log

      public static void log(org.eclipse.core.runtime.IStatus status)
    • log

      public static void log(Throwable e)
    • newClassFileReader

      public static ClassFileReader newClassFileReader(org.eclipse.core.resources.IResource resource) throws org.eclipse.core.runtime.CoreException, ClassFormatException, IOException
      Löst aus:
      org.eclipse.core.runtime.CoreException
      ClassFormatException
      IOException
    • normalizeCRs

      public static char[] normalizeCRs(char[] text, char[] buffer)
      Normalizes the cariage returns in the given text. They are all changed to use the given buffer's line separator.
    • normalizeCRs

      public static String normalizeCRs(String text, String buffer)
      Normalizes the carriage returns in the given text. They are all changed to use given buffer's line separator.
    • packageName

      public static String packageName(org.eclipse.core.runtime.IPath pkgPath, String sourceLevel, String complianceLevel)
      Converts the given relative path into a package name. Returns null if the path is not a valid package name.
      Parameter:
      pkgPath - the package path
      sourceLevel - the source level
      complianceLevel - the compliance level
    • prefixLength

      public static int prefixLength(char[] s1, char[] s2)
      Returns the length of the common prefix between s1 and s2.
    • prefixLength

      public static int prefixLength(String s1, String s2)
      Returns the length of the common prefix between s1 and s2.
    • relativePath

      public static String relativePath(org.eclipse.core.runtime.IPath fullPath, int skipSegmentCount)
      Returns the toString() of the given full path minus the first given number of segments. The returned string is always a relative path (it has no leading slash)
    • resetJavaLikeExtensions

      public static void resetJavaLikeExtensions()
    • scanTypeSignature

      public static int scanTypeSignature(char[] string, int start)
      Scans the given string for a type signature starting at the given index and returns the index of the last character.
       TypeSignature:
        |  BaseTypeSignature
        |  ArrayTypeSignature
        |  ClassTypeSignature
        |  TypeVariableSignature
       
      Parameter:
      string - the signature string
      start - the 0-based character index of the first character
      Gibt zurück:
      the 0-based character index of the last character
      Löst aus:
      IllegalArgumentException - if this is not a type signature
    • splitOn

      public static final String[] splitOn(char divider, String string, int start, int end)
      Return a new array which is the split of the given string using the given divider. The given end is exclusive and the given start is inclusive.

      For example:
      1.     divider = 'b'
            string = "abbaba"
            start = 2
            end = 5
            result => { "", "a", "" }
         
      Parameter:
      divider - the given divider
      string - the given string
      start - the given starting index
      end - the given ending index
      Gibt zurück:
      a new array which is the split of the given string using the given divider
      Löst aus:
      ArrayIndexOutOfBoundsException - if start is lower than 0 or end is greater than the array length
    • setReadOnly

      public static void setReadOnly(org.eclipse.core.resources.IResource resource, boolean readOnly)
      Sets or unsets the given resource as read-only in the file system. It's a no-op if the file system does not support the read-only attribute.
      Parameter:
      resource - The resource to set as read-only
      readOnly - true to set it to read-only, false to unset
    • sort

      public static void sort(char[][] list)
    • sort

      public static void sort(Util.Comparable[] objects)
      Sorts an array of Comparable objects in place.
    • sort

      public static void sort(int[] list)
    • sort

      public static void sort(Object[] objects, Util.Comparer comparer)
      Sorts an array of objects in place. The given comparer compares pairs of items.
    • sort

      public static void sort(String[] strings)
      Sorts an array of strings in place using quicksort.
    • sortCopy

      public static Util.Comparable[] sortCopy(Util.Comparable[] objects)
      Sorts an array of Comparable objects, returning a new array with the sorted items. The original array is left untouched.
    • sortCopy

      public static IJavaElement[] sortCopy(IJavaElement[] elements)
      Sorts an array of Java elements based on their toStringWithAncestors(), returning a new array with the sorted items. The original array is left untouched.
    • sortCopy

      public static Object[] sortCopy(Object[] objects, Util.Comparer comparer)
      Sorts an array of Strings, returning a new array with the sorted items. The original array is left untouched.
    • sortCopy

      public static String[] sortCopy(String[] objects)
      Sorts an array of Strings, returning a new array with the sorted items. The original array is left untouched.
    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(String[] compoundName, String[] prefix, boolean partialMatch)
    • toCharArrays

      public static char[][] toCharArrays(String[] a)
      Converts a String[] to char[][].
    • toCompoundChars

      public static char[][] toCompoundChars(String s)
      Converts a String to char[][], where segments are separate by '.'.
    • toLocalFile

      public static File toLocalFile(URI uri, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
      Löst aus:
      org.eclipse.core.runtime.CoreException
    • toString

      public static String toString(char[][] c)
      Converts a char[][] to String, where segments are separated by '.'.
    • toString

      public static String toString(char[][] c, char[] d)
      Converts a char[][] and a char[] to String, where segments are separated by '.'.
    • toStrings

      public static String[] toStrings(char[][] a)
    • toString

      public static String toString(char[] declaringClass, char[] methodName, char[] methodSignature, boolean includeReturnType, boolean compact)
    • typeParameterSignatures

      public static String[] typeParameterSignatures(AbstractMethodDeclaration method)
    • typeSignature

      public static String typeSignature(TypeReference type)
    • validateMethodSignature

      public static void validateMethodSignature(String sig)
      Asserts that the given method signature is valid.
    • validateTypeSignature

      public static void validateTypeSignature(String sig, boolean allowVoid)
      Asserts that the given type signature is valid.
    • isJavaLikeFileName

      public static final boolean isJavaLikeFileName(String name)
      Returns true if the given name ends with one of the known java like extension. (implementation is not creating extra strings)
    • isJavaLikeFileName

      public static final boolean isJavaLikeFileName(char[] fileName)
      Returns true if the given name ends with one of the known java like extension. (implementation is not creating extra strings)
    • getAllTypeArguments

      public static final char[][][] getAllTypeArguments(char[][] typeSignatures)
      Get all type arguments from an array of signatures. Example: For following type XUngültige Eingabe: "<"Y,V,U>.A signatures is: [ ['L','X','Ungültige Eingabe: "<"','L','Y','Ungültige Eingabe: "<"','L','Z',';'>',';','L','V','Ungültige Eingabe: "<"','L','W',';'>',';','L','U',';',>',';'], ['L','A','Ungültige Eingabe: "<"','L','B',';','>',';'] ]
      Parameter:
      typeSignatures - Array of signatures (one per each type levels)
      Gibt zurück:
      char[][][] Array of type arguments for each signature
      Löst aus:
      IllegalArgumentException - If one of provided signature is malformed
      Siehe auch:
    • getAnnotation

      public static IAnnotation getAnnotation(JavaElement parent, IBinaryAnnotation binaryAnnotation, String memberValuePairName)
    • getAnnotationMemberValue

      public static Object getAnnotationMemberValue(JavaElement parent, MemberValuePair memberValuePair, Object binaryValue)
    • getAnnotationMemberValue

      public static Object getAnnotationMemberValue(MemberValuePair memberValuePair, Constant constant)
    • getNegativeAnnotationMemberValue

      public static Object getNegativeAnnotationMemberValue(MemberValuePair memberValuePair, Constant constant)
    • splitTypeLevelsSignature

      public static final char[][] splitTypeLevelsSignature(String typeSignature)
      Split signatures of all levels from a type unique key. Example: For following type XUngültige Eingabe: "<"Y,V,U>.A, unique key is: "LXUngültige Eingabe: "<"LYUngültige Eingabe: "<"LZ;>;LVUngültige Eingabe: "<"LW;>;LU;>.LAUngültige Eingabe: "<"LB;>;" The return splitted signatures array is: [ ['L','X','Ungültige Eingabe: "<"','L','Y','Ungültige Eingabe: "<"','L','Z',';'>',';','L','V','Ungültige Eingabe: "<"','L','W',';'>',';','L','U','>',';'], ['L','A','Ungültige Eingabe: "<"','L','B',';','>',';']
      Parameter:
      typeSignature - ParameterizedSourceType type signature
      Gibt zurück:
      char[][] Array of signatures for each level of given unique key
    • toAnchor

      public static String toAnchor(int startingIndex, char[] methodSignature, String methodName, boolean isVarArgs)
    • toAnchor

      public static char[] toAnchor(int startingIndex, char[] methodSignature, char[] methodName, boolean isVargArgs)
    • fixTaskTags

      public static void fixTaskTags(Map defaultOptionsMap)
    • findMethod

      public static IMethod findMethod(IType type, char[] selector, String[] paramTypeSignatures, boolean isConstructor) throws JavaModelException
      Finds the IMethod element corresponding to the given selector, without creating a new dummy instance of a binary method.
      Parameter:
      type - the type in which the method is declared
      selector - the method name
      paramTypeSignatures - the type signatures of the method arguments
      isConstructor - whether we're looking for a constructor
      Gibt zurück:
      an IMethod if found, otherwise null
      Löst aus:
      JavaModelException