/** Synchronize on the tern project load, tern script pats with JSDT "Include Path". */
 @Override
 public void handleEvent(IIDETernProject ternProject, LifecycleEventType eventType) {
   if (eventType != LifecycleEventType.onLoadAfter) {
     return;
   }
   // the given tern project is loading...
   IProject project = ternProject.getProject();
   if (JavaProject.hasJavaNature(project)) {
     // The project is a JSDT project.
     IJavaScriptProject jsProject = JavaScriptCore.create(project);
     // Synchronize tern script paths with JSDT "Include Path"
     synchTernScriptPaths(jsProject, ternProject);
   }
 }
  private CPListElement[] openProjectDialog(CPListElement elem) {

    try {
      ArrayList selectable = new ArrayList();
      selectable.addAll(Arrays.asList(fCurrJProject.getJavaScriptModel().getJavaScriptProjects()));
      selectable.remove(fCurrJProject);

      List elements = fProjectsList.getElements();
      for (int i = 0; i < elements.size(); i++) {
        CPListElement curr = (CPListElement) elements.get(0);
        IJavaScriptProject proj = (IJavaScriptProject) JavaScriptCore.create(curr.getResource());
        selectable.remove(proj);
      }
      Object[] selectArr = selectable.toArray();
      new JavaScriptElementComparator().sort(null, selectArr);

      ListSelectionDialog dialog =
          new ListSelectionDialog(
              getShell(),
              Arrays.asList(selectArr),
              new ArrayContentProvider(),
              new JavaUILabelProvider(),
              NewWizardMessages.ProjectsWorkbookPage_chooseProjects_message);
      dialog.setTitle(NewWizardMessages.ProjectsWorkbookPage_chooseProjects_title);
      dialog.setHelpAvailable(false);
      if (dialog.open() == Window.OK) {
        Object[] result = dialog.getResult();
        CPListElement[] cpElements = new CPListElement[result.length];
        for (int i = 0; i < result.length; i++) {
          IJavaScriptProject curr = (IJavaScriptProject) result[i];
          cpElements[i] =
              new CPListElement(
                  fCurrJProject, IIncludePathEntry.CPE_PROJECT, curr.getPath(), curr.getResource());
        }
        return cpElements;
      }
    } catch (JavaScriptModelException e) {
      return null;
    }
    return null;
  }
  /**
   * Returns the parent for the element.
   *
   * <p>Note: This method will return a working copy if the parent is a working copy. The super
   * class implementation returns the original element instead.
   */
  protected Object internalGetParent(Object element) {
    if (element instanceof IJavaScriptProject) {
      return ((IJavaScriptProject) element).getJavaScriptModel();
    }
    // try to map resources to the containing package fragment
    if (element instanceof IResource) {
      IResource parent = ((IResource) element).getParent();
      Object jParent = JavaScriptCore.create(parent);
      if (jParent != null) return jParent;
      return parent;
    }

    // for package fragments that are contained in a project package fragment
    // we have to skip the package fragment root as the parent.
    if (element instanceof IPackageFragment) {
      IPackageFragmentRoot parent = (IPackageFragmentRoot) ((IPackageFragment) element).getParent();
      return skipProjectPackageFragmentRoot(parent);
    }
    if (element instanceof IJavaScriptElement) return ((IJavaScriptElement) element).getParent();

    return null;
  }
 public JavaBrowsingContentProvider(boolean provideMembers, JavaBrowsingPart browsingPart) {
   super(provideMembers);
   fBrowsingPart = browsingPart;
   fViewer = fBrowsingPart.getViewer();
   JavaScriptCore.addElementChangedListener(this);
 }
 /* (non-Javadoc)
  * Method declared on IContentProvider.
  */
 public void dispose() {
   super.dispose();
   JavaScriptCore.removeElementChangedListener(this);
 }
 /* (non-Javadoc)
  * @see org.eclipse.ui.texteditor.IMarkerUpdater#updateMarker(org.eclipse.core.resources.IMarker, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.Position)
  */
 public boolean updateMarker(IMarker marker, IDocument document, Position position) {
   if (position.isDeleted()) {
     return false;
   }
   IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
   IBreakpoint breakpoint = manager.getBreakpoint(marker);
   if (breakpoint == null) {
     return false;
   }
   IFile file = (IFile) marker.getResource();
   if (JavaScriptCore.isJavaScriptLikeFileName(file.getName())) {
     IJavaScriptUnit unit = JavaScriptCore.createCompilationUnitFrom(file);
     if (unit == null) {
       return false;
     }
     JavaScriptUnit jsunit =
         JavaScriptPlugin.getDefault().getASTProvider().getAST(unit, ASTProvider.WAIT_YES, null);
     try {
       BreakpointLocationFinder finder =
           new BreakpointLocationFinder(
               jsunit, document.getLineOfOffset(position.getOffset()) + 1, true);
       jsunit.accept(finder);
       if (finder.getLocation() == BreakpointLocationFinder.UNKNOWN) {
         return false;
       }
       int line = finder.getLineNumber();
       if (MarkerUtilities.getLineNumber(marker) == line) {
         // if there exists a breakpoint on the line remove this one
         if (isLineBreakpoint(marker)) {
           ensureRanges(document, marker, line);
           return lineBreakpointExists(
                   marker.getResource(),
                   ((IJavaScriptLineBreakpoint) breakpoint).getScriptPath(),
                   line,
                   marker,
                   true)
               == null;
         }
         return true;
       }
       if (isLineBreakpoint(marker) & line == -1) {
         return false;
       }
       if (lineBreakpointExists(
               marker.getResource(),
               ((IJavaScriptLineBreakpoint) breakpoint).getScriptPath(),
               line,
               marker,
               false)
           != null) {
         return false;
       }
       MarkerUtilities.setLineNumber(marker, line);
       if (isLineBreakpoint(marker)) {
         ensureRanges(document, marker, line);
       }
       return true;
     } catch (BadLocationException ble) {
       JavaScriptDebugUIPlugin.log(ble);
     } catch (CoreException e) {
       JavaScriptDebugUIPlugin.log(e);
     }
   }
   return true;
 }
 /* (non-Javadoc)
  * @see org.eclipse.wst.jsdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
  */
 public IJavaScriptElement getCreatedElement() {
   return JavaScriptCore.create(fFirstPage.getProjectHandle());
 }
  /* package */ static UserLibrary createFromString(Reader reader) throws IOException {
    Element cpElement;
    try {
      DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
    } catch (SAXException e) {
      throw new IOException(Messages.file_badFormat);
    } catch (ParserConfigurationException e) {
      throw new IOException(Messages.file_badFormat);
    } finally {
      reader.close();
    }

    if (!cpElement.getNodeName().equalsIgnoreCase(TAG_USERLIBRARY)) {
      throw new IOException(Messages.file_badFormat);
    }
    // String version= cpElement.getAttribute(TAG_VERSION);
    // in case we update the format: add code to read older versions

    boolean isSystem = Boolean.valueOf(cpElement.getAttribute(TAG_SYSTEMLIBRARY)).booleanValue();

    NodeList list = cpElement.getChildNodes();
    int length = list.getLength();

    ArrayList res = new ArrayList(length);
    for (int i = 0; i < length; ++i) {
      Node node = list.item(i);

      if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        if (element.getNodeName().equals(TAG_ARCHIVE)) {
          String path = element.getAttribute(TAG_PATH);
          IPath sourceAttach =
              element.hasAttribute(TAG_SOURCEATTACHMENT)
                  ? new Path(element.getAttribute(TAG_SOURCEATTACHMENT))
                  : null;
          IPath sourceAttachRoot =
              element.hasAttribute(TAG_SOURCEATTACHMENTROOT)
                  ? new Path(element.getAttribute(TAG_SOURCEATTACHMENTROOT))
                  : null;
          NodeList children = element.getElementsByTagName("*"); // $NON-NLS-1$
          boolean[] foundChildren = new boolean[children.getLength()];
          NodeList attributeList =
              ClasspathEntry.getChildAttributes(
                  ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren);
          IIncludePathAttribute[] extraAttributes =
              ClasspathEntry.decodeExtraAttributes(attributeList);
          attributeList =
              ClasspathEntry.getChildAttributes(
                  ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren);
          IAccessRule[] accessRules = ClasspathEntry.decodeAccessRules(attributeList);
          IIncludePathEntry entry =
              JavaScriptCore.newLibraryEntry(
                  new Path(path),
                  sourceAttach,
                  sourceAttachRoot,
                  accessRules,
                  extraAttributes,
                  false /*not exported*/);
          res.add(entry);
        }
      }
    }

    IIncludePathEntry[] entries =
        (IIncludePathEntry[]) res.toArray(new IIncludePathEntry[res.size()]);

    return new UserLibrary(entries, isSystem);
  }
 public void shutdown() {
   JavaScriptCore.removeElementChangedListener(this);
   TernCorePlugin.removeTernProjectLifeCycleListener(this);
 }
예제 #10
0
 public void startup() {
   JavaScriptCore.addElementChangedListener(this, ElementChangedEvent.POST_CHANGE);
   TernCorePlugin.addTernProjectLifeCycleListener(this);
 }