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

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

Introduction

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

Prototype

public ICompilationUnit getWorkingCopy() 

Source Link

Document

Returns the working copy this context refers to.

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   www.  j  a v a 2 s . 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 {/*from ww w .ja va  2s.  co  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  ww.j a v a2s  . co m

    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 . ja  v a  2s. 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());
    }
}

From source file:jmockit.assist.JMockitCompilationParticipant.java

License:Open Source License

@Override
public void reconcile(final ReconcileContext context) {
    if (getCheckScope() == CheckScope.Disabled) {
        return;// ww w .  ja v a  2 s.  c o m
    }

    try {
        ICompilationUnit cunit = context.getWorkingCopy();

        if (cunit.isStructureKnown()) {
            MockASTVisitor visitor = new MockASTVisitor(cunit);
            context.getAST3().accept(visitor);
            CategorizedProblem[] probs = visitor.getProblems();

            if (probs.length != 0) {
                context.putProblems(probs[0].getMarkerType(), probs);
            }
        }
    } catch (JavaModelException e) {
        Activator.log(e);
    }
}

From source file:org.springframework.ide.eclipse.quickfix.jdt.AnnotationCompilationParticipant.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//w w w .  j a v a  2s  .  co m
public void reconcile(ReconcileContext context) {
    if (context.getDelta() == null) {
        return;
    }

    CompilationUnit cuAST = context.getDelta().getCompilationUnitAST();
    ICompilationUnit cu = context.getWorkingCopy();
    IFile file = (IFile) cu.getResource();

    List<MissingPathVariableWarning> problems = new ArrayList<MissingPathVariableWarning>();

    if (cuAST != null) {
        List<AbstractTypeDeclaration> typeDecls = cuAST.types();
        for (AbstractTypeDeclaration typeDecl : typeDecls) {
            List<BodyDeclaration> bodyDecls = typeDecl.bodyDeclarations();
            for (BodyDeclaration bodyDecl : bodyDecls) {
                if (bodyDecl instanceof MethodDeclaration) {
                    MethodDeclaration methodDecl = (MethodDeclaration) bodyDecl;
                    List<String> currentPathVariables = findPathVariables(methodDecl);

                    Set<Annotation> annotations = ProposalCalculatorUtil.findAnnotations("RequestMapping",
                            methodDecl);
                    for (Annotation annotation : annotations) {
                        List<UriTemplateVariable> variables = ProposalCalculatorUtil
                                .getUriTemplatVariables(annotation);
                        for (UriTemplateVariable variable : variables) {
                            boolean found = false;
                            for (String currentPathVariable : currentPathVariables) {
                                if (Pattern.matches(variable.getVariableName(), currentPathVariable)) {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found) {
                                problems.add(new MissingPathVariableWarning(annotation, variable, file,
                                        cuAST.getLineNumber(variable.getOffset())));
                            }
                        }
                    }
                }
            }

            List<String> pathVariables;
            if (context.isResolvingBindings()) {
                pathVariables = new ArrayList<String>();

                ITypeBinding typeBinding = typeDecl.resolveBinding();
                while (typeBinding != null
                        && !typeDecl.getAST().resolveWellKnownType("java.lang.Object").equals(typeBinding)) {
                    pathVariables.addAll(findPathVariables(typeBinding));
                    typeBinding = typeBinding.getSuperclass();
                }
            } else {
                pathVariables = findPathVariables(typeDecl);
            }

            Set<Annotation> annotations = ProposalCalculatorUtil.findAnnotations("RequestMapping", typeDecl);
            for (Annotation annotation : annotations) {
                List<UriTemplateVariable> variables = ProposalCalculatorUtil.getUriTemplatVariables(annotation);
                for (UriTemplateVariable variable : variables) {
                    if (!pathVariables.contains(variable.getVariableName())) {
                        problems.add(new MissingPathVariableWarning(annotation, variable, file,
                                cuAST.getLineNumber(variable.getOffset())));
                    }
                }
            }
        }
    }

    context.putProblems(MissingPathVariableWarning.MARKER_TYPE,
            problems.toArray(new CategorizedProblem[problems.size()]));
}