List of usage examples for org.eclipse.jdt.core.compiler BuildContext recordNewProblems
public void recordNewProblems(CategorizedProblem[] newProblems)
From source file:at.bestsolution.efxclipse.tooling.fxml.compile.FxmlAnnotationCompilationParticipant.java
License:Open Source License
@Override public void buildStarting(BuildContext[] files, boolean isBatch) { super.buildStarting(files, isBatch); for (BuildContext context : files) { List<CategorizedProblem> problems = null; try {//from w w w. j a v a2 s .c o m ICompilationUnit unit = JavaCore.createCompilationUnitFrom(context.getFile()); problems = checkCU(unit, null); context.recordNewProblems(problems.toArray(new CategorizedProblem[problems.size()])); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (problems != null) { problems.clear(); } } } }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
@Override public void acceptAST(ICompilationUnit source, CompilationUnit ast) { HashSet<IDSModel> modelSet = new HashSet<IDSModel>(); models.put(source, modelSet);// w w w . ja va 2 s . c o m HashSet<DSAnnotationProblem> problems = new HashSet<DSAnnotationProblem>(); ast.accept(new AnnotationVisitor(modelSet, errorLevel, problems)); if (!problems.isEmpty()) { char[] filename = source.getResource().getFullPath().toString().toCharArray(); for (DSAnnotationProblem problem : problems) { problem.setOriginatingFileName(filename); if (problem.getSourceStart() >= 0) problem.setSourceLineNumber(ast.getLineNumber(problem.getSourceStart())); } BuildContext buildContext = fileMap.get(source); if (buildContext != null) buildContext.recordNewProblems(problems.toArray(new CategorizedProblem[problems.size()])); } }
From source file:com.google.appengine.eclipse.core.validators.java.JavaCompilationParticipant.java
License:Open Source License
private void handleBuildStarting(BuildContext[] files, IProgressMonitor monitor) { for (BuildContext context : files) { IFile file = context.getFile();/* w w w. ja v a2 s .c om*/ 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(file.getName()); monitor.worked(1); } try { ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file); ASTNode ast = null; 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.JLS3, true, null, null); assert (cu.isConsistent()); } else { // Have JDT parse the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS3); // TODO: Note I will resolve type bindings for now, but I might // be able to simply convert SimpleNames and QualifiedNames to // fully qualified names, thereby avoiding full binding resolution. parser.setResolveBindings(true); parser.setSource(cu); ast = parser.createAST(null); } } catch (JavaModelException e) { AppEngineCorePluginLog.logError(e); continue; } // Validate the Java AST and record any problems we find List<? extends CategorizedProblem> problems = validateCompilationUnit(ast); context.recordNewProblems(problems.toArray(EMPTY_PROBLEMS)); } 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 AppEngineCorePluginLog.logError(e, "Unexpected error while validating {0}", file.getName()); } } }
From source file:com.google.gdt.eclipse.appengine.rpc.validators.JavaCompilationParticipant.java
License:Open Source License
@Override public void buildStarting(final BuildContext[] files, boolean isBatch) { for (BuildContext context : files) { IFile file = context.getFile();/* ww w .j a v a 2 s.c o m*/ try { ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file); ASTNode ast = null; IType requestContext = null; // find the requestfactory classes, once per project if (javaProject == null || javaProject.getProject() != cu.getJavaProject().getProject()) { javaProject = cu.getJavaProject(); projectEntities.clear(); proxies.clear(); requestMap.clear(); RequestFactoryUtils.findAllTypes(javaProject, projectEntities, proxies, requestMap); } // if there is no requestfactory implementation, no need to validate String name = cu.findPrimaryType().getFullyQualifiedName(); if (requestMap.containsKey(name)) { requestContext = requestMap.get(name); } if (requestContext != null) { 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.JLS3, true, null, null); assert (cu.isConsistent()); } else { // Have JDT parse the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); parser.setSource(cu); ast = parser.createAST(null); } } catch (JavaModelException e) { AppEngineRPCPlugin.log(e); continue; } // Validate the Java AST and record any problems we find RequestFactoryValidator validator = new RequestFactoryValidator(requestContext, projectEntities, proxies); List<? extends CategorizedProblem> problems = validator.validate(ast); context.recordNewProblems(problems.toArray(EMPTY_PROBLEMS)); } } catch (OperationCanceledException e) { // Thrown by Eclipse to abort long-running processes throw e; } catch (Exception e) { AppEngineRPCPlugin.getLogger().logError(e, "Unexpected error while validating {0}", file.getName()); } } }
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); }/*ww w. j a v a 2s .c o 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); } }
From source file:net.rim.ejde.internal.builders.BBCompilationParticipant.java
License:Open Source License
@Override public void buildStarting(BuildContext[] files, boolean isBatch) { // _log.debug( "*********************************** BUILD STARTING ***********************************" ); // 5 files determined experimentally to be about the difference to make batch processing worth it. boolean runBatch = isBatch && (files.length > 5); // _log.trace( "Entering BBCompilationParticipant buildStarting();Running As Batch=" + runBatch ); //$NON-NLS-1$ // long start = System.currentTimeMillis(); if (files.length > 0) { // mark this project is built by the java builder IProject project = files[0].getFile().getProject(); // remove the packaging problems try {/* ww w . j a va 2s .c o m*/ ResourceBuilderUtils.cleanProblemMarkers(project, new String[] { IRIMMarker.SIGNATURE_TOOL_PROBLEM_MARKER, IRIMMarker.PACKAGING_PROBLEM }, IResource.DEPTH_INFINITE); } catch (CoreException e) { _log.error(e.getMessage()); } PackagingJob.setBuiltByJavaBuilders(project, true); try { IJavaElement javaElem; Map<ICompilationUnit, BuildContext> buildContextMap = new HashMap<ICompilationUnit, BuildContext>(); IVMInstall vm = JavaRuntime.getVMInstall(_currentProject); if ((vm == null) || !VMUtils.isBlackBerryVM(vm)) { throw ProblemFactory.create_VM_MISSING_exception(_currentProject.getElementName()); } BBSigningKeys signingKeys = null; List<String> protectedClasses = null; boolean needParse = false; // No need to parse when there are no protected classes for (BuildContext file : files) { if (!NatureUtils.hasBBNature(file.getFile().getProject())) { continue; } // we only initialize these variables if there is any file in a BB project if ((signingKeys == null) || (protectedClasses == null)) { signingKeys = VMUtils.addSignKeysToCache(vm); protectedClasses = VMUtils.getHiddenClassesFilteredByPreferences(vm.getName()); needParse = protectedClasses.size() > 0; } IPath srcFilePath = file.getFile().getProjectRelativePath(); // For some odd reason we must remove the original pkg name or it won't be found. if (srcFilePath.segmentCount() > 1) { srcFilePath = srcFilePath.removeFirstSegments(1); } javaElem = _currentProject.findElement(srcFilePath); if ((javaElem != null) && (javaElem instanceof ICompilationUnit)) { ICompilationUnit cu = (ICompilationUnit) javaElem; CompilerToAppDescriptorManager.getInstance().onCompilationUnitCompile(cu); if (needParse) { if (runBatch) { buildContextMap.put(cu, file); } else { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); parser.setSource(cu); parser.setProject(_currentProject); CompilationUnit astRoot = (CompilationUnit) parser .createAST(new NullProgressMonitor()); BBASTVisitor visitor = new BBASTVisitor(cu, astRoot, signingKeys, protectedClasses); astRoot.accept(visitor); file.recordNewProblems(visitor.getProblems()); } } } else { // Will be the case for Resources // _log.error( "buildStarting: Error retrieving source to Parse for file " + file.getFile().getName() // ); } } if (needParse && runBatch) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); parser.setProject(_currentProject); BBASTRequestor astRequestor = new BBASTRequestor(buildContextMap, signingKeys, protectedClasses); parser.createASTs( buildContextMap.keySet().toArray(new ICompilationUnit[buildContextMap.size()]), astRequestor.getKeys(), astRequestor, new NullProgressMonitor()); } } catch (JavaModelException jme) { _log.error("buildStarting: Error Parsing for Access Restrictions", jme); } catch (CoreException ce) { _log.error("buildStarting: " + ce.getMessage()); } // long stop = System.currentTimeMillis(); // long result = stop - start; // _totalTimeParsing += result; // _log.debug( _currentProject.getElementName() + " \t " + result + " \t Total \t " + _totalTimeParsing ); // _log.debug( "*******************************************************************************" ); // _log.trace( "Leaving BBCompilationParticipant buildStarting()" ); //$NON-NLS-1$ } }
From source file:org.codehaus.jdt.groovy.internal.compiler.ScriptFolderCompilationParticipant.java
License:Open Source License
/** * Some simple checks that we can do to ensure that the builder is set up properly * //from ww w . j av a 2s . c om * @param files */ private void sanityCheckBuilder(BuildContext[] files) { // GRECLIPSE-1230 also do a check to ensure the proper compiler is being used if (!LanguageSupportFactory.isGroovyLanguageSupportInstalled()) { for (BuildContext buildContext : files) { buildContext.recordNewProblems(createProblem(buildContext)); } } // also check if this project has the JavaBuilder. // note that other builders (like the ajbuilder) may implement the CompilationParticipant API try { ICommand[] buildSpec = project.getProject().getDescription().getBuildSpec(); boolean found = false; for (ICommand command : buildSpec) { if (command.getBuilderName().equals(JavaCore.BUILDER_ID)) { found = true; break; } } if (!found) { for (BuildContext buildContext : files) { buildContext.recordNewProblems(createProblem(buildContext)); } } } catch (CoreException e) { Util.log(e); } }
From source file:org.eclipse.pde.ds.internal.annotations.AnnotationProcessor.java
License:Open Source License
@Override public void acceptAST(ICompilationUnit source, CompilationUnit ast) { // determine CU key String cuKey;/*w ww . j a va2 s . c o m*/ IJavaElement parent = source.getParent(); if (parent == null) cuKey = source.getElementName(); else cuKey = String.format("%s/%s", parent.getElementName().replace('.', '/'), source.getElementName()); //$NON-NLS-1$ context.getUnprocessed().remove(cuKey); ProjectState state = context.getState(); HashMap<String, String> dsKeys = new HashMap<>(); HashSet<DSAnnotationProblem> problems = new HashSet<>(); ast.accept(new AnnotationVisitor(this, state, dsKeys, problems)); // track abandoned files (may be garbage) Collection<String> oldDSKeys = state.updateMappings(cuKey, dsKeys); if (oldDSKeys != null) { oldDSKeys.removeAll(dsKeys.values()); context.getAbandoned().addAll(oldDSKeys); } if (!problems.isEmpty()) { char[] filename = source.getResource().getFullPath().toString().toCharArray(); for (DSAnnotationProblem problem : problems) { problem.setOriginatingFileName(filename); if (problem.getSourceStart() >= 0) problem.setSourceLineNumber(ast.getLineNumber(problem.getSourceStart())); } BuildContext buildContext = fileMap.get(source); if (buildContext != null) buildContext.recordNewProblems(problems.toArray(new CategorizedProblem[problems.size()])); } }
From source file:org.eiichiro.gig.eclipse.core.compiler.GigCompilationParticipant.java
License:Open Source License
public void buildStarting(BuildContext[] files, boolean isBatch) { for (BuildContext context : files) { IFile file = context.getFile();//from www .ja va 2 s . c o m List<GigJavaProblem> problems = validate(JavaCore.createCompilationUnitFrom(file), file.getName()); context.recordNewProblems(problems.toArray(new GigJavaProblem[problems.size()])); } }