public void setConditionWithEnable(boolean enabled, String condition) throws CoreException {
   fCondition = condition;
   IMarker marker = getMarker();
   marker.setAttribute(IPHPDebugConstants.Condition, condition);
   fConditionEnabled = enabled;
   marker.setAttribute(IPHPDebugConstants.ConditionEnabled, new Boolean(enabled));
   int lineNumber = ((Integer) marker.getAttribute(IMarker.LINE_NUMBER)).intValue();
   if (enabled) {
     String message =
         MessageFormat.format(
             PHPDebugCoreMessages.ConditionalBreakPointMessage_1,
             new String[] {marker.getResource().getName(), Integer.toString(lineNumber)});
     message +=
         MessageFormat.format(
             PHPDebugCoreMessages.ConditionalBreakPointMessage_2, new String[] {condition});
     marker.setAttribute(IMarker.MESSAGE, message);
   } else {
     marker.setAttribute(
         IMarker.MESSAGE,
         MessageFormat.format(
             PHPDebugCoreMessages.LineBreakPointMessage_1,
             new String[] {marker.getResource().getName(), Integer.toString(lineNumber)}));
   }
   addConditionToBP();
   setConditionChanged(true);
 }
  /** @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object) */
  public IEditorInput getEditorInput(Object element) {
    IStorageEditorInput i;
    AtlStackFrame frame;
    //		String projectName;
    String fileName;

    if (element instanceof AtlStackFrame) {
      frame = (AtlStackFrame) element;
      if (((AtlDebugTarget) frame.getDebugTarget()).isDisassemblyMode())
        return getDisassemblyEditorInput(frame);
      ILaunchConfiguration configuration =
          frame.getDebugTarget().getLaunch().getLaunchConfiguration();
      try {
        // TODO Recuperer le nom du fichier sur la stackframe
        fileName =
            configuration.getAttribute(
                AtlLauncherTools.ATLFILENAME, AtlLauncherTools.NULLPARAMETER);

        IWorkspace wks = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot wksroot = wks.getRoot();

        i = new FileEditorInput(wksroot.getFile(new Path(fileName)));
        return i;
      } catch (CoreException e) {
        e.printStackTrace();
      }
    } else if (element instanceof AtlBreakpoint) {
      IMarker marker = ((AtlBreakpoint) element).getMarker();
      IFile ifile = (IFile) marker.getResource();
      return new FileEditorInput(ifile);
    }
    return null;
  }
 /**
  * Looks up the {@link IJavaScriptLineBreakpoint} that is associated with the given marker.
  * Returns <code>null</code> if one does not exist
  *
  * @param resource
  * @param typeName
  * @param lineNumber
  * @param currentmarker
  * @param useid if the id of the markers should be compared
  * @return the {@link IJavaScriptLineBreakpoint} for the given marker or <code>null</code> if one
  *     does not exist
  * @throws CoreException
  */
 IJavaScriptLineBreakpoint lineBreakpointExists(
     IResource resource, String typeName, int lineNumber, IMarker currentmarker, boolean useid)
     throws CoreException {
   String modelId = JavaScriptDebugModel.MODEL_ID;
   IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
   IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
   for (int i = 0; i < breakpoints.length; i++) {
     if ((breakpoints[i] instanceof IJavaScriptLineBreakpoint)) {
       IJavaScriptLineBreakpoint breakpoint = (IJavaScriptLineBreakpoint) breakpoints[i];
       if (breakpoint.getLineNumber() == lineNumber) {
         IMarker marker = breakpoint.getMarker();
         if (marker != null
             && marker.exists()
             && marker.getType().equals(IJavaScriptLineBreakpoint.MARKER_ID)
             && pathsEqual(breakpoint.getScriptPath(), typeName)
             && resource.equals(marker.getResource())) {
           if (useid) {
             if (currentmarker.getId() != marker.getId()) {
               return breakpoint;
             }
             return null;
           }
           return breakpoint;
         }
       }
     }
   }
   return null;
 }
 public void apply(final IDocument document) {
   IProject p = marker.getResource().getProject();
   IFile f = BuildWrapperPlugin.getCabalFile(p);
   IDocumentProvider prov = new TextFileDocumentProvider();
   try {
     prov.connect(f);
     IDocument doc = prov.getDocument(f);
     PackageDescription pd = PackageDescriptionLoader.load(f);
     int length = pd.getStanzas().size();
     for (int a = 0; a < length; a++) {
       PackageDescriptionStanza pds = pd.getStanzas().get(a);
       CabalSyntax cs = pds.getType();
       if (CabalSyntax.SECTION_EXECUTABLE.equals(cs)
           || CabalSyntax.SECTION_LIBRARY.equals(cs)
           || CabalSyntax.SECTION_TESTSUITE.equals(cs)) {
         RealValuePosition rvp = pds.addToPropertyList(CabalSyntax.FIELD_BUILD_DEPENDS, pkg);
         if (rvp != null) {
           rvp.updateDocument(doc);
           pd = PackageDescriptionLoader.load(doc.get());
         }
       }
     }
     prov.saveDocument(new NullProgressMonitor(), f, doc, true);
   } catch (CoreException ce) {
     HaskellUIPlugin.log(ce);
   }
 }
