Example usage for org.eclipse.jdt.internal.compiler.env IBinaryType isAnonymous

List of usage examples for org.eclipse.jdt.internal.compiler.env IBinaryType isAnonymous

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.env IBinaryType isAnonymous.

Prototype

boolean isAnonymous();

Source Link

Document

Answer true if the receiver is an anonymous class.

Usage

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

License:Open Source License

public boolean isAnonymous() throws JavaModelException {
    IBinaryType info = (IBinaryType) getElementInfo();
    return info.isAnonymous();
}

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 va  2  s  .c om*/
         * 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.SourceMapper.java

License:Open Source License

/**
 * Maps the given source code to the given binary type and its children.
 * If a non-null java element is passed, finds the name range for the
 * given java element without storing it.
 */// ww  w.ja  v a  2s .c o  m
public synchronized ISourceRange mapSource(IType type, char[] contents, IBinaryType info,
        IJavaElement elementToFind) {

    this.binaryType = (BinaryType) type;

    // check whether it is already mapped
    if (this.sourceRanges.get(type) != null)
        return (elementToFind != null) ? getNameRange(elementToFind) : null;

    this.importsTable.remove(this.binaryType);
    this.importsCounterTable.remove(this.binaryType);
    this.searchedElement = elementToFind;
    this.types = new IType[1];
    this.typeDeclarationStarts = new int[1];
    this.typeNameRanges = new SourceRange[1];
    this.typeModifiers = new int[1];
    this.typeDepth = -1;
    this.memberDeclarationStart = new int[1];
    this.memberName = new String[1];
    this.memberNameRange = new SourceRange[1];
    this.methodParameterTypes = new char[1][][];
    this.methodParameterNames = new char[1][][];
    this.anonymousCounter = 0;

    HashMap oldSourceRanges = null;
    if (elementToFind != null) {
        oldSourceRanges = (HashMap) this.sourceRanges.clone();
    }
    try {
        IProblemFactory factory = new DefaultProblemFactory();
        SourceElementParser parser = null;
        this.anonymousClassName = 0;
        if (info == null) {
            try {
                info = (IBinaryType) this.binaryType.getElementInfo();
            } catch (JavaModelException e) {
                return null;
            }
        }
        boolean isAnonymousClass = info.isAnonymous();
        char[] fullName = info.getName();
        if (isAnonymousClass) {
            String eltName = this.binaryType.getParent().getElementName();
            eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length());
            try {
                this.anonymousClassName = Integer.parseInt(eltName);
            } catch (NumberFormatException e) {
                // ignore
            }
        }
        boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName);
        parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse,
                true/*optimize string literals*/);
        parser.javadocParser.checkDocComment = false; // disable javadoc parsing
        IJavaElement javaElement = this.binaryType.getCompilationUnit();
        if (javaElement == null)
            javaElement = this.binaryType.getParent();
        parser.parseCompilationUnit(
                new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement),
                doFullParse, null/*no progress*/);
        if (elementToFind != null) {
            ISourceRange range = getNameRange(elementToFind);
            return range;
        } else {
            return null;
        }
    } finally {
        if (elementToFind != null) {
            this.sourceRanges = oldSourceRanges;
        }
        this.binaryType = null;
        this.searchedElement = null;
        this.types = null;
        this.typeDeclarationStarts = null;
        this.typeNameRanges = null;
        this.typeDepth = -1;
    }
}

From source file:org.eclipse.che.jdt.BinaryTypeConvector.java

License:Open Source License

public static String toJsonBinaryType(IBinaryType type) {
    JsonObject object = new JsonObject();
    object.add("annotations", toJsonAnnotations(type.getAnnotations()));
    object.add("enclosingMethod", type.getEnclosingMethod() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.getEnclosingMethod())));
    object.add("enclosingTypeName", type.getEnclosingTypeName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.getEnclosingTypeName())));
    object.add("fields", toJsonFields(type.getFields()));
    object.add("genericSignature", type.getGenericSignature() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.getGenericSignature())));
    object.add("interfaceNames", toJsonArrayString(type.getInterfaceNames()));
    object.add("memberTypes", toJsonMemberTypes(type.getMemberTypes()));
    object.add("methods", toJsonMethods(type.getMethods()));
    object.add("missingTypeNames", toJsonMissingTypeNames(type.getMissingTypeNames()));
    object.add("name",
            type.getName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getName())));
    object.add("sourceName", type.getSourceName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.getSourceName())));
    object.add("superclassName", type.getSuperclassName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.getSuperclassName())));
    object.add("tagBits", new JsonPrimitive(String.valueOf(type.getTagBits())));
    object.add("anonymous", new JsonPrimitive(type.isAnonymous()));
    object.add("local", new JsonPrimitive(type.isLocal()));
    object.add("member", new JsonPrimitive(type.isMember()));
    object.add("sourceFileName", type.sourceFileName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.sourceFileName())));
    object.add("modifiers", new JsonPrimitive(type.getModifiers()));
    object.add("binaryType", new JsonPrimitive(type.isBinaryType()));
    object.add("fileName",
            type.getFileName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getFileName())));
    return gson.toJson(object);
}

