예제 #1
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch)
  */
 public void acceptSearchMatch(SearchMatch match) throws CoreException {
   IJavaElement enclosingElement = (IJavaElement) match.getElement();
   if ((enclosingElement != null) && (enclosingElement.getElementType() == IJavaElement.TYPE)) {
     // found type declaration is of one of the types we want
     if (types.contains(enclosingElement.getHandleIdentifier())) {
       // it's in a different package than the from type
       // if (!fromPackage.equals(enclosingElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT))) {
       store.add(enclosingElement.getHandleIdentifier());
       // }
     }
   }
 }
예제 #2
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleMove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.IJavaElement)
   */
  public void handleMove(RootModel root, E sourceElement, E targetElement) {
    // get all types represented in the diagram
    String scuId = sourceElement.getHandleIdentifier();
    String tcuId = targetElement.getHandleIdentifier();

    String scuName = scuId.substring(scuId.indexOf('{') + 1, scuId.indexOf(".java"));
    String tcuName = tcuId.substring(tcuId.indexOf('{') + 1, tcuId.indexOf(".java"));

    List<IJavaElement> cuTypes = root.getElementsOfKind(TYPE);

    // see if any types belong to the compilation unit
    // that is undergoing the move event
    for (IJavaElement oType : cuTypes) {
      if (JavaModelListener.sameElements(sourceElement, oType.getAncestor(COMPILATION_UNIT))) {
        String oId = oType.getHandleIdentifier();
        String oName = oId.substring(oId.indexOf('['));

        oName = oName.replaceAll("\\[" + scuName, "[" + tcuName);

        IJavaElement nType = JavaCore.create(tcuId + oName);
        TypeModel oModel = (TypeModel) root.getModelFromElement(oType);

        TypeModel nModel = root.createTypeModel((IType) nType);
        if (oModel != null) {
          // TODO We tried to catch a ResourceException,
          // but it is caught in MemberModel
          oModel.removeFromParent();
          nModel.setLocation(oModel.getLocation());
          nModel.setSize(oModel.getSize());
        }
      }
    }
  }
예제 #3
0
  @Override
  public void performApply(ILaunchConfigurationWorkingCopy config) {
    config.setAttribute(
        IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
        StringUtils.trimToEmpty(txtProject.getText()));

    try {
      List<String> stories = getStoriesFullPaths();
      config.setAttribute(ILaunchConstants.LAUNCH_ATTR_STORIES_FULL_PATH, stories);
    } catch (CoreException cex) {
      EasybLaunchActivator.Log(
          "Unable apply configuration due to exception while retrieving story locations", cex);
      setErrorMessage(
          "Unable apply configuration due to exception while retrieving story locations");
    }

    if (container != null) {
      config.setAttribute(
          ILaunchConstants.LAUNCH_ATTR_CONTAINER_HANDLE, container.getHandleIdentifier());
    }

    if (storyFile != null) {
      config.setAttribute(
          ILaunchConstants.LAUNCH_ATTR_STORY_PATH,
          storyFile.getProjectRelativePath().toPortableString());
    }

    config.setAttribute(
        ILaunchConstants.LAUNCH_ATTR_IS_SINGLE_STORY, btnRadioSingleStory.getSelection());
  }
    public ClipboardData(IJavaElement origin, String[] typeImports, String[] staticImports) {
      Assert.isNotNull(origin);
      Assert.isNotNull(typeImports);
      Assert.isNotNull(staticImports);

      fTypeImports = typeImports;
      fStaticImports = staticImports;
      fOriginHandle = origin.getHandleIdentifier();
    }
예제 #5
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch)
  */
 public void acceptSearchMatch(SearchMatch match) {
   IJavaElement enclosingElement = (IJavaElement) match.getElement();
   try {
     if ((enclosingElement != null)
         && (enclosingElement.getElementType() == IJavaElement.TYPE)) {
       String packName =
           enclosingElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT).getElementName();
       Set deps = new HashSet();
       store.put(enclosingElement.getHandleIdentifier(), deps);
       Set typesInPackage = (Set) packages.get(packName);
       if (typesInPackage == null) {
         typesInPackage = new HashSet();
         packages.put(packName, typesInPackage);
       }
       typesInPackage.add(enclosingElement.getHandleIdentifier());
     }
   } catch (Throwable e) {
     e.printStackTrace();
   }
 }
예제 #6
0
  /**
   * Compares two elements by their handle identifiers.
   *
   * @param e1 - An element to compare.
   * @param e2 - An element to compare.
   * @return True if the elements have the same handles, false otherwise.
   */
  public static boolean sameElements(IJavaElement e1, IJavaElement e2) {
    if (e1 == null || e2 == null) return false;

    return (e1.getHandleIdentifier().equals(e2.getHandleIdentifier()));
  }
 public boolean isFromSame(IJavaElement elem) {
   return fOriginHandle.equals(elem.getHandleIdentifier());
 }
예제 #8
0
 /**
  * Creates a problem for a specific reference in the workspace
  *
  * @param reference reference
  * @param associated java project (with reference source location)
  * @return problem or <code>null</code> if none
  * @exception CoreException if something goes wrong
  */
 protected IApiProblem createProblem(IReference reference, IJavaProject javaProject) {
   IProject project = javaProject.getProject();
   if (ApiPlugin.getDefault().getSeverityLevel(getSeverityKey(), project)
       == ApiPlugin.SEVERITY_IGNORE) {
     return null;
   }
   try {
     String lookupName = getTypeName(reference.getMember()).replace('$', '.');
     IType type = javaProject.findType(lookupName, new NullProgressMonitor());
     if (type == null) {
       return null;
     }
     ICompilationUnit compilationUnit = type.getCompilationUnit();
     if (compilationUnit == null) {
       return null;
     }
     IResource resource = Util.getResource(project, type);
     if (resource == null) {
       return null;
     }
     int charStart = -1;
     int charEnd = -1;
     int lineNumber = reference.getLineNumber();
     IJavaElement element = compilationUnit;
     if (!Util.isManifest(resource.getProjectRelativePath()) && !type.isBinary()) {
       IDocument document = Util.getDocument(compilationUnit);
       // retrieve line number, char start and char end
       if (lineNumber > 0) {
         lineNumber--;
       }
       // get the source range for the problem
       try {
         Position pos = getSourceRange(type, document, reference);
         if (pos != null) {
           charStart = pos.getOffset();
           if (charStart != -1) {
             charEnd = charStart + pos.getLength();
             lineNumber = document.getLineOfOffset(charStart);
           }
         }
       } catch (CoreException e) {
         ApiPlugin.log(e);
         return null;
       } catch (BadLocationException e) {
         ApiPlugin.log(e);
         return null;
       }
       if (charStart > -1) {
         element = compilationUnit.getElementAt(charStart);
       }
     }
     return ApiProblemFactory.newApiUsageProblem(
         resource.getProjectRelativePath().toPortableString(),
         type.getFullyQualifiedName(),
         getMessageArgs(reference),
         new String[] {
           IApiMarkerConstants.MARKER_ATTR_HANDLE_ID, IApiMarkerConstants.API_MARKER_ATTR_ID
         },
         new Object[] {
           (element == null
               ? compilationUnit.getHandleIdentifier()
               : element.getHandleIdentifier()),
           new Integer(IApiMarkerConstants.API_USAGE_MARKER_ID)
         },
         lineNumber,
         charStart,
         charEnd,
         getElementType(reference),
         getProblemKind(),
         getProblemFlags(reference));
   } catch (CoreException e) {
     ApiPlugin.log(e);
   }
   return null;
 }