Example usage for org.eclipse.jdt.core.compiler ReconcileContext getProblems

List of usage examples for org.eclipse.jdt.core.compiler ReconcileContext getProblems

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler ReconcileContext getProblems.

Prototype

public CategorizedProblem[] getProblems(String markerType) 

Source Link

Document

Returns the problems to be reported to the problem requestor of the reconcile operation for the given marker type.

Usage

From source file:at.bestsolution.efxclipse.tooling.fxml.compile.FxmlAnnotationCompilationParticipant.java

License:Open Source License

@Override
public void reconcile(final ReconcileContext context) {
    super.reconcile(context);
    List<CategorizedProblem> problems = null;
    try {/*from   w  w  w .  j  a  v a2s  . c  om*/
        List<CategorizedProblem> existingProblems = null;
        if (context.getProblems(MARKER) != null) {
            existingProblems = Arrays.asList(context.getProblems(MARKER));
        }
        problems = checkCU(context.getWorkingCopy(), existingProblems);
        context.putProblems(MARKER, 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:com.google.appengine.eclipse.core.validators.java.JavaCompilationParticipant.java

License:Open Source License

@Override
public void reconcile(ReconcileContext context) {
    ICompilationUnit cu = context.getWorkingCopy();

    try {//w w w.  j av  a 2  s  . c  o  m
        CompilationUnit ast = null;

        try {
            ast = context.getAST3();
        } catch (JavaModelException e) {
            // Fall through to null check below
        }
        if (ast == null) {
            AppEngineCorePluginLog.logError("Could not get AST for " + cu.getPath());
            return;
        }

        // Add existing Java problems to the list of all problems
        ArrayList<CategorizedProblem> finalProblemSet = new ArrayList<CategorizedProblem>();
        CategorizedProblem[] currentProblems = context.getProblems(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
        if (currentProblems != null) {
            finalProblemSet.addAll(Arrays.asList(currentProblems));
        }

        // Find and add GAE-specific problems
        List<? extends CategorizedProblem> newProblems = validateCompilationUnit(ast);
        finalProblemSet.addAll(newProblems);

        context.putProblems(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER,
                finalProblemSet.isEmpty() ? null : finalProblemSet.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}", cu.getElementName());
    }
}

From source file:com.google.gdt.eclipse.appengine.rpc.validators.JavaCompilationParticipant.java

License:Open Source License

@Override
public void reconcile(ReconcileContext context) {

    ICompilationUnit cu = context.getWorkingCopy();

    IType requestContext = null;/*from w  w w.ja va 2  s .  c  om*/

    try {
        if (!cu.isConsistent()) {
            cu.reconcile(AST.JLS3, true, null, null);
            assert (cu.isConsistent());
        }

        // 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 (cu.findPrimaryType() == null) {
            return;
        }
        if (cuName == null || !cuName.equals(cu.findPrimaryType().getFullyQualifiedName())) {
            cuName = cu.findPrimaryType().getFullyQualifiedName();

            if (requestMap.containsKey(cuName)) {
                requestContext = requestMap.get(cuName);
            } else {
                requestContext = null;
            }
            // if there is no requestfactory implementation, no need to validate
        }
        if (requestContext != null) {
            CompilationUnit ast = context.getAST3();
            ArrayList<CategorizedProblem> finalProblemSet = new ArrayList<CategorizedProblem>();
            CategorizedProblem[] currentProblems = context.getProblems(GWTJavaProblem.MARKER_ID);
            if (currentProblems != null) {
                finalProblemSet.addAll(Arrays.asList(currentProblems));
            }
            RequestFactoryValidator validator = new RequestFactoryValidator(requestContext, projectEntities,
                    proxies);
            List<CategorizedProblem> reqFactoryProblems = validator.validate(ast);
            finalProblemSet.addAll(reqFactoryProblems);
            context.putProblems(GWTJavaProblem.MARKER_ID,
                    (finalProblemSet.size() > 0 ? finalProblemSet.toArray(EMPTY_PROBLEMS) : null));
        }
    } catch (JavaModelException e) {
        AppEngineRPCPlugin.log(e);
    }
}

From source file:com.google.gwt.eclipse.core.validators.java.JavaCompilationParticipant.java

License:Open Source License

@Override
public void reconcile(ReconcileContext context) {
    ICompilationUnit cu = context.getWorkingCopy();

    try {//  w  w w.jav a2  s.  c  o m
        CompilationUnit ast = null;

        try {
            ast = context.getAST4();
        } catch (JavaModelException e) {
            // Fall through to null check below
        }
        if (ast == null) {
            GWTPluginLog.logError("Could not get AST for " + cu.getPath());
            return;
        }

        // TODO: Merge this code with that of buildStarting

        CategorizedProblem[] currentProblems = context.getProblems(GWTJavaProblem.MARKER_ID);
        // GWT-validation and error reporting
        JavaValidationResult result = validateCompilationUnit(ast);
        List<GWTJavaProblem> gwtCoreProblems = result.getProblems();
        ArrayList<CategorizedProblem> finalProblemSet = new ArrayList<CategorizedProblem>();
        if (currentProblems != null) {
            finalProblemSet.addAll(Arrays.asList(currentProblems));
        }
        finalProblemSet.addAll(gwtCoreProblems);
        context.putProblems(GWTJavaProblem.MARKER_ID,
                (finalProblemSet.size() > 0 ? finalProblemSet.toArray(EMPTY_PROBLEMS) : null));

        // GWT RPC validation and error reporting
        RemoteServiceValidator rsv = new RemoteServiceValidator();
        ValidationResult validationResult = rsv.validate(ast);
        List<CategorizedProblem> rpcProblems = validationResult.getProblems();
        context.putProblems(RemoteServiceProblem.MARKER_ID,
                (rpcProblems.size() > 0 ? rpcProblems.toArray(EMPTY_PROBLEMS) : null));

        // ClientBundle validation
        ClientBundleValidator cbv = new ClientBundleValidator();
        ValidationResult cbvResult = cbv.validate(ast);
        List<CategorizedProblem> cbProblems = cbvResult.getProblems();
        context.putProblems(ClientBundleProblem.MARKER_ID,
                (cbProblems.size() > 0 ? cbProblems.toArray(EMPTY_PROBLEMS) : null));

        if (UiBinderConstants.UI_BINDER_ENABLED) {
            /*
             * Set up the UiBinder validator. Note that we're passing in copies of
             * the subtype-to-owner and subtype-to-xml indices instead of using the
             * "real" indices (i.e. the one that we update during builds). This
             * ensures that any updates the validator makes during a reconcile are
             * only used by that reconcile pass, and are not persisted.
             */
            UiBinderJavaValidator uiv = new UiBinderJavaValidator(ast,
                    new UiBinderSubtypeToOwnerIndex(UiBinderReferenceManager.INSTANCE.getSubtypeToOwnerIndex()),
                    new UiBinderSubtypeToUiXmlIndex(UiBinderReferenceManager.INSTANCE.getSubtypeToUiXmlIndex()),
                    UiBinderReferenceManager.INSTANCE.getUiXmlReferencedFieldIndex(), null);
            ValidationResult uivResult = uiv.validate();
            List<CategorizedProblem> uivProblems = uivResult.getProblems();
            context.putProblems(UiBinderJavaProblem.MARKER_ID,
                    (uivProblems.size() > 0 ? uivProblems.toArray(EMPTY_PROBLEMS) : null));
        }
    } 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}", cu.getElementName());
    }
}