Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IJavaElement


    String packageName = "";
    IEditorInput editorInput = editor.textEditor.getEditorInput();
   
    ITextSelection selection = (ITextSelection) editor.textEditor.getSelectionProvider().getSelection();
    IJavaElement elem = JavaUI.getEditorInputJavaElement(editorInput);
    ICompilationUnit unit = null;
    if (elem instanceof ICompilationUnit) {
      unit = (ICompilationUnit) elem;
      try {
        IPackageDeclaration[] packs = unit.getPackageDeclarations();
        if (packs.length < 1) {
          info("This action can only apply to controllers.");
          return null;
        } else {
          packageName = packs[0].getElementName();
          if (!packageName.startsWith("controllers")) {
            info("This action can only apply to controllers.");
            return null;
          }
        }
       
        // get the class declaration line
        IType type = unit.getType(controllerName);
        ITypeHierarchy superTypes = type.newSupertypeHierarchy(null);
//        String name = JapidController.class.getName(); // this will require play.jar
        String name = "cn.bran.play.JapidController";
        IType japidController = jProject.findType(name);
        if (superTypes.contains(japidController)) {
          useJapid = true;
        }
        else {
          useJapid = false;
        }
       
//        String superclassName = type.getSuperclassName();
//        if (superclassName.toLowerCase().contains("japid")) {
//          useJapid = true;
//        }
       
        // current selected elem
            IJavaElement[] elements= unit.codeSelect(selection.getOffset(), selection.getLength());
            if (elements.length > 0) {
              // TODO extract the current selection to tell if the cursor in on renderJapidXXX line
              System.out.println(elements);
            }

      } catch (JavaModelException e) {
        e.printStackTrace();
      }
    } else {
      System.out.println(elem.getElementType() + ":" + elem.getElementName());
    }

    viewName = getEnclosingActionName(selection, unit);

    int lineNo = editor.getCurrentLineNo();
