/**
   * Creates a new default spell checker.
   *
   * @param store the preference store for this spell checker
   * @param locale the locale
   */
  public DefaultSpellChecker(IPreferenceStore store, Locale locale) {
    Assert.isLegal(store != null);
    Assert.isLegal(locale != null);

    fPreferences = store;
    fLocale = locale;
  }
 /**
  * Creates a new history.
  *
  * @param maxLHS the maximum number of tracked left hand sides (> 0)
  * @param maxRHS the maximum number of tracked right hand sides per left hand side(> 0)
  */
 public ContentAssistHistory(int maxLHS, int maxRHS) {
   Assert.isLegal(maxLHS > 0);
   Assert.isLegal(maxRHS > 0);
   fMaxLHS = maxLHS;
   fMaxRHS = maxRHS;
   fLHSCache = new MRUMap<String, MRUSet<String>>(fMaxLHS);
 }
 public boolean initialize(EObject xtendMethod, IRenameElementContext context) {
   Assert.isLegal(xtendMethod instanceof XtendFunction);
   Assert.isLegal(((XtendFunction) xtendMethod).isDispatch());
   Assert.isLegal(context instanceof DispatchMethodRenameContext);
   ResourceSet resourceSet = xtendMethod.eResource().getResourceSet();
   Map<URI, IJavaElement> jvm2JavaElements =
       ((DispatchMethodRenameContext) context).getJvm2JavaElements();
   for (URI dispatchOperationURI : jvm2JavaElements.keySet()) {
     JvmOperation dispatchOperation =
         (JvmOperation) resourceSet.getEObject(dispatchOperationURI, true);
     XtendFunction xtendDispatchMethod = associations.getXtendFunction(dispatchOperation);
     if (xtendDispatchMethod != null) {
       if (equal(xtendDispatchMethod.getName(), dispatchOperation.getSimpleName())) {
         // synthetic dispatcher
         dispatchers.add(dispatchOperation);
       } else {
         // xtend dispatch method
         XtendDispatchMethodChildStrategy xtendChildStrategy = childStrategyProvider.get();
         xtendChildStrategy.initialize(xtendDispatchMethod, context);
         children.add(xtendChildStrategy);
       }
     } else {
       // a dispatch method form a Java class
       JavaDispatchMethodChildStrategy jvmChildStrategy = javaStrategyProvider.get();
       jvmChildStrategy.initialize(dispatchOperation, context);
       children.add(jvmChildStrategy);
     }
   }
   return !children.isEmpty();
 }
 public FileDialogFileNameFilter(
     final String shortFormatName,
     final List<String> filenamePatternList,
     final String defaultSuffix) {
   Assert.isLegal(shortFormatName != null, "The shortFormatName argument can not be null.");
   Assert.isLegal(filenamePatternList != null, "The filenameFilterList argument can not be null.");
   this.shortFormatName = shortFormatName;
   this.filenamePatternList = filenamePatternList;
   this.defaultSuffix = defaultSuffix;
 }
  public <T> T parseResponse(String responseMessage, Type resultType) {
    Assert.isLegal(responseMessage != null);
    Assert.isLegal(!responseMessage.isEmpty());

    // Gerrit 2.5 prepends the output with bogus characters
    // see http://code.google.com/p/gerrit/issues/detail?id=1648
    if (responseMessage.startsWith(")]}'\n")) { // $NON-NLS-1$
      responseMessage = responseMessage.substring(5);
    }
    return gson.fromJson(responseMessage, resultType);
  }
  /**
   * Returns an RGB that lies between the given foreground and background colors using the given
   * mixing factor. A <code>factor</code> of 1.0 will produce a color equal to <code>fg</code>,
   * while a <code>factor</code> of 0.0 will produce one equal to <code>bg</code>.
   *
   * @param bg the background color
   * @param fg the foreground color
   * @param factor the mixing factor, must be in [0,&nbsp;1]
   * @return the interpolated color
   * @since 3.6
   */
  private static RGB blend(RGB bg, RGB fg, float factor) {
    // copy of org.eclipse.jface.internal.text.revisions.Colors#blend(..)
    Assert.isLegal(bg != null);
    Assert.isLegal(fg != null);
    Assert.isLegal(factor >= 0f && factor <= 1f);

    float complement = 1f - factor;
    return new RGB(
        (int) (complement * bg.red + factor * fg.red),
        (int) (complement * bg.green + factor * fg.green),
        (int) (complement * bg.blue + factor * fg.blue));
  }
  /**
   * Returns the remote config for the given remote in the given repository
   *
   * @param remote
   * @param repository
   * @return
   * @throws CoreException
   */
  public static RemoteConfig getRemoteByName(String remote, Repository repository)
      throws CoreException {
    Assert.isLegal(repository != null, "Could not get configuration. No repository provided.");

    List<RemoteConfig> allRemotes = getAllRemoteConfigs(repository);
    return getRemoteConfig(remote, allRemotes);
  }
  /**
   * Returns the configuration of the remote repository that is set to the
   * given repository.
   * <code>null</null> if none was configured or if there's no remote repo configured.
   *
   * @param repository
   *            the repository to get the remote repo configuration from
   * @return the configurtion of the remote repository
   * @throws CoreException
   *             the core exception
   */
  private static RemoteConfig getRemoteConfig(Repository repository) throws CoreException {
    Assert.isLegal(repository != null, "Could not get configuration. No repository provided.");

    String currentBranch = getCurrentBranch(repository);
    String remote = getRemoteName(currentBranch, repository);
    return getRemoteByName(remote, repository);
  }
  private void combine(
      MPartSashContainerElement toInsert,
      MPartSashContainerElement relTo,
      MPartSashContainer newSash,
      boolean newFirst,
      float ratio) {
    MElementContainer<MUIElement> curParent = relTo.getParent();
    if (curParent == null) {
      // if relTo is a shared element, use its current placeholder
      MWindow win = getTopLevelWindowFor(relTo);
      relTo = findPlaceholderFor(win, relTo);
      curParent = relTo.getParent();
    }
    Assert.isLegal(relTo != null && curParent != null);
    int index = curParent.getChildren().indexOf(relTo);
    curParent.getChildren().remove(relTo);
    if (newFirst) {
      newSash.getChildren().add(toInsert);
      newSash.getChildren().add(relTo);
    } else {
      newSash.getChildren().add(relTo);
      newSash.getChildren().add(toInsert);
    }

    // Set up the container data before adding the new sash to the model
    // To raise the granularity assume 100% == 10,000
    int adjustedPct = (int) (ratio * 10000);
    toInsert.setContainerData(Integer.toString(adjustedPct));
    relTo.setContainerData(Integer.toString(10000 - adjustedPct));

    // add the new sash at the same location
    curParent.getChildren().add(index, newSash);
  }
 /*
  * @see IProblemRequestorExtension#setIsActive(boolean)
  */
 public synchronized void setIsActive(boolean isActive) {
   Assert.isLegal(
       !isActive || Display.getCurrent() == null); // must not be enabled from UI threads
   fIsActive = isActive;
   if (fIsActive) fActiveThread = Thread.currentThread();
   else fActiveThread = null;
 }
 @Override
 public ImportStrategy create(BuildType buildType, String name, String notInstalledMessage)
     throws Exception {
   Assert.isLegal(buildType == BuildType.GRADLE);
   Class.forName("org.eclipse.buildship.core.projectimport.ProjectImportConfiguration");
   return new BuildshipImportStrategy(buildType, name, notInstalledMessage);
 }
