Example usage for org.eclipse.jdt.internal.core.util Util indexOfJavaLikeExtension

List of usage examples for org.eclipse.jdt.internal.core.util Util indexOfJavaLikeExtension

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util Util indexOfJavaLikeExtension.

Prototype

public static int indexOfJavaLikeExtension(String fileName) 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PossibleMatch.java

License:Open Source License

private char[] getQualifiedName() {
    if (this.openable instanceof CompilationUnit) {
        // get file name
        String fileName = this.openable.getElementName(); // working copy on a .class file may not have a resource, so use the element name
        // get main type name
        char[] mainTypeName = Util.getNameWithoutJavaLikeExtension(fileName).toCharArray();
        CompilationUnit cu = (CompilationUnit) this.openable;
        return cu.getType(new String(mainTypeName)).getFullyQualifiedName().toCharArray();
    } else if (this.openable instanceof ClassFile) {
        String fileName = getSourceFileName();
        if (fileName == NO_SOURCE_FILE_NAME)
            return ((ClassFile) this.openable).getType().getFullyQualifiedName('.').toCharArray();

        // Class file may have a source file name with ".java" extension (see bug 73784)
        int index = Util.indexOfJavaLikeExtension(fileName);
        String simpleName = index == -1 ? fileName : fileName.substring(0, index);
        PackageFragment pkg = (PackageFragment) this.openable.getParent();
        return Util.concatWith(pkg.names, simpleName, '.').toCharArray();
    }/*from w w w  .  ja  va 2s. co m*/
    return null;
}

From source file:net.sf.j2s.core.builder.SourceFile.java

License:Open Source License

String extractTypeName() {
    // answer a String with the qualified type name for the source file in the form: 'p1/p2/A'
    IPath fullPath = this.resource.getFullPath();
    int resourceSegmentCount = fullPath.segmentCount();
    int sourceFolderSegmentCount = this.sourceLocation.sourceFolder.getFullPath().segmentCount();
    int charCount = (resourceSegmentCount - sourceFolderSegmentCount - 1);
    resourceSegmentCount--; // deal with the last segment separately
    for (int i = sourceFolderSegmentCount; i < resourceSegmentCount; i++)
        charCount += fullPath.segment(i).length();
    String lastSegment = fullPath.segment(resourceSegmentCount);
    int extensionIndex = Util.indexOfJavaLikeExtension(lastSegment);
    charCount += extensionIndex;/* ww w  . j  a  v  a2 s .  com*/

    char[] result = new char[charCount];
    int offset = 0;
    for (int i = sourceFolderSegmentCount; i < resourceSegmentCount; i++) {
        String segment = fullPath.segment(i);
        int size = segment.length();
        segment.getChars(0, size, result, offset);
        offset += size;
        result[offset++] = '/';
    }
    lastSegment.getChars(0, extensionIndex, result, offset);
    return new String(result);
}

From source file:org.jboss.tools.arquillian.core.internal.compiler.SourceFile.java

License:Open Source License

String extractTypeName() {
    // answer a String with the qualified type name for the source file in
    // the form: 'p1/p2/A'
    IPath fullPath = this.resource.getFullPath();
    int resourceSegmentCount = fullPath.segmentCount();
    int sourceFolderSegmentCount = this.sourceLocation.sourceFolder.getFullPath().segmentCount();
    int charCount = (resourceSegmentCount - sourceFolderSegmentCount - 1);
    resourceSegmentCount--; // deal with the last segment separately
    for (int i = sourceFolderSegmentCount; i < resourceSegmentCount; i++)
        charCount += fullPath.segment(i).length();
    String lastSegment = fullPath.segment(resourceSegmentCount);
    int extensionIndex = Util.indexOfJavaLikeExtension(lastSegment);
    charCount += extensionIndex;//  w  w  w  .  ja  v a  2s.co  m

    char[] result = new char[charCount];
    int offset = 0;
    for (int i = sourceFolderSegmentCount; i < resourceSegmentCount; i++) {
        String segment = fullPath.segment(i);
        int size = segment.length();
        segment.getChars(0, size, result, offset);
        offset += size;
        result[offset++] = '/';
    }
    lastSegment.getChars(0, extensionIndex, result, offset);
    return new String(result);
}