View Full Code Here


  /**
   * @param selection
   * @param unit
   */
  private String getEnclosingActionName(ITextSelection selection, ICompilationUnit unit) {
    IJavaElement selected;
    try {
      selected = unit.getElementAt(selection.getOffset());
      List<IJavaElement> path = getJavaElementsPath(selected);
      if (path.size() >= 7) {
        IJavaElement el = path.get(6);
        if (el.getElementType() == IJavaElement.METHOD) {
          IMethod sm = (IMethod)el;
          int flags = sm.getFlags();
          String actionMethodName = el.getElementName();
          if (/*Flags.isPublic(flags) &&*/ Flags.isStatic(flags)) {
            return actionMethodName;
          }
          else {
            info("The enclosig method " + actionMethodName + " is not public static, thus not a valid action method.");
View Full Code Here

    return null;
  }
 
  static void printAstPath(IJavaElement elem) {
    System.out.println(elem.getClass() + ":" + elem.getElementType() + ":" + elem.getElementName());
    IJavaElement parent = elem.getParent();
    if (parent != null) {
      printAstPath(parent);
    }
  }
View Full Code Here

  }


  static void printAstPath(IJavaElement elem) {
    System.out.println(elem.getClass() + ":" + elem.getElementType() + ":" + elem.getElementName());
    IJavaElement parent = elem.getParent();
    if (parent != null) {
      printAstPath(parent);
    }
  }
View Full Code Here

      for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it.hasNext();) {
        Object element = it.next();
        if (element instanceof IProject) {
          project = (IProject) element;
        } else if (element instanceof IJavaElement) {
          IJavaElement res = (IJavaElement) element;
          project = res.getJavaProject().getProject();
          break;
        } else if (element instanceof IResource) {
          IResource res = (IResource) element;
          project = res.getProject();
          break;
        } else if (element instanceof IAdaptable) {
          project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
        }
      }
View Full Code Here

    boolean res = hasTypeAddedOrRemoved(event.getDelta());
   
  }

  private boolean hasTypeAddedOrRemoved(IJavaElementDelta delta) {
    IJavaElement elem = delta.getElement();
    int kind = delta.getKind();
//    boolean changed = false;
//    boolean added = false;
//    boolean removed = false;
//    if (kind == IJavaElementDelta.CHANGED)
//      changed = true;
//    else if (kind == IJavaElementDelta.ADDED)
//      added = true;
//    else if (kind == IJavaElementDelta.REMOVED)
//      removed = true;
   
   
    boolean isAddedOrRemoved = (kind != IJavaElementDelta.CHANGED);
   
    switch(elem.getElementType()) {
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
        if (isAddedOrRemoved)
View Full Code Here

    String packageName = "";
    IEditorInput editorInput = editor.textEditor.getEditorInput();
   
    ITextSelection selection = (ITextSelection) editor.textEditor.getSelectionProvider().getSelection();
    IJavaElement elem = JavaUI.getEditorInputJavaElement(editorInput);
    ICompilationUnit unit = null;
    if (elem instanceof ICompilationUnit) {
      unit = (ICompilationUnit) elem;
      try {
        IPackageDeclaration[] packs = unit.getPackageDeclarations();
        if (packs.length < 1) {
          info("This action can only apply to controllers.");
          return null;
        } else {
          packageName = packs[0].getElementName();
          if (!packageName.startsWith("controllers")) {
            info("This action can only apply to controllers.");
            return null;
          }
        }
       
//        // get the class declaration line
//        IType type = unit.getType(controllerName);
//        ITypeHierarchy superTypes = type.newSupertypeHierarchy(null);
////        String name = JapidController.class.getName(); // this will require play.jar
//        String name = "cn.bran.play.JapidController";
//        IType japidController = jProject.findType(name);
//       
        // current selected elem
            IJavaElement[] elements= unit.codeSelect(selection.getOffset(), selection.getLength());
            if (elements.length > 0) {
              // TODO extract the current selection to tell if the cursor in on renderJapidXXX line
//              System.out.println(elements);
            }

      } catch (JavaModelException e) {
        e.printStackTrace();
      }
    } else {
      System.out.println(elem.getElementType() + ":" + elem.getElementName());
    }

    viewName = getEnclosingActionName(selection, unit);
   
    if (viewName == null) {
View Full Code Here

  /**
   * @param selection
   * @param unit
   */
  private String getEnclosingActionName(ITextSelection selection, ICompilationUnit unit) {
    IJavaElement selected;
    try {
      selected = unit.getElementAt(selection.getOffset());
      List<IJavaElement> path = getJavaElementsPath(selected);
      if (path.size() >= 7) {
        IJavaElement el = path.get(6);
        if (el.getElementType() == IJavaElement.METHOD) {
          IMethod sm = (IMethod)el;
          int flags = sm.getFlags();
          String actionMethodName = el.getElementName();
          if (Flags.isPublic(flags) && Flags.isStatic(flags)) {
            return actionMethodName;
          }
          else {
            info("The enclosig method " + actionMethodName + " is not public static, thus not a valid action method.");
View Full Code Here

    return null;
  }
 
  static void printAstPath(IJavaElement elem) {
    System.out.println(elem.getClass() + ":" + elem.getElementType() + ":" + elem.getElementName());
    IJavaElement parent = elem.getParent();
    if (parent != null) {
      printAstPath(parent);
    }
  }
View Full Code Here

    private void elementChanged(IJavaElementDelta delta, boolean forceUpdate) {
      if (frameworkIsShuttingDown())
        return;

      IJavaElement element = delta.getElement();
      if (element.getElementType() == IJavaElement.JAVA_MODEL) {
        IJavaElementDelta[] changed = delta.getAffectedChildren();
        for (int i = 0; i < changed.length; i++) {
          elementChanged(changed[i], forceUpdate);
        }
      }
      // Handle any changes at the project level
      else if (element.getElementType() == IJavaElement.JAVA_PROJECT) {
        if ((delta.getFlags() & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) {
          IJavaElement proj = element;
          handleClasspathChange((IJavaProject) proj, delta, forceUpdate);
        }
        else {
          IJavaElementDelta[] deltas = delta.getAffectedChildren();
          if (deltas.length == 0) {
            if (delta.getKind() == IJavaElementDelta.REMOVED || (delta.getFlags() & IJavaElementDelta.F_CLOSED) != 0) {
              /*
               * If the project is being deleted or closed, just
               * remove the description
               */
              IJavaProject proj = (IJavaProject) element;
              ProjectDescription description = (ProjectDescription) fProjectDescriptions.remove(proj.getProject());
              if (description != null) {
                if (_debugIndexCreation) {
                  Logger.log(Logger.INFO, "removing index of " + description.fProject.getName()); //$NON-NLS-1$
                }
                // removing the index file ensures that we
                // don't get stale data if the project is
                // reopened
                removeIndexFile(proj.getProject());
              }
            }
          }
          /*
           * (else) Without the classpath changing, there's nothing
View Full Code Here

TOP

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

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.