示例#12
0
  public void setHeight(int height) {
    if (height < 0) {
      height = getDefaultHeight();
    }
    this.height = height;

    Assert.isLegal(this.height >= 0);
  }
示例#13
0
  /**
   * Gets the repository that is configured to the given project.
   *
   * @param project the project
   * @return the repository
   */
  public static Repository getRepository(IProject project) {
    Assert.isLegal(project != null, "Could not get repository. No project provided");

    RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
    if (repositoryMapping == null) {
      return null;
    }
    return repositoryMapping.getRepository();
  }
示例#14
0
  public SeasonTableWidget(Composite parent, IMedia media, int style) {
    super(parent, media, style);

    Assert.isLegal(media instanceof MediaSeason);

    this.seasonField.setEditable(false);
    this.seasonField.setEnabled(false);
    this.seasonField.removeVerifyListener(this.intVerifier);
    this.seasonField.setText("" + ((MediaSeason) media).season);
  }
 /* (non-Javadoc)
  * @see org.eclipse.search.ui.text.TextSearchQueryProvider#createQuery(TextSearchInput)
  */
 public ISearchQuery createQuery(TextSearchInput input) {
   FileTextSearchScope scope = input.getScope();
   String text = input.getSearchText();
   boolean regEx = input.isRegExSearch();
   boolean caseSensitive = input.isCaseSensitiveSearch();
   boolean wholeWord = input.isWholeWordSearch();
   boolean searchInBinaries = input.searchInBinaries();
   Assert.isLegal(!(wholeWord && regEx));
   return new FileSearchQuery(text, regEx, caseSensitive, wholeWord, searchInBinaries, scope);
 }