From source file:org.eclipse.jdt.internal.core.SourceMapper.java

License:Open Source License

/**
 * Maps the given source code to the given binary type and its children.
 * If a non-null java element is passed, finds the name range for the
 * given java element without storing it.
 *///from  w  w  w.j a  v  a  2 s .  c om
public synchronized ISourceRange mapSource(IType type, char[] contents, IBinaryType info,
        IJavaElement elementToFind) {

    this.binaryType = (BinaryType) type;

    // check whether it is already mapped
    if (this.sourceRanges.get(type) != null)
        return (elementToFind != null) ? getNameRange(elementToFind) : null;

    this.importsTable.remove(this.binaryType);
    this.importsCounterTable.remove(this.binaryType);
    this.searchedElement = elementToFind;
    this.types = new IType[1];
    this.typeDeclarationStarts = new int[1];
    this.typeNameRanges = new SourceRange[1];
    this.typeModifiers = new int[1];
    this.typeDepth = -1;
    this.memberDeclarationStart = new int[1];
    this.memberName = new String[1];
    this.memberNameRange = new SourceRange[1];
    this.methodParameterTypes = new char[1][][];
    this.methodParameterNames = new char[1][][];
    this.anonymousCounter = 0;

    HashMap oldSourceRanges = null;
    if (elementToFind != null) {
        oldSourceRanges = (HashMap) this.sourceRanges.clone();
    }
    try {
        IProblemFactory factory = new DefaultProblemFactory();
        SourceElementParser parser = null;
        this.anonymousClassName = 0;
        if (info == null) {
            try {
                info = (IBinaryType) this.binaryType.getElementInfo();
            } catch (JavaModelException e) {
                return null;
            }
        }
        boolean isAnonymousClass = info.isAnonymous();
        char[] fullName = info.getName();
        if (isAnonymousClass) {
            String eltName = this.binaryType.getParent().getElementName();
            eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length());
            try {
                this.anonymousClassName = Integer.parseInt(eltName);
            } catch (NumberFormatException e) {
                // ignore
            }
        }
        boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName);
        // GROOVY start
        /* old {
        parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true/*optimize string literals..);
        } new */
        parser = LanguageSupportFactory.getSourceElementParser(this, factory, new CompilerOptions(this.options),
                doFullParse, true/*optimize string literals*/, true);
        // GROOVY end
        parser.javadocParser.checkDocComment = false; // disable javadoc parsing
        IJavaElement javaElement = this.binaryType.getCompilationUnit();
        if (javaElement == null)
            javaElement = this.binaryType.getParent();
        parser.parseCompilationUnit(
                new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement),
                doFullParse, null/*no progress*/);
        // GROOVY start
        // if this is an interesting file in an interesting project,
        // then filter out all binary members that do not have a direct
        // mapping to the source
        IProject project = javaElement.getJavaProject().getProject();
        if (LanguageSupportFactory.isInterestingProject(project)
                && LanguageSupportFactory.isInterestingSourceFile(this.binaryType.getSourceFileName(info))) {
            LanguageSupportFactory.filterNonSourceMembers(this.binaryType);
        }

        // GROOVY end
        if (elementToFind != null) {
            ISourceRange range = getNameRange(elementToFind);
            return range;
        } else {
            return null;
        }
    } finally {
        if (elementToFind != null) {
            this.sourceRanges = oldSourceRanges;
        }
        this.binaryType = null;
        this.searchedElement = null;
        this.types = null;
        this.typeDeclarationStarts = null;
        this.typeNameRanges = null;
        this.typeDepth = -1;
    }
}