Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.ICompilationUnit


      return methodName;
    return "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
  }

  private void revealInEditor(final IEditorPart editor, WidgetAdapter adapter) {
    ICompilationUnit unit = adapter.getCompilationUnit();
    String methodName = adapter.isRoot() ? INIT_METHOD_NAME : getGetMethodName(adapter, adapter.getID());
    String unitname = unit.getElementName();
    int dot = unitname.indexOf('.');
    if (dot != -1)
      unitname = unitname.substring(0, dot);
    IType type = unit.getType(unitname);
    IMethod method = type.getMethod(methodName, new String[0]);
    JavaUI.revealInEditor(editor, (IJavaElement) method);
  }
View Full Code Here


  }

 
  public void editCode(IEditorPart editor) {
    IFileEditorInput file = (IFileEditorInput) editor.getEditorInput();
    ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file
        .getFile());
    try {
      String name = file.getName();
      int dot = name.lastIndexOf('.');
      if (dot != -1)
        name = name.substring(0, dot);
      IType type = unit.getType(name);
      String mName = adapter.isRoot() ? INIT_METHOD_NAME
          : NamespaceUtil.getGetMethodName(adapter, adapter.getID());
      IMethod method = type.getMethod(mName, new String[0]);
      IJavaElement[] children = method.getChildren();
      for (IJavaElement javaElement : children) {
View Full Code Here

  public ICompilationUnit generate(WidgetAdapter root, IProgressMonitor monitor) {
    try {
      IParser parser = (IParser) root.getAdapter(IParser.class);
      if (parser == null)
        return null;
      ICompilationUnit unit = root.getCompilationUnit();
      ICompilationUnit copy = unit.getWorkingCopy(monitor);
      IType type = getUnitMainType(copy);
      if (type != null) {
        ImportRewrite imports = createImportRewrite(copy);
        boolean success = parser.generateCode(type, imports, monitor);
        if (!success)
          return null;
        removeRemovedComponent(root, monitor, unit, type);
        createPreferredLnf(root, monitor, type, imports);
        if (success) {
          TextEdit edit = imports.rewriteImports(monitor);
          JavaUtil.applyEdit(copy, edit, true, monitor);
        }
        if (copy.isWorkingCopy()) {
          copy.commitWorkingCopy(true, monitor);
          copy.discardWorkingCopy();
        }
        IWorkbenchPartSite site = getEditorSite();
        if (site != null) {
          OrganizeImportsAction action = new OrganizeImportsAction(site);
          action.run(unit);
View Full Code Here

        pname = pname.substring(dot + 1);
     
      String eventTypeSig = Signature.createTypeSignature(pname, false);
     
      IFileEditorInput file = (IFileEditorInput) editor.getEditorInput();
      ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file.getFile());
      String name = file.getName();
      dot = name.lastIndexOf('.');
      if (dot != -1)
        name = name.substring(0, dot);
      IType type = unit.getType(name);
      IType meType = type.getType(className);     
      IMember member = meType.getMethod(methodDesc.getName(),new String[] {eventTypeSig });
      JavaUI.revealInEditor(editor, (IJavaElement) member);
    }   
  }
View Full Code Here

    }
  }

  private void addImplInterface(IType type, String cName) {
    try {
      ICompilationUnit icunit = type.getCompilationUnit();
      String source = icunit.getBuffer().getContents();
      Document document = new Document(source);
      ASTParser parser = ASTParser.newParser(AST.JLS3);
      parser.setSource(icunit);
      CompilationUnit cunit = (CompilationUnit) parser.createAST(null);
      cunit.recordModifications();
      AST ast = cunit.getAST();
      TypeDeclaration typeDec = (TypeDeclaration) cunit.types().get(0);
      List list = typeDec.superInterfaceTypes();
      Name name = ast.newName(cName);
      Type interfaceType = ast.newSimpleType(name);
      list.add(interfaceType);
      TextEdit edits = cunit.rewrite(document, icunit.getJavaProject()
          .getOptions(true));
      edits.apply(document);
      String newSource = document.get();
      icunit.getBuffer().setContents(newSource);
    } catch (Exception e) {
      ParserPlugin.getLogger().error(e);
    }
  }
View Full Code Here

        pname = pname.substring(dot + 1);

      String eventTypeSig = Signature.createTypeSignature(pname, false);

      IFileEditorInput file = (IFileEditorInput) editor.getEditorInput();
      ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file
          .getFile());
      String name = file.getName();
      dot = name.lastIndexOf('.');
      if (dot != -1)
        name = name.substring(0, dot);
      IType type = unit.getType(name);
      IMember member = type.getMethod(methodDesc.getName(),
          new String[] { eventTypeSig });
      JavaUI.revealInEditor(editor, (IJavaElement) member);
    }
  }
View Full Code Here

    CompilationUnitEditor javaEditor = getCompilationUnitEditor();
   
    if (javaEditor == null)
      return null;
   
    ICompilationUnit compilationUnit = getCompilationUnit(javaEditor);
   
    Menu menu = new Menu(parent);
   
    ISelection selection = javaEditor.getSelectionProvider().getSelection();
   
View Full Code Here

   
    ICompilationUnit[] compilationUnits = packageFragment.getCompilationUnits();
   
    for (int i = 0; i < compilationUnits.length; i++)
    {
      ICompilationUnit compilationUnit = compilationUnits[i];
     
      accept(visitor, compilationUnit);
    }
  }
View Full Code Here

    if(compilationUnits == null)
      throw new CrystalRuntimeException("null list of compilation units");
   
    Map<ICompilationUnit, ASTNode> parsedCompilationUnits = new HashMap<ICompilationUnit, ASTNode>();
     Iterator<ICompilationUnit> iter = compilationUnits.iterator();
     ICompilationUnit compUnit = null;
     ASTParser parser = null;
     ASTNode node = null;
     for(; iter.hasNext() ;) {
       compUnit = iter.next();
        parser = ASTParser.newParser(AST.JLS3);
View Full Code Here

    List<MethodDeclaration> methodList = new LinkedList<MethodDeclaration>();
    List<MethodDeclaration> tempMethodList;
    // Get all CompilationUnits and look for MethodDeclarations in each
    Set<ICompilationUnit> compUnits = compilationUnitToASTNode.keySet();
    Iterator<ICompilationUnit> compUnitIterator = compUnits.iterator();
    ICompilationUnit icu;
    for(;compUnitIterator.hasNext();){
      icu = compUnitIterator.next();
      tempMethodList = scanForMethodDeclarationsFromAST(compilationUnitToASTNode.get(icu));
      methodList.addAll(tempMethodList);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.ICompilationUnit

Copyright © 2018 www.massapicom. 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.