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

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

Introduction

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

Prototype

public static String defaultJavaExtension() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java

License:Open Source License

public String getSourceFileName(IBinaryType info) {
    if (info == null) {
        try {/* w  w w  .j a  va 2  s. co  m*/
            info = (IBinaryType) getElementInfo();
        } catch (JavaModelException e) {
            // default to using the outer most declaring type name
            IType type = this;
            IType enclosingType = getDeclaringType();
            while (enclosingType != null) {
                type = enclosingType;
                enclosingType = type.getDeclaringType();
            }
            return type.getElementName() + Util.defaultJavaExtension();
        }
    }
    return sourceFileName(info);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java

License:Open Source License

public String sourceFileName(IBinaryType info) {
    char[] sourceFileName = info.sourceFileName();
    if (sourceFileName == null) {
        /*//w  w  w  .ja v  a 2 s.c  o  m
         * We assume that this type has been compiled from a file with its name
         * For example, A.class comes from A.java and p.A.class comes from a file A.java
         * in the folder p.
         */
        if (info.isMember()) {
            IType enclosingType = getDeclaringType();
            if (enclosingType == null)
                return null; // play it safe
            while (enclosingType.getDeclaringType() != null) {
                enclosingType = enclosingType.getDeclaringType();
            }
            return enclosingType.getElementName() + Util.defaultJavaExtension();
        } else if (info.isLocal() || info.isAnonymous()) {
            String typeQualifiedName = getTypeQualifiedName();
            int dollar = typeQualifiedName.indexOf('$');
            if (dollar == -1) {
                // malformed inner type: name doesn't contain a dollar
                return getElementName() + Util.defaultJavaExtension();
            }
            return typeQualifiedName.substring(0, dollar) + Util.defaultJavaExtension();
        } else {
            return getElementName() + Util.defaultJavaExtension();
        }
    } else {
        int index = CharOperation.lastIndexOf('/', sourceFileName);
        return new String(sourceFileName, index + 1, sourceFileName.length - index - 1);
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.SearchableEnvironment.java

License:Open Source License

/**
 * Returns the given type in the the given package if it exists,
 * otherwise <code>null</code>.
 *///from w  ww.  j  a v  a2  s  .c  o m
protected NameEnvironmentAnswer find(String typeName, String packageName) {
    if (packageName == null)
        packageName = IPackageFragment.DEFAULT_PACKAGE_NAME;
    if (this.owner != null) {
        String source = this.owner.findSource(typeName, packageName);
        if (source != null) {
            ICompilationUnit cu = new BasicCompilationUnit(source.toCharArray(),
                    CharOperation.splitOn('.', packageName.toCharArray()),
                    typeName + Util.defaultJavaExtension());
            return new NameEnvironmentAnswer(cu, null);
        }
    }
    NameLookup.Answer answer = this.nameLookup.findType(typeName, packageName, false/*exact match*/,
            NameLookup.ACCEPT_ALL, this.checkAccessRestrictions);
    if (answer != null) {
        // construct name env answer
        if (answer.type instanceof BinaryType) { // BinaryType
            try {
                return new NameEnvironmentAnswer((IBinaryType) ((BinaryType) answer.type).getElementInfo(),
                        answer.restriction);
            } catch (JavaModelException npe) {
                // fall back to using owner
            }
        } else { //SourceType
            try {
                // retrieve the requested type
                SourceTypeElementInfo sourceType = (SourceTypeElementInfo) ((SourceType) answer.type)
                        .getElementInfo();
                ISourceType topLevelType = sourceType;
                while (topLevelType.getEnclosingType() != null) {
                    topLevelType = topLevelType.getEnclosingType();
                }
                // find all siblings (other types declared in same unit, since may be used for name resolution)
                IType[] types = sourceType.getHandle().getCompilationUnit().getTypes();
                ISourceType[] sourceTypes = new ISourceType[types.length];

                // in the resulting collection, ensure the requested type is the first one
                sourceTypes[0] = sourceType;
                int length = types.length;
                for (int i = 0, index = 1; i < length; i++) {
                    ISourceType otherType = (ISourceType) ((JavaElement) types[i]).getElementInfo();
                    if (!otherType.equals(topLevelType) && index < length) // check that the index is in bounds (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=62861)
                        sourceTypes[index++] = otherType;
                }
                return new NameEnvironmentAnswer(sourceTypes, answer.restriction);
            } catch (JavaModelException jme) {
                if (jme.isDoesNotExist() && String.valueOf(TypeConstants.PACKAGE_INFO_NAME).equals(typeName)) {
                    // in case of package-info.java the type doesn't exist in the model,
                    // but the CU may still help in order to fetch package level annotations.
                    return new NameEnvironmentAnswer((ICompilationUnit) answer.type.getParent(),
                            answer.restriction);
                }
                // no usable answer
            }
        }
    }
    return null;
}