示例#16
0
  /**
   * Remembers the selection of a right hand side type (proposal type) for a certain left hand side
   * (expected type) in content assist.
   *
   * @param lhs the left hand side / expected type
   * @param rhs the selected right hand side
   */
  public void remember(IType lhs, IType rhs) {
    Assert.isLegal(lhs != null);
    Assert.isLegal(rhs != null);

    try {
      if (!isCacheableRHS(rhs)) return;
      ITypeHierarchy hierarchy = rhs.newSupertypeHierarchy(getProgressMonitor());
      if (hierarchy.contains(lhs)) {
        // TODO remember for every member of the LHS hierarchy or not? Yes for now.
        IType[] allLHSides = hierarchy.getAllSupertypes(lhs);
        String rhsQualifiedName = rhs.getFullyQualifiedName();
        for (int i = 0; i < allLHSides.length; i++)
          rememberInternal(allLHSides[i], rhsQualifiedName);
        rememberInternal(lhs, rhsQualifiedName);
      }
    } catch (JavaModelException x) {
      JavaPlugin.log(x);
    }
  }
示例#17
0
 /**
  * Gets the remote config with the given name from the list of remote configs. Returns <code>null
  * </code> if it was not found.
  *
  * @param remoteName the remote name
  * @param remoteRepositories the remote repositories
  * @return the remote config
  * @see #getAllRemoteConfigs(Repository)
  */
 public static RemoteConfig getRemoteConfig(String name, List<RemoteConfig> remoteConfigs) {
   Assert.isLegal(name != null);
   RemoteConfig remoteConfig = null;
   for (RemoteConfig config : remoteConfigs) {
     if (name != null && config.getName().equals(name)) {
       remoteConfig = config;
       break;
     }
   }
   return remoteConfig;
 }
示例#18
0
 public IPath removeLastSegments(int count) {
   if (count == 0) return this;
   if (count >= segments.length) {
     // result will have no trailing separator
     return new URLPath(device, new String[0], false);
   }
   Assert.isLegal(count > 0);
   int newSize = segments.length - count;
   String[] newSegments = new String[newSize];
   System.arraycopy(this.segments, 0, newSegments, 0, newSize);
   return new URLPath(device, newSegments, hasTrailingSeparator());
 }
示例#19
0
  /**
   * Gets the UserConfig from the given repository. The UserConfig of a repo holds the default
   * author and committer.
   *
   * @param repository the repository
   * @return the user configuration
   * @throws CoreException
   * @see PersonIdent(Repository)
   * @see CommittHelper#calculateCommitInfo
   */
  private static UserConfig getUserConfig(Repository repository) throws CoreException {
    Assert.isLegal(repository != null, "Could not get user configuration. No repository provided.");

    if (repository.getConfig() == null) {
      throw new CoreException(
          createStatus(
              null,
              "no user configuration (author, committer) are present in repository \"{0}\"",
              repository.toString()));
    }
    return repository.getConfig().get(UserConfig.KEY);
  }
示例#20
0
 @Override
 public void visitMethodCallExpression(MethodCallExpression call) {
   String name =
       call.getMethodAsString(); // Could be null (for 'funny' calls where target name is dynamic)
   SearchingCodeVisitor.MethodCallAction action = getMethodCallAction(name);
   if (action != null) {
     Assert.isLegal(action.methodName.equals(name));
     if (!isVisited(call)) {
       action.doit(this, call);
     }
   }
   super.visitMethodCallExpression(call);
 }
