Examples of CompilationUnit


Examples of org.eclipse.jdt.core.dom.CompilationUnit

        return markers;
    }

    List<MarkerData> generateRemovedMethodMarker(IJavaProject javaProject, final String className, final String methodName, final Delta requiresDelta) throws JavaModelException {
        final List<MarkerData> markers = new LinkedList<MarkerData>();
        final CompilationUnit ast = createAST(javaProject, className);
        ast.accept(new ASTVisitor() {
            @Override
            public boolean visit(TypeDeclaration typeDecl) {
                ITypeBinding typeBinding = typeDecl.resolveBinding();
                if (typeBinding != null) {
                    if (typeBinding.getBinaryName().equals(className)) {
                        Map<String,Object> attribs = new HashMap<String,Object>();
                        SimpleName nameNode = typeDecl.getName();
                        attribs.put(IMarker.CHAR_START, nameNode.getStartPosition());
                        attribs.put(IMarker.CHAR_END, nameNode.getStartPosition() + nameNode.getLength());

                        String message = String.format("The method '%s' was removed, which requires a %s change to the package.", methodName, requiresDelta);
                        attribs.put(IMarker.MESSAGE, message);

                        markers.add(new MarkerData(ast.getJavaElement().getResource(), attribs, false));
                        return false;
                    }
                }
                return true;
            }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

        return (CompilationUnit) parser.createAST(null);
    }

    List<MarkerData> generateAddedMethodMarker(IJavaProject javaProject, String className, final String methodName, final Delta requiresDelta) throws JavaModelException {
        final List<MarkerData> markers = new LinkedList<MarkerData>();
        final CompilationUnit ast = createAST(javaProject, className);
        ast.accept(new ASTVisitor() {
            @Override
            public boolean visit(MethodDeclaration methodDecl) {
                String signature = ASTUtil.buildMethodSignature(methodDecl);
                if (signature.equals(methodName)) {
                    // Create the marker attribs here
                    Map<String,Object> attribs = new HashMap<String,Object>();
                    attribs.put(IMarker.CHAR_START, methodDecl.getStartPosition());
                    attribs.put(IMarker.CHAR_END, methodDecl.getStartPosition() + methodDecl.getLength());

                    String message = String.format("This method was added, which requires a %s change to the package.", requiresDelta);
                    attribs.put(IMarker.MESSAGE, message);

                    markers.add(new MarkerData(ast.getJavaElement().getResource(), attribs, false));
                }

                return false;
            }
        });
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

        return markers;
    }

    List<MarkerData> generateRemovedMethodMarker(IJavaProject javaProject, final String className, final String methodName, final Delta requiresDelta) throws JavaModelException {
        final List<MarkerData> markers = new LinkedList<MarkerData>();
        final CompilationUnit ast = createAST(javaProject, className);
        ast.accept(new ASTVisitor() {
            @Override
            public boolean visit(TypeDeclaration typeDecl) {
                ITypeBinding typeBinding = typeDecl.resolveBinding();
                if (typeBinding != null) {
                    if (typeBinding.getBinaryName().equals(className)) {
                        Map<String,Object> attribs = new HashMap<String,Object>();
                        SimpleName nameNode = typeDecl.getName();
                        attribs.put(IMarker.CHAR_START, nameNode.getStartPosition());
                        attribs.put(IMarker.CHAR_END, nameNode.getStartPosition() + nameNode.getLength());

                        String message = String.format("The method '%s' was removed, which requires a %s change to the package.", methodName, requiresDelta);
                        attribs.put(IMarker.MESSAGE, message);

                        markers.add(new MarkerData(ast.getJavaElement().getResource(), attribs, false));
                        return false;
                    }
                }
                return true;
            }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

    public void analyseFile(final IFile file, final ICompilationUnit cunit, final IProgressMonitor mon)
        throws JavaModelException, CoreException
    {
      if ( cunit != null && cunit.exists() && cunit.isStructureKnown() )
      {
        CompilationUnit cu = ASTUtil.getAstOrParse(cunit, mon);

        MockASTVisitor visitor = new MockASTVisitor(cunit);
        cu.accept(visitor);

        CategorizedProblem[] probs = visitor.getProblems();
        file.deleteMarkers(MARKER, true, IResource.DEPTH_INFINITE);

        for (CategorizedProblem prob : probs) //f.recordNewProblems(probs);
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

      final ImportRewrite importRw) throws CoreException, BadLocationException
  {
    try
    {
      Document recoveredDocument = new Document();
      CompilationUnit unit = getRecoveredAST(document, offset, recoveredDocument);
      initContext(offset, importRw, unit);

      ASTNode node = NodeFinder.perform(unit, offset, 1);
      AST ast = unit.getAST();
      ASTRewrite rewrite = ASTRewrite.create(ast);

      CodeGenerationSettings settings = getCodeGenSettings();

      MethodDeclaration stub = createMockMethodStub(ast, rewrite, settings);
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

  }

  private CompilationUnit getRecoveredAST(final IDocument document, final int offset,
      final Document recoveredDocument)
  {
    CompilationUnit ast = SharedASTProvider.getAST(fCompilationUnit, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
    if (ast != null)
    {
      recoveredDocument.set(document.get());
      return ast;
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

  public final List<ICompletionProposal> computeCompletionProposals(final ContentAssistInvocationContext context,
      final IProgressMonitor mon)
  {
    ITypeBinding mockType = null, paramType = null;
    ICompilationUnit cunit = getCompilationUnit(context);
    CompilationUnit astRoot = null;

    if (cunit != null)
    {
      astRoot = ASTUtil.getAstOrParse(cunit, mon);

      if( astRoot != null )
      {
        ASTNode node = NodeFinder.perform(astRoot, context.getInvocationOffset(), 1);

        mockType = MockUtil.getMockType(node);
        paramType = findMockedTypeFromNode(node);
      }
    }

    if ( paramType != null && mockType != null )
    {
      try
      {
        return getProposals(context, paramType, cunit, mockType, astRoot.getAST());
      }
      catch (Exception e)
      {
        fErrorMessage = e.getMessage();
        Activator.log(e);
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

    return null;
  }

  public static CompilationUnit getAstOrParse(final ITypeRoot iTypeRoot, final IProgressMonitor mon)
  {
    CompilationUnit cu = SharedASTProvider.getAST(iTypeRoot, SharedASTProvider.WAIT_NO, mon);

    if( cu == null && (mon == null || !mon.isCanceled()) )
    {
      cu = parse(iTypeRoot, mon);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

    ITypeBinding paramType = null;
    IRegion wordRegion = null;
    IMethodBinding mockMethod = null, realMethod = null;

    CompilationUnit astRoot = ASTUtil.getAstOrParse(input, null);
    if( astRoot == null )
    {
      return null;
    }

    ASTNode node = NodeFinder.perform(astRoot, region.getOffset(), 1);

    if( node instanceof SimpleName && node.getParent() instanceof MethodDeclaration )
    {
      MethodDeclaration mdec = (MethodDeclaration) node.getParent();
      mockMethod = mdec.resolveBinding();

      paramType = MockUtil.findMockedType(mdec, mockMethod);

      wordRegion = new Region(node.getStartPosition(), node.getLength());

      if( paramType != null && mockMethod != null )
      {
        realMethod = MockUtil.findRealMethodInType(paramType, mockMethod, astRoot.getAST());
      }

    }

    if ( realMethod != null && wordRegion != null )
View Full Code Here

Examples of org.eclipse.jdt.core.dom.CompilationUnit

            }
            String typeDeclaration = "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$
            ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
            parser.setSource(typeDeclaration.toCharArray());
            parser.setProject(project);
            CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
            IProblem[] problems = compilationUnit.getProblems();
            if (problems.length > 0) {
                status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
                return status;
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.