Example usage for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding getFileName

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding getFileName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding getFileName.

Prototype

public char[] getFileName() 

Source Link

Usage

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

License:Open Source License

public static boolean isDeclaringPackageFragment(IPackageFragment packageFragment,
        ReferenceBinding typeBinding) {
    char[] fileName = typeBinding.getFileName();
    if (fileName != null) {
        // retrieve the actual file name from the full path (sources are generally only containing it already)
        fileName = CharOperation.replaceOnCopy(fileName, '/', '\\'); // ensure to not do any side effect on file name (see https://bugs.eclipse
        // .org/bugs/show_bug.cgi?id=136016)
        fileName = CharOperation.lastSegment(fileName, '\\');

        try {//from w  w  w.jav a2s.c  o m
            switch (packageFragment.getKind()) {
            case IPackageFragmentRoot.K_SOURCE:
                if (!org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(fileName)
                        || !packageFragment.getCompilationUnit(new String(fileName)).exists()) {
                    return false; // unit doesn't live in selected package
                }
                break;
            case IPackageFragmentRoot.K_BINARY:
                //               if (Util.isJavaFileName(fileName)) { // binary with attached source
                //                  int length = fileName.length;
                //                  System.arraycopy(fileName, 0, fileName = new char[length], 0, length - 4); // copy all but extension
                //                  System.arraycopy(SuffixConstants.SUFFIX_class, 0, fileName, length - 4, 4);
                //               }
                if (!Util.isClassFileName(fileName)
                        || !packageFragment.getClassFile(new String(fileName)).exists()) {
                    return false; // classfile doesn't live in selected package
                }
                break;
            }
        } catch (JavaModelException e) {
            // unable to determine kind; tolerate this match
        }
    }
    return true; // by default, do not eliminate
}

From source file:com.google.gwt.dev.jjs.impl.BuildTypeMap.java

License:Apache License

private JDeclaredType createExternalType(String name, ReferenceBinding binding) {
    char[] chars = binding.getFileName();
    String fileName = chars == null ? "" : String.valueOf(chars);
    SourceInfo sourceInfo = SourceOrigin.create(0, fileName);
    JDeclaredType type = createType(name, sourceInfo, binding);
    typeMap.put(binding, type);//from w w  w  .  java  2s  . co  m
    return type;
}

From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java

License:Open Source License

public JDTClass(ReferenceBinding klass, IType type) {
    this.type = type;
    bindingRef = new WeakReference<ReferenceBinding>(klass);
    pkg = new JDTPackage(klass.getPackage());
    simpleName = new String(klass.sourceName());
    qualifiedName = JDTUtils.getFullyQualifiedName(klass);
    isPublic = klass.isPublic();/*from w  w  w.  jav  a2 s.  c  om*/
    isInterface = klass.isInterface();
    isAbstract = klass.isAbstract();
    isProtected = klass.isProtected();
    isDefaultAccess = klass.isDefault();
    isLocalType = klass.isLocalType();
    isStatic = (klass.modifiers & ClassFileConstants.AccStatic) != 0;
    isFinal = klass.isFinal();
    isEnum = klass.isEnum();
    isBinary = klass.isBinaryBinding();
    isAnonymous = klass.isAnonymousType();
    isJavaSource = (klass instanceof SourceTypeBinding)
            && new String(((SourceTypeBinding) klass).getFileName()).endsWith(".java");
    isAnnotationType = klass.isAnnotationType();
    bindingKey = klass.computeUniqueKey();

    char[] bindingFileName = klass.getFileName();
    int start = CharOperation.lastIndexOf('/', bindingFileName) + 1;
    if (start == 0 || start < CharOperation.lastIndexOf('\\', bindingFileName))
        start = CharOperation.lastIndexOf('\\', bindingFileName) + 1;
    fileName = new String(CharOperation.subarray(bindingFileName, start, -1));

    int jarFileEntrySeparatorIndex = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR,
            bindingFileName);
    if (jarFileEntrySeparatorIndex > 0) {
        char[] jarPart = CharOperation.subarray(bindingFileName, 0, jarFileEntrySeparatorIndex);
        IJavaElement jarPackageFragmentRoot = JavaCore.create(new String(jarPart));
        String jarPath = jarPackageFragmentRoot.getPath().toOSString();
        char[] entryPart = CharOperation.subarray(bindingFileName, jarFileEntrySeparatorIndex + 1,
                bindingFileName.length);
        fullPath = new StringBuilder(jarPath).append("!/").append(entryPart).toString();
    } else {
        fullPath = new String(bindingFileName);
    }

    ReferenceBinding sourceOrClass = klass;
    if (!klass.isBinaryBinding()) {
        sourceOrClass = klass.outermostEnclosingType();
    }
    char[] classFullName = new char[0];
    for (char[] part : sourceOrClass.compoundName) {
        classFullName = CharOperation.concat(classFullName, part, '/');
    }
    char[][] temp = CharOperation.splitOn('.', sourceOrClass.getFileName());
    String extension = temp.length > 1 ? "." + new String(temp[temp.length - 1]) : "";
    javaModelPath = new String(classFullName) + extension;

    if (type == null) {
        annotations = new HashMap<>();
        methods = Collections.emptyList();
        interfaces = Collections.emptyList();
        typeParams = Collections.emptyList();
        fields = Collections.emptyList();
        innerClasses = Collections.emptyList();
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.StateHelper.java

License:Open Source License

public static boolean isDefinitelyReadyToProcess(ReferenceBinding type, ReferenceBinding requestingSite,
        int state) {

    if (!(type instanceof SourceTypeBinding))
        return false; // most treatment not needed for binary types
    SourceTypeBinding sourceType = (SourceTypeBinding) type;

    if (TypeBinding.equalsEquals(sourceType.outermostEnclosingType().erasure(),
            requestingSite.outermostEnclosingType().erasure())
            || CharOperation.equals(type.getFileName(), requestingSite.getFileName()))
        return false; // could infinitely recurse to the same inclosing of kind

    if (!StateHelper.isReadyToProcess(sourceType, state))
        return false;

    try {//from  ww w.ja  v  a 2  s.  c o m
        StateMemento unitState = sourceType.scope.compilationUnitScope().referenceContext.state;
        if (unitState.isReadyToProcess(state))
            return true; // GOAL
    } catch (NullPointerException npe) {
        // be shy, if any enclosing thing was missing don't risk infinite recursion.
    }

    return false;
}