/** * Create a compilation unit that can be serialized from another {@link CompilationUnit}. * * @param unit A unit to copy * @param sourceToken A valid {@DiskCache} token for this unit's source code. * @param astToken A valid {@DiskCache} token for this unit's serialized AST types. */ @SuppressWarnings("deprecation") CachedCompilationUnit(CompilationUnit unit, long sourceToken, long astToken) { assert unit != null; this.compiledClasses = unit.getCompiledClasses(); this.contentId = unit.getContentId(); this.dependencies = unit.getDependencies(); this.resourceLocation = unit.getResourceLocation(); this.resourcePath = unit.getResourcePath(); this.jsniMethods = unit.getJsniMethods(); this.lastModified = unit.getLastModified(); this.methodArgNamesLookup = unit.getMethodArgs(); this.typeName = unit.getTypeName(); this.isError = unit.isError(); this.isGenerated = unit.isGenerated(); this.isSuperSource = unit.isSuperSource(); CategorizedProblem[] problemsIn = unit.getProblems(); if (problemsIn == null) { this.problems = null; } else { this.problems = new CategorizedProblem[problemsIn.length]; for (int i = 0; i < problemsIn.length; i++) { this.problems[i] = new SerializableCategorizedProblem(problemsIn[i]); } } this.astToken = new DiskCacheToken(astToken); this.astVersion = GwtAstBuilder.getSerializationVersion(); this.sourceToken = new DiskCacheToken(sourceToken); }
private void assertProblems( String expectedProblems, String path, String source, WorkingCopyOwner owner) throws JavaModelException { this.workingCopy = getWorkingCopy(path, source); ASTParser parser = ASTParser.newParser(JLS3_INTERNAL); parser.setSource(this.workingCopy); parser.setResolveBindings(true); parser.setWorkingCopyOwner(owner); CompilationUnit cu = (CompilationUnit) parser.createAST(null); assertProblems("Unexpected problems", expectedProblems, cu.getProblems(), source.toCharArray()); }