Ejemplo n.º 5
0
  private void openSelectedMarker() {
    ISelection sel = tableViewer.getSelection();

    if (sel instanceof IStructuredSelection) {
      Object element = ((IStructuredSelection) sel).getFirstElement();

      if (element instanceof IMarker) {
        IMarker marker = (IMarker) element;

        if (marker.getResource() instanceof IFile) {
          try {
            IDE.openEditor(getViewSite().getPage(), marker);
          } catch (PartInitException e) {
            ErrorDialog.openError(
                getSite().getShell(),
                "Error Opening Marker",
                "Unable to open an editor for the given marker: " + e.getClass().getSimpleName(),
                new Status(IStatus.ERROR, DartToolsPlugin.PLUGIN_ID, e.toString(), e));

            DartToolsPlugin.log(e);
          }
        }
      }
    }
  }
  @Override
  public ICompletionProposal getCompletionProposal(final IMarker marker, final IDocument document) {
    String msg = marker.getAttribute(IMarker.MESSAGE, ""); // $NON-NLS-1$
    String toSearch = GhcMessages.WARNING_INFERREDTYPE_START;
    int ix = msg.toLowerCase().indexOf(toSearch);
    String type = msg.substring(ix + toSearch.length()).trim();

    int line = marker.getAttribute(IMarker.LINE_NUMBER, 0);
    try {

      int offset = document.getLineOffset(line - 1);
      String txt = type + PlatformUtil.NL;
      return new CompletionProposal(
          getLineStartAddition(txt, marker.getResource()),
          offset,
          0,
          offset + txt.length(),
          HaskellUIImages.getImage(IImageNames.TYPE_SIGNATURE),
          getLabel(),
          null,
          null);
      // doc.replace( offset, 0, type+NL );

    } catch (BadLocationException ex) {
      HaskellUIPlugin.log(ex);
    }
    return null;
  }
 private static ICompilationUnit getCompilationUnit(IMarker marker) {
   IResource res = marker.getResource();
   if (res instanceof IFile && res.isAccessible()) {
     IJavaElement element = JavaCore.create((IFile) res);
     if (element instanceof ICompilationUnit) return (ICompilationUnit) element;
   }
   return null;
 }
 private static CompilationUnit getCompilationUnit(IMarker marker) {
   IResource res = marker.getResource();
   if (res instanceof IFile && res.isAccessible()) {
     DartElement element = DartCore.create((IFile) res);
     if (element instanceof CompilationUnit) {
       return (CompilationUnit) element;
     }
   }
   return null;
 }
 private boolean isNeedToCreate(IMarker marker) {
   String message = marker.getAttribute(IMarker.MESSAGE, "");
   String attribute = marker.getAttribute(ATTRIBUTE_NAME, "");
   if (attribute.equals(VALIDATOR_ID)
       && marker.getResource() instanceof IFile
       && message.endsWith(MESSAGE)) {
     return true;
   }
   return false;
 }
  public static boolean canHandle(final IMarker marker) {
    final int code = marker.getAttribute(IMarker.PROBLEM, 0);
    final String sourceId = marker.getAttribute(IMarker.SOURCE_ID, "");

    if (marker.getResource().getName().endsWith(SpdPackage.FILE_EXTENSION)
        && code == EventPortConstraint.STATUS_CODE
        && sourceId.equals(EventPortConstraint.SOURCE_ID)) {
      return true;
    }
    return false;
  }
