List of usage examples for org.eclipse.jdt.core.compiler BuildContext recordDependencies
public void recordDependencies(String[] typeNameDependencies)
From source file:com.google.gwt.eclipse.core.validators.java.JavaCompilationParticipant.java
License:Open Source License
private void handleBuildStarting(BuildContext[] files, final IProgressMonitor monitor) { UiBinderSubtypeToOwnerIndex prebuildOwnerIndex = new UiBinderSubtypeToOwnerIndex( UiBinderReferenceManager.INSTANCE.getSubtypeToOwnerIndex()); final LinkedHashMap<ICompilationUnit, BuildContext> compilationUnitToBuildContext = new LinkedHashMap<ICompilationUnit, BuildContext>(); for (BuildContext buildContext : files) { ICompilationUnit cu = JavaCore.createCompilationUnitFrom(buildContext.getFile()); compilationUnitToBuildContext.put(cu, buildContext); }/*from w w w .j av a 2 s . co m*/ final Set<ICompilationUnit> validatedCompilationUnits = new HashSet<ICompilationUnit>(); /* * ASTBatchParser processes the ICompilationUnits in batches based on the * available memory in the system. Note that we never cache the ASTs they * are only live for the duration of the callback below. Empirically, trying * to cache all ASTs for gwt-user project results in an OOM. */ new ASTBatchParser().createASTs(compilationUnitToBuildContext.keySet().toArray(NO_UNITS), NO_STRINGS, new ASTRequestor() { @Override public void acceptAST(ICompilationUnit source, CompilationUnit ast) { BuildContext buildContext = compilationUnitToBuildContext.get(source); IFile file = buildContext.getFile(); if (monitor != null) { // Return early if this is a canceled job. Note that the AST is // still being built as there is no way to signal an abort. if (monitor.isCanceled()) { return; } // Update the progress monitor. monitor.subTask(source.getElementName()); monitor.worked(1); } try { ICompilationUnit cu = source; validatedCompilationUnits.add(cu); try { /* * Generally, the compilation unit will be consistent (the Java * Model matches the .java file on disk). However, in certain * cases, such as when the user undos a member rename * refactoring, the two are out of sync when the build starts. * In these cases, we have to explicitly reconcile the * compilation unit with its underlying resource and use the AST * we get back for validation. */ if (!cu.isConsistent()) { ast = cu.reconcile(AST.JLS4, true, null, null); assert (cu.isConsistent()); } } catch (JavaModelException e) { GWTPluginLog.logError(e); return; } // TODO: Merge this code with that of reconcile // Validate the Java AST and record any GWT problems we find JavaValidationResult result = validateCompilationUnit(ast); List<CategorizedProblem> problems = new ArrayList<CategorizedProblem>( result.getProblems()); RemoteServiceValidator rsv = new RemoteServiceValidator(); ValidationResult validationResult = rsv.validate(ast); problems.addAll(validationResult.getProblems()); ClientBundleValidator cbv = new ClientBundleValidator(); ValidationResult cbvResult = cbv.validate(ast); problems.addAll(cbvResult.getProblems()); ValidationResult uivResult; if (UiBinderConstants.UI_BINDER_ENABLED) { UiBinderJavaValidator uiv = new UiBinderJavaValidator(ast, UiBinderReferenceManager.INSTANCE.getSubtypeToOwnerIndex(), UiBinderReferenceManager.INSTANCE.getSubtypeToUiXmlIndex(), UiBinderReferenceManager.INSTANCE.getUiXmlReferencedFieldIndex(), UiBinderReferenceManager.INSTANCE.getReferenceManager()); uivResult = uiv.validate(); problems.addAll(uivResult.getProblems()); } // Record the problems buildContext.recordNewProblems(problems.toArray(EMPTY_PROBLEMS)); // Get all Java types references from JSNI blocks in this file List<String> typeDependencies = new ArrayList<String>(); for (JsniJavaRef javaRef : result.getJavaRefs()) { if (!typeDependencies.contains(javaRef.dottedClassName())) { typeDependencies.add(javaRef.dottedClassName()); } } // Add the RPC dependencies typeDependencies.addAll(validationResult.getTypeDependencies()); if (UiBinderConstants.UI_BINDER_ENABLED) { // Add the UiBinder dependencies typeDependencies.addAll(uivResult.getTypeDependencies()); } // Record the JSNI dependencies so that changing any referenced // types // will automatically trigger a rebuild of this file buildContext.recordDependencies(typeDependencies.toArray(Empty.STRINGS)); } catch (OperationCanceledException e) { // Thrown by Eclipse to abort long-running processes throw e; } catch (Exception e) { // Don't want to allow any unexpected exceptions to escape GWTPluginLog.logError(e, "Unexpected error while validating {0}", file.getName()); } } }, null); if (UiBinderConstants.UI_BINDER_ENABLED) { revalidateOwnerTypes(prebuildOwnerIndex, validatedCompilationUnits); } }