示例#1
0
 /* (non-Javadoc)
  * @see org.eclipse.core.runtime.Plugin#startup()
  */
 @Override
 public void start(BundleContext context) throws Exception {
   super.start(context);
   ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDefaultDebugConfiguration();
   if (dc == null) {
     CDebugCorePlugin.getDefault()
         .getPluginPreferences()
         .setDefault(
             ICDebugConstants.PREF_DEFAULT_DEBUGGER_TYPE,
             "org.eclipse.cdt.debug.mi.core.CDebuggerNew"); //$NON-NLS-1$
   }
 }
 public SetSteppingModeHandler() {
   super();
   fCurrentValue =
       CDebugCorePlugin.getDefault()
           .getPluginPreferences()
           .getString(ICDebugConstants.PREF_STEP_MODE);
 }
  /** @deprecated Not intended to be public - do not use */
  @Deprecated
  public String getDefaultDebugger(final ILaunchConfiguration config) throws CoreException {
    // Mostly from CDebbuggerTab
    String defaultDebugger = null;

    String projectName =
        config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
    if (projectName.length() > 0) {
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
      ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project);
      if (projDesc != null) {
        ICConfigurationDescription configDesc = projDesc.getActiveConfiguration();
        String configId = configDesc.getId();
        ICDebugConfiguration[] debugConfigs =
            CDebugCorePlugin.getDefault().getActiveDebugConfigurations();
        outer:
        for (int i = 0; i < debugConfigs.length; ++i) {
          ICDebugConfiguration debugConfig = debugConfigs[i];
          String[] patterns = debugConfig.getSupportedBuildConfigPatterns();
          if (patterns != null) {
            for (int j = 0; j < patterns.length; ++j) {
              if (configId.matches(patterns[j])) {
                defaultDebugger = debugConfig.getID();
                break outer;
              }
            }
          }
        }
      }
    }

    if (defaultDebugger == null) {
      ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration();
      if (dc != null) {
        defaultDebugger = dc.getID();
      }
    }

    return defaultDebugger;
  }
  /* (non-Javadoc)
   * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    String param = event.getParameter(ID_PARAMETER_MODE);
    if (param == null || param.equals(fCurrentValue)) return null;

    fCurrentValue = param;
    CDebugCorePlugin.getDefault()
        .getPluginPreferences()
        .setValue(ICDebugConstants.PREF_STEP_MODE, fCurrentValue);

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ICommandService service = window.getService(ICommandService.class);
    service.refreshElements(event.getCommand().getId(), null);

    return null;
  }
	private IEditorInput findFileInCommonSourceLookup(IPath path)
	{
		try {
			AbstractSourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector();
			ISourceContainer[] c = director.getSourceContainers();
			for (ISourceContainer sourceContainer : c) {
				Object[] o = sourceContainer.findSourceElements(path.toOSString());
				for (Object object : o) {
					if (object instanceof IFile) {
						return new FileEditorInput((IFile)object);
					} else if (object instanceof LocalFileStorage) {
						LocalFileStorage storage = (LocalFileStorage) object;
						IFileStore ifs = EFS.getStore(storage.getFile().toURI());
						return new FileStoreEditorInput(ifs);
					}
				}
			}
		} catch (Exception _) {
			// do nothing
		}
		return null;
	}
/**
 * A directory in the local file system that is used for running the C/C++ compiler. This container
 * is intended to be used when debugging information produced by the C/C++ compiler contains paths
 * to the source and header files relative to the directory where the compiler is run from. The
 * assumption is that all files under a compilation directory are compiled relative to that
 * directory, unless they belong to another compilation directory container that is higher on the
 * source container list.
 *
 * <p>Source elements returned from <code>findSourceElements(...)</code> are instances of <code>
 * IFile</code> or <code>LocalFileStorage</code>.
 *
 * <p>Clients may instantiate this class.
 *
 * @noextend This class is not intended to be subclassed by clients.
 */