Ejemplo n.º 11
0
 /**
  * Gets a string representation of marker
  *
  * @param marker The marker instance
  * @return Readable description of the marker
  */
 @SuppressWarnings("unchecked")
 protected String getDescription(IMarker marker) {
   try {
     HashMap<String, Object> map = new HashMap<String, Object>();
     map.put("resource", marker.getResource().getName());
     map.put("type", marker.getType());
     map.put("attributes", new HashMap<String, Object>(marker.getAttributes()).toString());
     return map.toString();
   } catch (CoreException e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 12
0
 /* (non-Javadoc)
  * @see org.eclipse.debug.core.model.Breakpoint#setMarker(org.eclipse.core.resources.IMarker)
  */
 @Override
 public void setMarker(IMarker marker) throws CoreException {
   super.setMarker(marker);
   this.projectName =
       marker.getAttribute(ICamelDebugConstants.MARKER_ATTRIBUTE_PROJECTNAME, this.projectName);
   this.endpointNodeId =
       marker.getAttribute(ICamelDebugConstants.MARKER_ATTRIBUTE_ENDPOINTID, this.endpointNodeId);
   this.fileName =
       marker.getAttribute(ICamelDebugConstants.MARKER_ATTRIBUTE_FILENAME, this.fileName);
   this.contextId =
       marker.getAttribute(ICamelDebugConstants.MARKER_ATTRIBUTE_CONTEXTID, this.contextId);
   this.resource = marker.getResource();
 }
 /**
  * Compares two AadlMarkers based on the <code>ReporterSettings</code> that an object of this
  * class is constructed with.
  *
  * @param marker1 The first AadlMarker to be compared.
  * @param marker2 The second AadlMarker to be compared.
  * @return a negative integer, zero, or a positive integer as the first marker is less than, equal
  *     to, or greater than the second.
  * @throws CoreException If this method fails. Reasons include:
  *     <ul>
  *       <li>This marker does not exist.
  *     </ul>
  */
 public int compare(IMarker marker1, IMarker marker2) {
   try {
     int compareResult = 0;
     if (settings.getGroupByAndSortBy(ReporterSettings.GROUP_BY_FIELD)
         == ReporterSettings.GROUP_BY_FILE) {
       if (settings.getGroupByAndSortBy(ReporterSettings.SORT_GROUPS_BY_FIELD)
           == ReporterSettings.SORT_BY_FILE_TYPE) {
         boolean marker1IsAadl = marker1.getResource().getName().endsWith(".aadl");
         boolean marker2IsAadl = marker2.getResource().getName().endsWith(".aadl");
         if (marker1IsAadl != marker2IsAadl) compareResult = (marker1IsAadl) ? -1 : 1;
       }
       if (compareResult == 0)
         compareResult =
             marker1.getResource().getName().compareTo(marker2.getResource().getName());
     }
     // group by type
     else compareResult = marker1.getType().compareTo(marker2.getType());
     for (int i = ReporterSettings.SORT_MARKERS_BY_FIRST;
         (i <= ReporterSettings.SORT_MARKERS_BY_FOURTH) && (compareResult == 0);
         i++)
       switch (settings.getGroupByAndSortBy(i)) {
         case ReporterSettings.SORT_BY_SEVERITY:
           int marker1Severity = ((Integer) marker1.getAttribute(IMarker.SEVERITY)).intValue();
           int marker2Severity = ((Integer) marker2.getAttribute(IMarker.SEVERITY)).intValue();
           if (marker1Severity != marker2Severity)
             compareResult = (marker1Severity > marker2Severity) ? -1 : 1;
           break;
         case ReporterSettings.SORT_BY_MESSAGE:
           compareResult =
               marker1
                   .getAttribute(IMarker.MESSAGE)
                   .toString()
                   .compareTo(marker2.getAttribute(IMarker.MESSAGE).toString());
           break;
         case ReporterSettings.SORT_BY_LOCATION:
           String marker1Location =
               (marker1.getType().endsWith("AadlTextMarker"))
                   ? marker1.getAttribute(IMarker.LINE_NUMBER).toString()
                   : marker1.getAttribute(AadlConstants.AADLURI).toString();
           String marker2Location =
               (marker2.getType().endsWith("AadlTextMarker"))
                   ? marker2.getAttribute(IMarker.LINE_NUMBER).toString()
                   : marker2.getAttribute(AadlConstants.AADLURI).toString();
           compareResult = marker1Location.compareTo(marker2Location);
           break;
         case ReporterSettings.SORT_BY_FILE_NAME:
           compareResult =
               marker1.getResource().getName().compareTo(marker2.getResource().getName());
           break;
         case ReporterSettings.SORT_BY_MARKER_TYPE:
           compareResult = marker1.getType().compareTo(marker2.getType());
           break;
       }
     return compareResult;
   } catch (CoreException e) {
     OsateUiPlugin.log(e);
     return 0;
   }
 }
 /**
  * return the number of compilation errors and as a side effect, write the errors to the specified
  * output file or to the build log if none specified.
  *
  * @param project
  * @param monitor
  * @return
  */
 private int getJavacErrorCount(IProject project, AntConsoleProgressMonitor monitor) {
   try {
     IMarker[] markerList =
         project.findMarkers(
             IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
     if (markerList == null || markerList.length == 0) {
       return 0;
     }
     IMarker marker = null;
     int numErrors = 0;
     XMLPrintStream out = getErrorOutputStream(project.getName());
     for (IMarker element : markerList) {
       marker = element;
       int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
       // default severity = ERROR
       if (severity == IMarker.SEVERITY_ERROR) {
         numErrors++;
         Integer lineNum = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
         String resourceName = marker.getResource().getName();
         String message = (String) marker.getAttribute(IMarker.MESSAGE);
         if (out != null) {
           appendError(out, marker.getResource(), message, lineNum);
         } else {
           monitor.displayMsg(resourceName + ":" + lineNum + ": " + message);
         }
       }
     }
     if (out != null) {
       close(out);
     }
     return numErrors;
   } catch (CoreException e) {
     displayError("CoreException: " + e.getMessage());
   }
   return UNKNOWN_ERRORS;
 }
Ejemplo n.º 15
0
 protected void collectBrakePoint(IResource resource) throws CoreException {
   fBreakpoints = new BucketMap<IResource, IBreakpoint>(6);
   fBreakpointAttributes = new HashMap<IBreakpoint, Map<String, Object>>(6);
   final IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
   IMarker[] markers =
       resource.findMarkers(IBreakpoint.LINE_BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
   for (IMarker marker : markers) {
     IResource markerResource = marker.getResource();
     IBreakpoint breakpoint = breakpointManager.getBreakpoint(marker);
     if (breakpoint != null) {
       fBreakpoints.add(markerResource, breakpoint);
       fBreakpointAttributes.put(breakpoint, breakpoint.getMarker().getAttributes());
     }
   }
 }
Ejemplo n.º 16
0
 private IDocument getDocument() {
   IMarker marker = getMarker();
   IResource r = marker.getResource();
   if (r instanceof IFile) {
     return FileUtilsFileBuffer.getDocFromResource(r);
   } else {
     // it's an external file...
     try {
       return FileUtilsFileBuffer.getDocFromFile(
           new File((String) marker.getAttribute(PyBreakpoint.PY_BREAK_EXTERNAL_PATH_ID)));
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
   }
 }
Ejemplo n.º 17
0
 /*
  * (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(
     final IMarker marker, final IDocument document, final Position position) {
   if (position.isDeleted()) {
     return false;
   }
   try {
     final int line = MarkerUtilities.getLineNumber(marker);
     final int newLine = document.getLineOfOffset(position.getOffset()) + 1;
     if (line == newLine) {
       return true;
     }
     final IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
     final IBreakpoint breakpoint = manager.getBreakpoint(marker);
     if (breakpoint == null) {
       return false;
     }
     if (breakpoint instanceof ErlangLineBreakpoint) {
       final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) breakpoint;
       final ErlangDebugTarget target = erlangLineBreakpoint.getTarget();
       erlangLineBreakpoint.remove(target);
       MarkerUtilities.setLineNumber(marker, newLine);
       erlangLineBreakpoint.install(target);
       return true;
     }
     // if there exists a breakpoint on the line remove this one
     if (isLineBreakpointMarker(marker)) {
       ensureRanges(document, marker, line);
       return lineBreakpointExists(marker.getResource(), line, marker) == null;
     }
     // if the line info is a valid location with an invalid line
     // number,
     // a line breakpoint must be removed
     if (isLineBreakpointMarker(marker) && line == -1) {
       return false;
     }
     MarkerUtilities.setLineNumber(marker, line);
     if (isLineBreakpointMarker(marker)) {
       ensureRanges(document, marker, line);
     }
     return true;
   } catch (final BadLocationException e) {
     ErlLogger.error(e);
   } catch (final CoreException e) {
     ErlLogger.error(e);
   }
   return false;
 }
Ejemplo n.º 18
0
 /** @since 2.7 */
 protected Set<IFile> getDerivedResources(
     Delta delta,
     final Map<String, OutputConfiguration> outputConfigurations,
     Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers) {
   String uri = delta.getUri().toString();
   Set<IFile> derivedResources = newLinkedHashSet();
   for (OutputConfiguration config : outputConfigurations.values()) {
     if (config.isCleanUpDerivedResources()) {
       Iterable<IMarker> markers = generatorMarkers.get(config);
       for (IMarker marker : markers) {
         String source = derivedResourceMarkers.getSource(marker);
         if (source != null && source.equals(uri))
           derivedResources.add((IFile) marker.getResource());
       }
     }
   }
   return derivedResources;
 }
Ejemplo n.º 19
0
 /** @return the file to be debugged or null if it cannot be determined. */
 public String getFile() {
   IMarker marker = getMarker();
   IResource r = marker.getResource();
   if (r instanceof IFile) {
     IPath location = r.getLocation();
     if (location == null) {
       return null;
     }
     return location.toOSString();
   } else {
     // it's an external file...
     try {
       return (String) marker.getAttribute(PyBreakpoint.PY_BREAK_EXTERNAL_PATH_ID);
     } catch (CoreException e) {
       throw new RuntimeException(e);
     }
   }
 }
Ejemplo n.º 20
0
 /** @return The nature to be used for this breakpoint or null if it cannot be determined. */
 private IPythonNature getPythonNature() {
   IMarker marker = getMarker();
   IPythonNature nature = PythonNature.getPythonNature(marker.getResource());
   if (nature == null) {
     try {
       String externalPath = (String) marker.getAttribute(PyBreakpoint.PY_BREAK_EXTERNAL_PATH_ID);
       if (externalPath != null) {
         Tuple<IPythonNature, String> infoForFile =
             PydevPlugin.getInfoForFile(new File(externalPath));
         if (infoForFile != null) {
           nature = infoForFile.o1;
         }
       }
     } catch (CoreException e) {
       throw new RuntimeException(e);
     }
   }
   return nature;
 }
Ejemplo n.º 21
0
    /** @return boolean - True if the properties on this maker match the given IMarker */
    public boolean equals(IMarker marker) {
      int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);

      boolean equals =
          ((severity == IMarker.SEVERITY_WARNING) && !_isError)
              || ((severity == IMarker.SEVERITY_ERROR) && _isError);

      if (equals && (_description != null)) {
        String actualDescription = marker.getAttribute(IMarker.MESSAGE, ""); // $NON-NLS-1$
        equals = Pattern.matches(_description, actualDescription);
      }

      if (equals && (_resourceName != null)) {
        IResource actualResource = marker.getResource();
        equals = (actualResource != null) && (actualResource.getName().equals(_resourceName));
      }

      return equals;
    }
 public IMarkerResolution[] getResolutions(IMarker marker) {
   if (isNeedToCreate(marker)) {
     IMutableValidator[] validators;
     try {
       MutableWorkspaceSettings workspaceSettings =
           ValidationFramework.getDefault().getWorkspaceSettings();
       validators = workspaceSettings.getValidators();
       if (DisableFaceletHTMLValidatorMarkerResolution.findValidator(validators, VALIDATOR_ID)
           != null) {
         return new IMarkerResolution[] {
           new DisableFaceletHTMLValidatorMarkerResolution((IFile) marker.getResource())
         };
       }
     } catch (InvocationTargetException e) {
       JsfUiPlugin.getPluginLog().logError(e);
     }
   }
   return new IMarkerResolution[] {};
 }
 /**
  * Returns a Java line breakpoint that is already registered with the breakpoint manager for a
  * type with the given name at the given line number.
  *
  * @param typeName fully qualified type name
  * @param lineNumber line number
  * @return a Java line breakpoint that is already registered with the breakpoint manager for a
  *     type with the given name at the given line number or <code>null</code> if no such
  *     breakpoint is registered
  * @exception CoreException if unable to retrieve the associated marker attributes (line number).
  */
 public static IJavaLineBreakpoint findStratumBreakpoint(IResource resource, int lineNumber)
     throws CoreException {
   String modelId = JDT_DEBUG_PLUGIN_ID;
   String markerType = "org.eclipse.jdt.debug.javaStratumLineBreakpointMarker";
   IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
   IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
   for (int i = 0; i < breakpoints.length; i++) {
     if (!(breakpoints[i] instanceof IJavaLineBreakpoint)) {
       continue;
     }
     IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) breakpoints[i];
     IMarker marker = breakpoint.getMarker();
     if (marker != null && marker.exists() && marker.getType().equals(markerType)) {
       if (breakpoint.getLineNumber() == lineNumber && resource.equals(marker.getResource())) {
         return breakpoint;
       }
     }
   }
   return null;
 }
Ejemplo n.º 24
0
 public static List<String> addBreakpointProjectsAndModules(
     final Collection<IProject> projects, final Collection<String> interpretedModules2) {
   final IBreakpointManager bpm = DebugPlugin.getDefault().getBreakpointManager();
   final List<String> result = Lists.newArrayList(interpretedModules2);
   for (final IBreakpoint bp : bpm.getBreakpoints(ErlDebugConstants.ID_ERLANG_DEBUG_MODEL)) {
     final IMarker m = bp.getMarker();
     final IResource r = m.getResource();
     final String name = r.getName();
     if (ModuleKind.hasErlExtension(name)) {
       final IProject p = r.getProject();
       if (projects.contains(p)) {
         final String s = p.getName() + ":" + name;
         if (!result.contains(s)) {
           result.add(s);
         }
       }
     }
   }
   return result;
 }
Ejemplo n.º 25
0
  /** Makes the fix */
  public boolean fix() {
    IResource source = marker.getResource();
    IJavaElement javaElem = JavaCore.create(source);
    ICompilationUnit compUnit = (ICompilationUnit) javaElem;
    IProgressMonitor pm = new NullProgressMonitor();

    try {
      // create move policy and processor for the compilation unit
      IMovePolicy movePolicy =
          ReorgPolicyFactory.createMovePolicy(
              new IResource[] {compUnit.getResource()}, new IJavaElement[] {compUnit});
      JavaMoveProcessor processor = new JavaMoveProcessor(movePolicy);
      if (newSource == null) return false;
      processor.setDestination(ReorgDestinationFactory.createDestination(newSource));
      // the refactoring object
      Refactoring refactoring = new ProcessorBasedRefactoring(processor);
      // set a refactoring wizard
      RefactoringWizard wizard = new ReorgMoveWizard(processor, refactoring);
      Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
      wizard.setContainer(new RefactoringWizardDialog(activeShell, wizard));
      // set reorg queries (no idea what it is used for, but doesn't work without it)
      processor.setCreateTargetQueries(new CreateTargetQueries(wizard));
      processor.setReorgQueries(new ReorgQueries(activeShell));
      // perform the refactoring and return its success result
      performRefactoring(refactoring);
      boolean status = wizard.getChange() != null;
      System.out.println(status);
      return status;
    } catch (JavaModelException e) {
      e.printStackTrace();
      return false;
    } catch (OperationCanceledException e) {
      e.printStackTrace();
      return false;
    } finally {
      pm.done();
    }
  }
Ejemplo n.º 26
0
 private BreakpointData[] createBreakpointData() {
   IBreakpointManager bpm = getBreakpointManager();
   IBreakpoint[] breakpoints = bpm.getBreakpoints(LSLDebugTarget.LSLFORGE);
   LinkedList<BreakpointData> list = new LinkedList<BreakpointData>();
   for (int i = 0; i < breakpoints.length; i++) {
     try {
       if (breakpoints[i] instanceof LSLLineBreakpoint) {
         LSLLineBreakpoint bp = (LSLLineBreakpoint) breakpoints[i];
         int line = bp.getLineNumber();
         IMarker marker = bp.getMarker();
         IResource resource = marker.getResource();
         IFile file = (IFile) resource.getAdapter(IFile.class);
         if (file == null) continue;
         if (!marker.getAttribute(IBreakpoint.ENABLED, false)) continue;
         IPath fullPath = file.getLocation();
         list.add(new BreakpointData(fullPath.toOSString(), line));
       }
     } catch (CoreException e) {
       Log.error(e);
     }
   }
   return list.toArray(new BreakpointData[list.size()]);
 }
Ejemplo n.º 27
0
 /**
  * Constructor
  *
  * @param marker the marker to be fixed
  */
 public Fixer(IMarker marker) {
   super();
   this.marker = marker;
   IResource source = marker.getResource();
   IProject project = source.getProject();
   IJavaProject javaProject = JavaCore.create(project);
   IPackageFragment[] packageFragments;
   try {
     packageFragments = javaProject.getPackageFragments();
     String newSourceName;
     newSourceName = (String) marker.getAttribute(QuickFix.ATTRIBUTE_NEWSOURCE);
     for (IPackageFragment pckgFrg : packageFragments) {
       if (pckgFrg.getElementName().equals(newSourceName)) {
         newSource = pckgFrg;
         break;
       }
     }
   } catch (JavaModelException e) {
     e.printStackTrace();
   } catch (CoreException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 28
0
    @Override
    public StyledString getStyledText(Object element) {
      StyledString str = new StyledString();

      if (element instanceof IMarker) {
        IMarker marker = (IMarker) element;

        IResource resource = marker.getResource();

        if (resource != null) {
          String name = resource.getName();

          if (resource instanceof IWorkspaceRoot) {
            name = "Workspace";
          }

          if (name == null) {
            name = "";
          }

          str.append(name);

          if (name.length() > 0) {
            int lineNumber = marker.getAttribute(IMarker.LINE_NUMBER, -1);

            if (lineNumber != -1) {
              String num = NumberFormat.getIntegerInstance().format(lineNumber);

              str.append(" [line " + num + "]", StyledString.DECORATIONS_STYLER);
            }
          }
        }
      }

      return str;
    }
  private IMarkerResolution[] findResolutions(IMarker marker) throws CoreException {

    int messageId = getMessageID(marker);
    if (messageId == -1) return new IMarkerResolution[] {};

    IFile file = (IFile) marker.getResource();

    Integer attribute = ((Integer) marker.getAttribute(IMarker.CHAR_START));
    if (attribute == null) return new IMarkerResolution[] {};
    int start = attribute.intValue();

    attribute = ((Integer) marker.getAttribute(IMarker.CHAR_END));
    if (attribute == null) return new IMarkerResolution[] {};
    int end = attribute.intValue();

    if (JAVA_EXTENSION.equals(file.getFileExtension())) {
      if (messageId == SeamCoreValidator.NONUNIQUE_COMPONENT_NAME_MESSAGE_ID) {
        return new IMarkerResolution[] {
          new RenameAnnotationMarkerResolution(
              SeamCoreMessages.RENAME_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Name",
              file,
              start,
              end),
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Name",
              file,
              start,
              end)
        };
      } else if (messageId == SeamCoreValidator.DUPLICATE_REMOVE_MESSAGE_ID)
        return new IMarkerResolution[] {
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_REMOVE_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "javax.ejb.Remove",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.DUPLICATE_DESTROY_MESSAGE_ID)
        return new IMarkerResolution[] {
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_DESTROY_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Destroy",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.DUPLICATE_CREATE_MESSAGE_ID)
        return new IMarkerResolution[] {
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_CREATE_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Create",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.DUPLICATE_UNWRAP_MESSAGE_ID)
        return new IMarkerResolution[] {
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_UNWRAP_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Unwrap",
              file,
              start,
              end)
        };
      else if (messageId
          == SeamCoreValidator.DESTROY_METHOD_BELONGS_TO_STATELESS_SESSION_BEAN_MESSAGE_ID)
        return new IMarkerResolution[] {
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_DESTROY_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Destroy",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.CREATE_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID)
        return new IMarkerResolution[] {
          new AddAnnotationMarkerResolution(
              SeamCoreMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Name",
              file,
              start,
              end,
              true),
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_CREATE_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Create",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.UNWRAP_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID)
        return new IMarkerResolution[] {
          new AddAnnotationMarkerResolution(
              SeamCoreMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Name",
              file,
              start,
              end,
              true),
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_UNWRAP_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Unwrap",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.OBSERVER_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID)
        return new IMarkerResolution[] {
          new AddAnnotationMarkerResolution(
              SeamCoreMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Name",
              file,
              start,
              end,
              true),
          new DeleteAnnotationMarkerResolution(
              SeamCoreMessages.DELETE_OBSERVER_ANNOTATION_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Observer",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_REMOVE_ID)
        return new IMarkerResolution[] {
          new AddAnnotatedMethodMarkerResolution(
              SeamCoreMessages.ADD_ANNOTATED_REMOVE_METHOD_MARKER_RESOLUTION_TITLE,
              "javax.ejb.Remove",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_DESTROY_ID)
        return new IMarkerResolution[] {
          new AddAnnotatedMethodMarkerResolution(
              SeamCoreMessages.ADD_ANNOTATED_DESTROY_METHOD_MARKER_RESOLUTION_TITLE,
              "org.jboss.seam.annotations.Destroy",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.STATEFUL_COMPONENT_WRONG_SCOPE_ID)
        return new IMarkerResolution[] {
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.APPLICATION",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.BUSINESS_PROCESS",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.CONVERSATION",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.EVENT",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.METHOD",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.SESSION",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.UNSPECIFIED",
              file,
              start,
              end)
        };
      else if (messageId == SeamCoreValidator.ENTITY_COMPONENT_WRONG_SCOPE_ID)
        return new IMarkerResolution[] {
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.APPLICATION",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.BUSINESS_PROCESS",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.CONVERSATION",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.EVENT",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.METHOD",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.PAGE",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.SESSION",
              file,
              start,
              end),
          new ChangeScopeMarkerResolution(
              SeamCoreMessages.CHANGE_SCOPETYPE_MARKER_RESOLUTION_TITLE,
              "ScopeType.UNSPECIFIED",
              file,
              start,
              end)
        };
    } else if (XML_EXTENSION.equals(file.getFileExtension())) {
      if (messageId == SeamCoreValidator.UNKNOWN_COMPONENT_PROPERTY_ID) {
        ISeamProperty property = findSeamProperty(file, start, end);
        if (property != null) {
          if (property.getParent() != null
              && property.getParent() instanceof SeamComponentDeclaration) {
            SeamComponentDeclaration xmlDeclaration =
                (SeamComponentDeclaration) property.getParent();
            if (xmlDeclaration == null) {
              return new IMarkerResolution[] {};
            }
            for (ISeamComponent component : xmlDeclaration.getComponents()) {
              ISeamJavaComponentDeclaration javaDeclaration = component.getJavaDeclaration();
              if (javaDeclaration != null)
                return new IMarkerResolution[] {
                  new AddSetterMarkerResolution(property, javaDeclaration)
                };
            }
          }
        }
      }
    }

    return new IMarkerResolution[] {};
  }
Ejemplo n.º 30
0
    private int compareResourceName(IMarker marker1, IMarker marker2) {
      String name1 = marker1.getResource().getName();
      String name2 = marker2.getResource().getName();

      return name1.compareToIgnoreCase(name2);
    }