示例#21
0
  public IPath removeFirstSegments(int count) {
    if (count == 0) return this;
    if (count >= segments.length) {
      return new URLPath(device, new String[0], false);
    }
    Assert.isLegal(count > 0);
    int newSize = segments.length - count;
    String[] newSegments = new String[newSize];
    System.arraycopy(this.segments, count, newSegments, 0, newSize);

    // result is always a relative path
    return new URLPath(device, newSegments, hasTrailingSeparator());
  }
  /**
   * Returns the charset explicitly set by the user for the given resource, or <code>null</code>. If
   * no setting exists for the given resource and <code>recurse</code> is <code>true</code>, every
   * parent up to the workspace root will be checked until a charset setting can be found.
   *
   * @param resourcePath the path for the resource
   * @param recurse whether the parent should be queried
   * @return the charset setting for the given resource
   */
  public String getCharsetFor(IPath resourcePath, boolean recurse) {
    Assert.isLegal(resourcePath.segmentCount() >= 1);
    IProject project = workspace.getRoot().getProject(resourcePath.segment(0));

    Preferences prefs = getPreferences(project, false, false);
    Preferences derivedPrefs = getPreferences(project, false, true);

    if (prefs == null && derivedPrefs == null)
      // no preferences found - for performance reasons, short-circuit
      // lookup by falling back to workspace's default setting
      return recurse ? ResourcesPlugin.getEncoding() : null;

    return internalGetCharsetFor(prefs, derivedPrefs, resourcePath, recurse);
  }
 /*
  * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
  */
 public String getColumnText(Object element, int columnIndex) {
   switch (columnIndex) {
     case 0:
       return ((ListItem) element).name;
     case 1:
       String text = ((ListItem) element).modifierKeys;
       if (text == null) return fHyperlinkDefaultKeyModifierText.getText();
       return text;
     case 2:
       return ((ListItem) element).targetName;
     default:
       Assert.isLegal(false);
   }
   return null; // cannot happen
 }
示例#24
0
 private static RevCommit commit(
     IProject project, String commitMessage, Repository repository, IProgressMonitor monitor)
     throws CoreException {
   Assert.isLegal(project != null, "Could not commit project. No project provided");
   Assert.isLegal(
       repository != null,
       MessageFormat.format(
           "Could not commit. Project \"{0}\" is not connected to a repository (call #connect(project, repository) first)",
           project.getName()));
   /** TODO: add capability to commit selectively */
   UserConfig userConfig = getUserConfig(repository);
   CommitOperation op =
       new CommitOperation(
           null,
           null,
           null,
           getFormattedUser(userConfig.getAuthorName(), userConfig.getAuthorEmail()),
           getFormattedUser(userConfig.getCommitterName(), userConfig.getCommitterEmail()),
           commitMessage);
   op.setCommitAll(true);
   op.setRepository(repository);
   op.execute(monitor);
   return op.getCommit();
 }
  public List<NewsReference> getNews(Set<INews.State> states) {
    List<NewsReference> newsRefs = new ArrayList<NewsReference>(getNewsCount(states));

    for (INews.State state : states) {
      int index = state.ordinal();
      LongArrayList newsIds = fNewsIds[index];
      for (int i = 0, c = newsIds.size(); i < c; ++i) {
        long newsId = newsIds.get(i);
        Assert.isLegal(newsId != 0);
        newsRefs.add(new NewsReference(newsId));
      }
    }

    return newsRefs;
  }
    private void setLabelAndTooltipProviders(
        final IColumnLabelProvider<E> labelProvider,
        final CellLabelProvider cellLabelProvider,
        final ICellToolTipProvider<E> tooltipProvider,
        TableViewerColumn column) {
      Assert.isLegal(
          (cellLabelProvider != null && tooltipProvider == null) || cellLabelProvider == null,
          "cannot use ITooltipProvider with CellLabelProvider");
      if (labelProvider != null) {
        column.setLabelProvider(
            new CellLabelProvider() {

              @SuppressWarnings("unchecked")
              @Override
              public void update(ViewerCell cell) {
                if (labelProvider != null) {
                  String cellValue = labelProvider.getValue((E) cell.getElement());
                  cell.setText(cellValue);
                  boolean italic = labelProvider.isModified((E) cell.getElement());
                  applyFont(cell, italic);
                }
              }

              @SuppressWarnings("unchecked")
              @Override
              public String getToolTipText(Object object) {
                if (tooltipProvider != null) {
                  return tooltipProvider.getToolTipText((E) object);
                } else {
                  return super.getToolTipText(object);
                }
              };

              @SuppressWarnings("unchecked")
              @Override
              public int getToolTipDisplayDelayTime(Object element) {
                if (tooltipProvider != null) {
                  return tooltipProvider.getToolTipDisplayDelayTime((E) element);
                } else {
                  return super.getToolTipDisplayDelayTime(element);
                }
              }
            });
      } else if (cellLabelProvider != null) {
        column.setLabelProvider(cellLabelProvider);
      }
    }
    @Override
    public IConnection update(IConnection conn) {
      Assert.isLegal(conn instanceof Connection);

      final Connection connection = (Connection) conn;
      Display.getDefault()
          .syncExec(
              new Runnable() {

                @Override
                public void run() {
                  connection.setExtendedProperty(
                      ICommonAttributes.IMAGE_REGISTRY_URL_KEY, registryURLObservable.getValue());
                }
              });
      return connection;
    }