public class CompilationDirectorySourceContainer extends CompositeSourceContainer
    implements IMappingSourceContainer {
  /**
   * Unique identifier for the compilation directory source container type (value <code>
   * org.eclipse.debug.core.containerType.compilationDirectory</code>).
   */
  public static final String TYPE_ID =
      CDebugCorePlugin.getUniqueIdentifier() + ".containerType.compilationDirectory"; // $NON-NLS-1$

  // Root directory.
  private File fDirectory;
  // Whether to each subdirectory of the compilation directory is also the compilation directory
  // for the files it contains.
  private boolean fSubfolders;

  /**
   * Constructs an external folder container for the directory identified by the given path.
   *
   * @param dirPath path to a directory in the local file system
   * @param subfolders whether folders within the root directory should be searched for source
   *     elements
   */
  public CompilationDirectorySourceContainer(IPath dirPath, boolean subfolders) {
    this(dirPath.toFile(), subfolders);
  }

  /**
   * Constructs an external folder container for the directory identified by the given file.
   *
   * @param dir a directory in the local file system
   * @param subfolders whether folders within the root directory should be searched for source
   *     elements
   */
  public CompilationDirectorySourceContainer(File dir, boolean subfolders) {
    fDirectory = dir;
    fSubfolders = subfolders;
  }

  /* (non-Javadoc)
   * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
   */
  public String getName() {
    return fDirectory.getAbsolutePath();
  }

  /**
   * Returns the root directory in the local file system associated with this source container.
   *
   * @return the root directory in the local file system associated with this source container
   */
  public File getDirectory() {
    return fDirectory;
  }

  /* (non-Javadoc)
   * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
   */
  public ISourceContainerType getType() {
    return getSourceContainerType(TYPE_ID);
  }

  /**
   * Source elements returned from this method are instances of <code>IFile</code> or <code>
   * LocalFileStorage</code>.
   *
   * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(String)
   */
  public Object[] findSourceElements(String name) throws CoreException {
    File file = new File(name);
    if (!file.isAbsolute()) {
      file = new File(fDirectory, name);
    }
    List<Object> sources = new ArrayList<Object>();
    if (file.exists() && file.isFile()) {
      sources.addAll(Arrays.asList(SourceUtils.findSourceElements(file, getDirector())));
    } else {
      sources = new ArrayList<Object>();
    }

    // Check sub-folders
    if (fSubfolders && (isFindDuplicates() || sources.isEmpty())) {
      for (ISourceContainer container : getSourceContainers()) {
        Object[] elements = container.findSourceElements(name);
        if (elements == null || elements.length == 0) {
          continue;
        }
        if (isFindDuplicates()) {
          for (Object element : elements) sources.add(element);
        } else {
          sources.add(elements[0]);
          break;
        }
      }
    }

    if (sources.isEmpty()) return EMPTY;
    return sources.toArray();
  }

  /* (non-Javadoc)
   * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#isComposite()
   */
  public boolean isComposite() {
    return fSubfolders;
  }

  /* (non-Javadoc)
   * @see java.lang.Object#equals(java.lang.Object)
   */
  public boolean equals(Object obj) {
    if (obj instanceof CompilationDirectorySourceContainer) {
      CompilationDirectorySourceContainer container = (CompilationDirectorySourceContainer) obj;
      return container.getDirectory().equals(getDirectory());
    }
    return false;
  }

  /* (non-Javadoc)
   * @see java.lang.Object#hashCode()
   */
  public int hashCode() {
    return getDirectory().hashCode();
  }

  /* (non-Javadoc)
   * @see org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer#createSourceContainers()
   */
  protected ISourceContainer[] createSourceContainers() throws CoreException {
    if (fSubfolders) {
      String[] files = fDirectory.list();
      if (files != null) {
        List<ISourceContainer> dirs = new ArrayList<ISourceContainer>();
        for (String name : files) {
          File file = new File(getDirectory(), name);
          if (file.exists() && file.isDirectory()) {
            dirs.add(new CompilationDirectorySourceContainer(file, true));
          }
        }
        ISourceContainer[] containers = dirs.toArray(new ISourceContainer[dirs.size()]);
        for (ISourceContainer container : containers) {
          container.init(getDirector());
        }
        return containers;
      }
    }
    return new ISourceContainer[0];
  }

  /* (non-Javadoc)
   * @see org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer#getCompilationPath(java.lang.String)
   */
  public IPath getCompilationPath(String sourceName) {
    IPath path = new Path(sourceName);
    IPath base = new Path(fDirectory.getPath());
    if (base.isPrefixOf(path)) {
      if (fSubfolders) {
        base = path.removeLastSegments(1);
      }
      return path.makeRelativeTo(base);
    }
    return null;
  }
}