Example usage for org.eclipse.jdt.internal.compiler.lookup CompilationUnitScope CompilationUnitScope

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

Introduction

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

Prototype

public CompilationUnitScope(CompilationUnitDeclaration unit, CompilerOptions compilerOptions) 

Source Link

Usage

From source file:com.google.gwt.dev.javac.BinaryTypeReferenceRestrictionsCheckerTest.java

License:Apache License

/**
 * Creates a mock {@link CompilationUnitDeclaration} that has binary type
 * references in a superclass reference, in a method return type, in an
 * annotation and in a local variable declaration. It then checks that the we
 * find all of these locations except for the one used in an annotation.
 *///  w  ww  .  j  a  v  a 2  s  . c o  m
public void testFindAllBinaryTypeReferenceSites() {
    CompilationResult compilationResult = new CompilationResult("TestCompilationUnit.java".toCharArray(), 0, 0,
            0);
    CompilationUnitDeclaration cud = new CompilationUnitDeclaration(null, compilationResult, 1);
    LookupEnvironment lookupEnvironment = createMockLookupEnvironment();
    cud.scope = new CompilationUnitScope(cud, lookupEnvironment);

    TypeDeclaration typeDeclaration = new TypeDeclaration(compilationResult);
    typeDeclaration.scope = new ClassScope(cud.scope, null);
    typeDeclaration.staticInitializerScope = new MethodScope(typeDeclaration.scope, null, false);
    cud.types = new TypeDeclaration[] { typeDeclaration };

    BinaryTypeBinding binaryTypeBinding = new BinaryTypeBinding(null, new MockBinaryType(BINARY_TYPE_NAME),
            lookupEnvironment);
    typeDeclaration.superclass = createMockBinaryTypeReference(binaryTypeBinding);

    MethodDeclaration methodDeclaration = new MethodDeclaration(compilationResult);
    methodDeclaration.scope = new MethodScope(typeDeclaration.scope, null, false);
    methodDeclaration.returnType = createMockBinaryTypeReference(binaryTypeBinding);

    LocalDeclaration localDeclaration = new LocalDeclaration(null, 0, 0);
    localDeclaration.type = createMockBinaryTypeReference(binaryTypeBinding);
    methodDeclaration.statements = new Statement[] { localDeclaration };

    SingleMemberAnnotation annotation = new SingleMemberAnnotation(
            createMockBinaryTypeReference(binaryTypeBinding), 0);
    annotation.memberValue = annotation.type;
    typeDeclaration.annotations = new Annotation[] { annotation };

    typeDeclaration.methods = new AbstractMethodDeclaration[] { methodDeclaration };

    /*
     * Check that we find binary type references in the following expected
     * locations.
     */
    Expression[] expectedExpressions = new Expression[] { typeDeclaration.superclass,
            methodDeclaration.returnType, localDeclaration.type };

    List<BinaryTypeReferenceSite> binaryTypeReferenceSites = BinaryTypeReferenceRestrictionsChecker
            .findAllBinaryTypeReferenceSites(cud);
    assertEquals(expectedExpressions.length, binaryTypeReferenceSites.size());
    for (int i = 0; i < binaryTypeReferenceSites.size(); ++i) {
        BinaryTypeReferenceSite binaryTypeReferenceSite = binaryTypeReferenceSites.get(i);
        assertSame(binaryTypeBinding, binaryTypeReferenceSite.getBinaryTypeBinding());
        assertSame(expectedExpressions[i], binaryTypeReferenceSite.getExpression());
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.OTClassScope.java

License:Open Source License

public void checkAndSetBaseImports(LookupEnvironment env, ImportReference[] references,
        ImportBinding[] resolvedBaseImports) {
    // TODO what checks need to be performed??
    // TODO: support base class decapsulation for base imports!
    // TODO: perhaps we should not report name class between a role's name and its base-imported
    //       baseclass??
    ImportReference currentPackage = referenceCompilationUnit().currentPackage;
    if (currentPackage != null && currentPackage.isTeam()) {
        for (ImportReference reference : references)
            if (reference != null)
                problemReporter().baseImportInRoleFile(reference);
        return;//www .j a  v  a  2 s.co  m
    }
    CompilationUnitDeclaration cud = new CompilationUnitDeclaration(problemReporter(),
            this.referenceContext.compilationResult, 0);
    cud.currentPackage = currentPackage;
    this.baseImportScope = new CompilationUnitScope(cud, env);
    this.baseImportScope.imports = resolvedBaseImports;
    this.baseImportScope.fPackage = compilationUnitScope().fPackage;
    this.baseImportScope.topLevelTypes = new SourceTypeBinding[0];
}