List of usage examples for org.eclipse.jdt.internal.compiler.lookup ClassScope ClassScope
public ClassScope(Scope parent, TypeDeclaration context)
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 a2 s. co 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.ajdt.core.parserbridge.ITDInserter.java
License:Open Source License
private TypeDeclaration createITIT(String name, TypeDeclaration enclosing) { TypeDeclaration decl = new TypeDeclaration(enclosing.compilationResult); decl.enclosingType = enclosing;/*from ww w . j a v a 2 s . c o m*/ decl.name = name.toCharArray(); ClassScope innerClassScope = new ClassScope(enclosing.scope, decl); decl.binding = new MemberTypeBinding(new char[][] { enclosing.name, name.toCharArray() }, innerClassScope, enclosing.binding); decl.staticInitializerScope = enclosing.staticInitializerScope; decl.initializerScope = enclosing.initializerScope; decl.scope = innerClassScope; decl.binding.superInterfaces = new ReferenceBinding[0]; decl.binding.typeVariables = new TypeVariableBinding[0]; decl.binding.memberTypes = new ReferenceBinding[0]; decl.modifiers = Flags.AccPublic | Flags.AccStatic; decl.binding.modifiers = decl.modifiers; // also set the bindings, but may have to unset them as well. ReferenceBinding[] newBindings = new ReferenceBinding[enclosing.binding.memberTypes.length + 1]; System.arraycopy(enclosing.binding.memberTypes, 0, newBindings, 0, enclosing.binding.memberTypes.length); newBindings[enclosing.binding.memberTypes.length] = decl.binding; enclosing.binding.memberTypes = newBindings; return decl; }