Example usage for org.eclipse.jdt.internal.core SourceType getOuterMostLocalContext

List of usage examples for org.eclipse.jdt.internal.core SourceType getOuterMostLocalContext

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core SourceType getOuterMostLocalContext.

Prototype

public Member getOuterMostLocalContext() 

Source Link

Usage

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

License:Open Source License

public MatchLocator(SearchPattern pattern, SearchRequestor requestor, IJavaSearchScope scope,
        IProgressMonitor progressMonitor) {

    this.pattern = pattern;
    this.patternLocator = PatternLocator.patternLocator(this.pattern);
    this.matchContainer = this.patternLocator == null ? 0 : this.patternLocator.matchContainer();
    this.requestor = requestor;
    this.scope = scope;
    this.progressMonitor = progressMonitor;
    if (pattern instanceof PackageDeclarationPattern) {
        this.searchPackageDeclaration = true;
    } else if (pattern instanceof OrPattern) {
        this.searchPackageDeclaration = ((OrPattern) pattern).hasPackageDeclaration();
    } else {//w  w  w . j  av a 2 s  .  c o m
        this.searchPackageDeclaration = false;
    }
    if (pattern instanceof MethodPattern) {
        IType type = ((MethodPattern) pattern).declaringType;
        if (type != null && !type.isBinary()) {
            SourceType sourceType = (SourceType) type;
            IMember local = sourceType.getOuterMostLocalContext();
            if (local instanceof IMethod) { // remember this method's range so we don't purge its statements.
                try {
                    ISourceRange range = local.getSourceRange();
                    this.sourceStartOfMethodToRetain = range.getOffset();
                    this.sourceEndOfMethodToRetain = this.sourceStartOfMethodToRetain + range.getLength() - 1; // offset is 0 based.
                } catch (JavaModelException e) {
                    // drop silently.
                }
            }
        }
    }
}

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

License:Open Source License

public char[][][] collect() throws JavaModelException {
    if (this.type != null) {
        // Collect the paths of the cus that are in the hierarchy of the given type
        this.result = new char[1][][];
        this.resultIndex = 0;
        JavaProject javaProject = (JavaProject) this.type.getJavaProject();
        this.locator.initialize(javaProject, 0);
        try {//w w  w .j  a  v  a 2s .  com
            if (this.type.isBinary()) {
                BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null);
                if (binding != null)
                    collectSuperTypeNames(binding, null);
            } else {
                ICompilationUnit unit = this.type.getCompilationUnit();
                SourceType sourceType = (SourceType) this.type;
                boolean isTopLevelOrMember = sourceType.getOuterMostLocalContext() == null;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit, isTopLevelOrMember);
                if (parsedUnit != null) {
                    TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type);
                    if (typeDecl != null && typeDecl.binding != null)
                        collectSuperTypeNames(typeDecl.binding, null);
                }
            }
        } catch (AbortCompilation e) {
            // problem with classpath: report inaccurate matches
            return null;
        }
        if (this.result.length > this.resultIndex)
            System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
        return this.result;
    }

    // Collect the paths of the cus that declare a type which matches declaringQualification + declaringSimpleName
    String[] paths = getPathsOfDeclaringType();
    if (paths == null)
        return null;

    // Create bindings from source types and binary types and collect super type names of the type declaration
    // that match the given declaring type
    Util.sort(paths); // sort by projects
    JavaProject previousProject = null;
    this.result = new char[1][][];
    this.samePackageSuperTypeName = new char[1][][];
    this.resultIndex = 0;
    for (int i = 0, length = paths.length; i < length; i++) {
        try {
            //todo Openable
            Openable openable = null;//this.locator.handleFactory.createOpenable(paths[i], this.locator.scope);
            if (openable == null)
                continue; // outside classpath

            IJavaProject project = openable.getJavaProject();
            if (!project.equals(previousProject)) {
                previousProject = (JavaProject) project;
                this.locator.initialize(previousProject, 0);
            }
            if (openable instanceof ICompilationUnit) {
                ICompilationUnit unit = (ICompilationUnit) openable;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit,
                        true /*only top level and member types are visible to the focus type*/);
                if (parsedUnit != null)
                    parsedUnit.traverse(new TypeDeclarationVisitor(), parsedUnit.scope);
            } else if (openable instanceof IClassFile) {
                IClassFile classFile = (IClassFile) openable;
                BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null);
                if (matches(binding))
                    collectSuperTypeNames(binding, binding.compoundName);
            }
        } catch (AbortCompilation e) {
            // ignore: continue with next element
        } catch (JavaModelException e) {
            // ignore: continue with next element
        }
    }
    if (this.result.length > this.resultIndex)
        System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
    return this.result;
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.SuperTypeNamesCollector.java

License:Open Source License

public char[][][] collect() throws JavaModelException {
    if (this.type != null) {
        // Collect the paths of the cus that are in the hierarchy of the given type
        this.result = new char[1][][];
        this.resultIndex = 0;
        JavaProject javaProject = (JavaProject) this.type.getJavaProject();
        this.locator.initialize(javaProject, 0);
        try {//w  ww . ja  v a 2s  . c om
            if (this.type.isBinary()) {
                BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null);
                if (binding != null)
                    collectSuperTypeNames(binding, null);
            } else {
                ICompilationUnit unit = this.type.getCompilationUnit();
                SourceType sourceType = (SourceType) this.type;
                boolean isTopLevelOrMember = sourceType.getOuterMostLocalContext() == null;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit, isTopLevelOrMember);
                if (parsedUnit != null) {
                    TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type);
                    if (typeDecl != null && typeDecl.binding != null)
                        collectSuperTypeNames(typeDecl.binding, null);
                }
            }
        } catch (AbortCompilation e) {
            // problem with classpath: report inaccurate matches
            return null;
        }
        if (this.result.length > this.resultIndex)
            System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
        return this.result;
    }

    // Collect the paths of the cus that declare a type which matches declaringQualification + declaringSimpleName
    String[] paths = getPathsOfDeclaringType();
    if (paths == null)
        return null;

    // Create bindings from source types and binary types and collect super type names of the type declaration
    // that match the given declaring type
    Util.sort(paths); // sort by projects
    JavaProject previousProject = null;
    this.result = new char[1][][];
    this.samePackageSuperTypeName = new char[1][][];
    this.resultIndex = 0;
    for (int i = 0, length = paths.length; i < length; i++) {
        try {
            Openable openable = this.locator.handleFactory.createOpenable(paths[i], this.locator.scope);
            if (openable == null)
                continue; // outside classpath

            IJavaProject project = openable.getJavaProject();
            if (!project.equals(previousProject)) {
                previousProject = (JavaProject) project;
                this.locator.initialize(previousProject, 0);
            }
            if (openable instanceof ICompilationUnit) {
                ICompilationUnit unit = (ICompilationUnit) openable;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit,
                        true /*only top level and member types are visible to the focus type*/);
                if (parsedUnit != null)
                    parsedUnit.traverse(new TypeDeclarationVisitor(), parsedUnit.scope);
            } else if (openable instanceof IClassFile) {
                IClassFile classFile = (IClassFile) openable;
                BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null);
                if (matches(binding))
                    collectSuperTypeNames(binding, binding.compoundName);
            }
        } catch (AbortCompilation e) {
            // ignore: continue with next element
        } catch (JavaModelException e) {
            // ignore: continue with next element
        }
    }
    if (this.result.length > this.resultIndex)
        System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
    return this.result;
}