示例#28
0
 public IRuleAction getAction(ISynchronizationRule rule) {
   if (rule instanceof DownloadRule) {
     DownloadRule downloadRule = (DownloadRule) rule;
     DownloadRuleAction action = new DownloadRuleAction(process, downloadRule);
     return action;
   } else if (rule instanceof UploadRule) {
     UploadRule uploadRule = (UploadRule) rule;
     UploadRuleAction action = new UploadRuleAction(process, uploadRule);
     return action;
   } else if (rule instanceof DownloadBackRule) {
     DownloadBackRule uploadRule = (DownloadBackRule) rule;
     DownloadBackAction action = new DownloadBackAction(process, uploadRule);
     return action;
   } else {
     Assert.isLegal(false);
     return null;
   }
 }
  /* (non-Javadoc)
   * @see com.aptana.ide.ui.io.IPropertiesEditor#loadPropertiesFrom(java.lang.Object)
   */
  public void loadPropertiesFrom(Object element) {
    Assert.isLegal(element instanceof ISFTPConnectionPoint);
    ISFTPConnectionPoint sftpConnectionPoint = (ISFTPConnectionPoint) element;

    removeListeners();
    try {
      int index = compressionCombo.indexOf(String.valueOf(sftpConnectionPoint.getCompression()));
      if (index >= 0) {
        compressionCombo.select(index);
      }
      portText.setText(Integer.toString(sftpConnectionPoint.getPort()));
      index = encodingCombo.indexOf(String.valueOf(sftpConnectionPoint.getEncoding()));
      if (index >= 0) {
        encodingCombo.select(index);
      }
    } finally {
      addListeners();
    }
  }
示例#30
0
 /**
  * Compiles a single source code unit.
  *
  * @param newRepo
  * @param source
  * @param baseDestination
  * @param mode
  * @param deferred
  * @param problemTracker
  * @throws CoreException
  */
 private boolean compileUnit(
     IRepository newRepo,
     final IFileStore source,
     int mode,
     IReferenceTracker refTracker,
     final IProblemTracker problemTracker,
     IProgressMonitor monitor)
     throws CoreException {
   if (monitor.isCanceled()) throw new OperationCanceledException();
   if (!source.fetchInfo().exists()) return false;
   Assert.isLegal(!source.fetchInfo().isDirectory());
   ICompiler compiler =
       findCompiler(source, newRepo.getProperties().getProperty(IRepository.DEFAULT_LANGUAGE));
   if (compiler == null) return false;
   // TODO need to provide a way for receiving the encoding to be used
   // (IResource has that)
   monitor.beginTask("Compiling " + source.toURI().getPath(), 1);
   Reader contents = null;
   try {
     contents =
         new InputStreamReader(
             new BufferedInputStream(source.openInputStream(EFS.NONE, null), 8192));
     compiler.compile(
         contents,
         new CompilationContext(
             refTracker,
             new LocalProblemTracker(problemTracker, source),
             newRepo,
             (mode & DEBUG) != 0));
   } catch (AbortedScopeCompilationException e) {
     // continue with next source unit
   } finally {
     if (contents != null)
       try {
         contents.close();
       } catch (IOException e) {
         // we don't care about these
       }
     monitor.done();
   }
   // we compiled this unit
   return true;
 }