Java 类org.eclipse.jdt.core.search.TypeNameMatch 实例源码

项目:egradle    文件:JDTDataAccess.java   
/**
 * Find type
 * 
 * @param className
 * @param monitor
 * @return type or <code>null</code>
 */
public IType findType(String className, IProgressMonitor monitor) {
    final IType[] result = { null };
    TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() {
        @Override
        public void acceptTypeNameMatch(TypeNameMatch match) {
            result[0] = match.getType();
        }
    };
    int lastDot = className.lastIndexOf('.');
    char[] packageName = lastDot >= 0 ? className.substring(0, lastDot).toCharArray() : null;
    char[] typeName = (lastDot >= 0 ? className.substring(lastDot + 1) : className).toCharArray();
    SearchEngine engine = new SearchEngine();
    int packageMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    try {
        engine.searchAllTypeNames(packageName, packageMatchRule, typeName, packageMatchRule, IJavaSearchConstants.TYPE,
                SearchEngine.createWorkspaceScope(), nameMatchRequestor,
                IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
    } catch (JavaModelException e) {
        EditorUtil.INSTANCE.logError("Was not able to search all type names",e);
    }
    return result[0];
}
项目:eclipse.jdt.ls    文件:OrganizeImportsOperation.java   
private boolean isVisible(TypeNameMatch curr) {
    int flags= curr.getModifiers();
    if (Flags.isPrivate(flags)) {
        return false;
    }
    boolean isPublic;
    try {
        isPublic= JdtFlags.isPublic(curr.getType());
    } catch (JavaModelException e) {
        isPublic= Flags.isPublic(flags);
    }
    if (isPublic || Flags.isProtected(flags)) {
        return true;
    }
    return curr.getPackageName().equals(fCurrPackage.getElementName());
}
项目:che    文件:TypeFilter.java   
public static boolean isFiltered(TypeNameMatch match) {
  boolean filteredByPattern = getDefault().filter(match.getFullyQualifiedName());
  if (filteredByPattern) return true;

  int accessibility = match.getAccessibility();
  switch (accessibility) {
    case IAccessRule.K_NON_ACCESSIBLE:
      return JavaCore.ENABLED.equals(
          JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK));
    case IAccessRule.K_DISCOURAGED:
      return JavaCore.ENABLED.equals(
          JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK));
    default:
      return false;
  }
}
项目:che    文件:JavaDebuggerUtils.java   
private List<IType> findTypeByFqn(char[][] packages, char[][] names, IJavaSearchScope scope)
    throws JavaModelException {
  List<IType> result = new ArrayList<>();

  SearchEngine searchEngine = new SearchEngine();
  searchEngine.searchAllTypeNames(
      packages,
      names,
      scope,
      new TypeNameMatchRequestor() {
        @Override
        public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
          result.add(typeNameMatch.getType());
        }
      },
      IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
      new NullProgressMonitor());
  return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeContextChecker.java   
private static List<TypeNameMatch> findTypeInfos(String typeName, IType contextType, IProgressMonitor pm) throws JavaModelException {
    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaProject[]{contextType.getJavaProject()}, true);
    IPackageFragment currPackage= contextType.getPackageFragment();
    ArrayList<TypeNameMatch> collectedInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(collectedInfos);
    int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, typeName.toCharArray(), matchMode, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, pm);

    List<TypeNameMatch> result= new ArrayList<TypeNameMatch>();
    for (Iterator<TypeNameMatch> iter= collectedInfos.iterator(); iter.hasNext();) {
        TypeNameMatch curr= iter.next();
        IType type= curr.getType();
        if (type != null) {
            boolean visible=true;
            try {
                visible= JavaModelUtil.isVisible(type, currPackage);
            } catch (JavaModelException e) {
                //Assume visibile if not available
            }
            if (visible) {
                result.add(curr);
            }
        }
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SuperInterfaceSelectionDialog.java   
private void addSelectedInterfaces() {
    StructuredSelection selection= getSelectedItems();
    if (selection == null)
        return;
    for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
        Object obj= iter.next();
        if (obj instanceof TypeNameMatch) {
            accessedHistoryItem(obj);
            TypeNameMatch type= (TypeNameMatch) obj;
            String qualifiedName= getNameWithTypeParameters(type.getType());
            String message;

            if (fTypeWizardPage.addSuperInterface(qualifiedName)) {
                message= Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfaceadded_info, BasicElementLabels.getJavaElementName(qualifiedName));
            } else {
                message= Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfacealreadyadded_info, BasicElementLabels.getJavaElementName(qualifiedName));
            }
            updateStatus(new StatusInfo(IStatus.INFO, message));
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeInfoViewer.java   
private String getContainerName(TypeNameMatch type) {
    IPackageFragmentRoot root= type.getPackageFragmentRoot();
    if (root.isExternal()) {
        String name= root.getPath().toOSString();
        for (int i= 0; i < fInstallLocations.length; i++) {
            if (name.startsWith(fInstallLocations[i])) {
                return fVMNames[i];
            }
        }
        String lib= (String)fLib2Name.get(name);
        if (lib != null)
            return lib;
    }
    StringBuffer buf= new StringBuffer();
    JavaElementLabels.getPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED | JavaElementLabels.ROOT_VARIABLE, buf);
    return buf.toString();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AddImportsOperation.java   
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException {
    boolean is50OrHigher= JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());

    int typeKinds= SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }

    ArrayList<TypeNameMatch> typeInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(typeInfos);
    int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, simpleTypeName.toCharArray(), matchMode, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);

    ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i= 0, len= typeInfos.size(); i < len; i++) {
        TypeNameMatch curr= typeInfos.get(i);
        if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeInfoViewer.java   
private void addDashLineAndUpdateLastHistoryEntry(int ticket, final TypeNameMatch next) {
    syncExec(ticket, new Runnable() {
        public void run() {
            if (fNextElement > 0) {
                TableItem item= fTable.getItem(fNextElement - 1);
                String label= item.getText();
                String newLabel= fLabelProvider.getText(null, (TypeNameMatch)item.getData(), next);
                if (newLabel.length() != label.length())
                    item.setText(newLabel);
                if (fLastSelection != null && fLastSelection.length > 0) {
                    TableItem last= fLastSelection[fLastSelection.length - 1];
                    if (last == item) {
                        fLastLabels[fLastLabels.length - 1]= newLabel;
                    }
                }
            }
            fDashLineIndex= fNextElement;
            addDashLine();
        }
    });
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TypeContextChecker.java   
private static List<TypeNameMatch> findTypeInfos(String typeName, IType contextType, IProgressMonitor pm) throws JavaModelException {
    IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaProject[]{contextType.getJavaProject()}, true);
    IPackageFragment currPackage= contextType.getPackageFragment();
    ArrayList<TypeNameMatch> collectedInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(collectedInfos);
    int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, typeName.toCharArray(), matchMode, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, pm);

    List<TypeNameMatch> result= new ArrayList<TypeNameMatch>();
    for (Iterator<TypeNameMatch> iter= collectedInfos.iterator(); iter.hasNext();) {
        TypeNameMatch curr= iter.next();
        IType type= curr.getType();
        if (type != null) {
            boolean visible=true;
            try {
                visible= JavaModelUtil.isVisible(type, currPackage);
            } catch (JavaModelException e) {
                //Assume visibile if not available
            }
            if (visible) {
                result.add(curr);
            }
        }
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:FilteredTypesSelectionDialog.java   
@Override
protected IStatus validateItem(Object item) {

    if (item == null)
        return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, "", null); //$NON-NLS-1$

    if (fValidator != null) {
        IType type= ((TypeNameMatch) item).getType();
        if (!type.exists()) {
            String qualifiedName= TypeNameMatchLabelProvider.getText((TypeNameMatch) item, TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED);
            return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, Messages.format(JavaUIMessages.FilteredTypesSelectionDialog_error_type_doesnot_exist, qualifiedName), null);
        }
        Object[] elements= { type };
        return fValidator.validate(elements);
    } else
        return Status.OK_STATUS;
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeInfoFilter.java   
private boolean matchesModifiers(TypeNameMatch type) {
    if (fElementKind == IJavaSearchConstants.TYPE)
        return true;
    int modifiers= type.getModifiers() & TYPE_MODIFIERS;
    switch (fElementKind) {
        case IJavaSearchConstants.CLASS:
            return modifiers == 0;
        case IJavaSearchConstants.ANNOTATION_TYPE:
            return Flags.isAnnotation(modifiers);
        case IJavaSearchConstants.INTERFACE:
            return modifiers == Flags.AccInterface;
        case IJavaSearchConstants.ENUM:
            return Flags.isEnum(modifiers);
        case IJavaSearchConstants.CLASS_AND_INTERFACE:
            return modifiers == 0 || modifiers == Flags.AccInterface;
        case IJavaSearchConstants.CLASS_AND_ENUM:
            return modifiers == 0 || Flags.isEnum(modifiers);
        case IJavaSearchConstants.INTERFACE_AND_ANNOTATION:
            return Flags.isInterface(modifiers);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaContext.java   
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor, ICompilationUnit cu) throws JavaModelException {
    boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject());

    int typeKinds= SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }

    ArrayList<TypeNameMatch> typeInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(typeInfos);
    new SearchEngine().searchAllTypeNames(null, 0, simpleTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, monitor);

    ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i= 0, len= typeInfos.size(); i < len; i++) {
        TypeNameMatch curr= typeInfos.get(i);
        if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr, cu)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TypeInfoViewer.java   
private void internalRunVirtual(ProgressMonitor monitor) throws CoreException, InterruptedException {
    if (monitor.isCanceled())
        throw new OperationCanceledException();

    fViewer.clear(fTicket);

    TypeNameMatch[] matchingTypes= fHistory.getFilteredTypeInfos(fFilter);
    fViewer.setHistoryResult(fTicket, matchingTypes);
    if ((fMode & INDEX) == 0)
        return;

    Set filteredMatches= new HashSet(matchingTypes.length * 2);
    for (int i= 0; i < matchingTypes.length; i++) {
        filteredMatches.add(matchingTypes[i]);
    }

    TypeNameMatch[] result= getSearchResult(filteredMatches, monitor);
    if (monitor.isCanceled())
        throw new OperationCanceledException();

    fViewer.setSearchResult(fTicket, result);
}
项目:Eclipse-Postfix-Code-Completion    文件:AddImportsOperation.java   
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException {
    boolean is50OrHigher= JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());

    int typeKinds= SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }

    ArrayList<TypeNameMatch> typeInfos= new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor= new TypeNameMatchCollector(typeInfos);
    int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, simpleTypeName.toCharArray(), matchMode, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);

    ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i= 0, len= typeInfos.size(); i < len; i++) {
        TypeNameMatch curr= typeInfos.get(i);
        if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TypeInfoViewer.java   
@Override
protected TypeNameMatch[] getSearchResult(Set filteredHistory, ProgressMonitor monitor) throws CoreException {
    List result= new ArrayList(2048);
    for (int i= 0; i < fLastResult.length; i++) {
        TypeNameMatch type= fLastResult[i];
        if (filteredHistory.contains(type))
            continue;
        if (fFilter.matchesCachedResult(type))
            result.add(type);
    }
    // we have to sort if the filter is a camel case filter.
    TypeNameMatch[] types= (TypeNameMatch[])result.toArray(new TypeNameMatch[result.size()]);
    if (fFilter.isCamelCasePattern()) {
        Arrays.sort(types, new TypeInfoComparator(fLabelProvider, fFilter));
    }
    return types;
}
项目:Eclipse-Postfix-Code-Completion    文件:FilteredTypesSelectionDialog.java   
@Override
protected void setResult(List newResult) {

    List<IType> resultToReturn= new ArrayList<IType>();

    for (int i= 0; i < newResult.size(); i++) {
        if (newResult.get(i) instanceof TypeNameMatch) {
            IType type= ((TypeNameMatch) newResult.get(i)).getType();
            if (type.exists()) {
                // items are added to history in the
                // org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#computeResult()
                // method
                resultToReturn.add(type);
            } else {
                TypeNameMatch typeInfo= (TypeNameMatch) newResult.get(i);
                IPackageFragmentRoot root= typeInfo.getPackageFragmentRoot();
                String containerName= JavaElementLabels.getElementLabel(root, JavaElementLabels.ROOT_QUALIFIED);
                String message= Messages.format(JavaUIMessages.FilteredTypesSelectionDialog_dialogMessage, new String[] { TypeNameMatchLabelProvider.getText(typeInfo, TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED), containerName });
                MessageDialog.openError(getShell(), fTitle, message);
                getSelectionHistory().remove(typeInfo);
            }
        }
    }

    super.setResult(resultToReturn);
}
项目:Eclipse-Postfix-Code-Completion    文件:FilteredTypesSelectionDialog.java   
@Override
public String getText(Object element) {
    if (!(element instanceof TypeNameMatch)) {
        return super.getText(element);
    }
    TypeNameMatch typeMatch= (TypeNameMatch) element;
    if (fContainerInfo && isDuplicateElement(element)) {
        return BasicElementLabels.getJavaElementName(fTypeInfoUtil.getFullyQualifiedText(typeMatch));
    }

    if (!fContainerInfo && isDuplicateElement(element)) {
        return BasicElementLabels.getJavaElementName(fTypeInfoUtil.getQualifiedText(typeMatch));
    }

    return BasicElementLabels.getJavaElementName(typeMatch.getSimpleTypeName());
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TypeInfoFilter.java   
private boolean matchesModifiers(TypeNameMatch type) {
    if (fElementKind == IJavaSearchConstants.TYPE)
        return true;
    int modifiers= type.getModifiers() & TYPE_MODIFIERS;
    switch (fElementKind) {
        case IJavaSearchConstants.CLASS:
            return modifiers == 0;
        case IJavaSearchConstants.ANNOTATION_TYPE:
            return Flags.isAnnotation(modifiers);
        case IJavaSearchConstants.INTERFACE:
            return modifiers == Flags.AccInterface;
        case IJavaSearchConstants.ENUM:
            return Flags.isEnum(modifiers);
        case IJavaSearchConstants.CLASS_AND_INTERFACE:
            return modifiers == 0 || modifiers == Flags.AccInterface;
        case IJavaSearchConstants.CLASS_AND_ENUM:
            return modifiers == 0 || Flags.isEnum(modifiers);
        case IJavaSearchConstants.INTERFACE_AND_ANNOTATION:
            return Flags.isInterface(modifiers);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:FilteredTypesSelectionDialog.java   
private String getContainerName(TypeNameMatch type) {
    IPackageFragmentRoot root= type.getPackageFragmentRoot();
    if (root.isExternal()) {
        String name= root.getPath().toOSString();
        for (int i= 0; i < fInstallLocations.length; i++) {
            if (name.startsWith(fInstallLocations[i])) {
                return fVMNames[i];
            }
        }
        String lib= fLib2Name.get(name);
        if (lib != null)
            return lib;
    }
    StringBuffer buf= new StringBuffer();
    JavaElementLabels.getPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED | JavaElementLabels.ROOT_VARIABLE, buf);
    return buf.toString();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TypeInfoViewer.java   
private void setData(TableItem item) {
    int index= fTable.indexOf(item);
    TypeNameMatch type= getTypeInfo(index);
    if (type == DASH_LINE) {
        item.setData(fDashLine);
        fillDashLine(item);
    } else {
        item.setData(type);
        item.setImage(fImageManager.get(fLabelProvider.getImageDescriptor(type)));
        item.setText(fLabelProvider.getText(
            getTypeInfo(index - 1),
            type,
            getTypeInfo(index + 1)));
        item.setForeground(null);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:FilteredTypesSelectionDialog.java   
public int compare(TypeNameMatch leftInfo, TypeNameMatch rightInfo) {
    int result= compareName(leftInfo.getSimpleTypeName(), rightInfo.getSimpleTypeName());
    if (result != 0)
        return result;

    result= compareDeprecation(leftInfo.getModifiers(), rightInfo.getModifiers());
    if (result != 0)
        return result;

    result= compareTypeContainerName(leftInfo.getTypeContainerName(), rightInfo.getTypeContainerName());
    if (result != 0)
        return result;

    int leftCategory= getElementTypeCategory(leftInfo);
    int rightCategory= getElementTypeCategory(rightInfo);
    if (leftCategory < rightCategory)
        return -1;
    if (leftCategory > rightCategory)
        return +1;
    return compareContainerName(leftInfo, rightInfo);
}
项目:eclipse.jdt.ls    文件:OrganizeImportsOperation.java   
public void addInfo(TypeNameMatch info) {
    for (int i= this.foundInfos.size() - 1; i >= 0; i--) {
        TypeNameMatch curr= this.foundInfos.get(i);
        if (curr.getTypeContainerName().equals(info.getTypeContainerName())) {
            return; // not added. already contains type with same name
        }
    }
    foundInfos.add(info);
}
项目:eclipse.jdt.ls    文件:OrganizeImportsOperation.java   
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
    int flags= curr.getModifiers();
    if (Flags.isAnnotation(flags)) {
        return is50OrHigher && (typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0;
    }
    if (Flags.isEnum(flags)) {
        return is50OrHigher && (typeKinds & SimilarElementsRequestor.ENUMS) != 0;
    }
    if (Flags.isInterface(flags)) {
        return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
    }
    return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
}
项目:eclipse.jdt.ls    文件:ClassFileUtil.java   
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
    try {
        if (match.getType().isBinary()) {
            Location location = JDTUtils.toLocation(match.getType().getClassFile());
            if (location != null) {
                uri = location.getUri();
            }
        }  else {
            uri = match.getType().getResource().getLocationURI().toString();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:che    文件:CodeAssist.java   
private OrganizeImportResult createOrganizeImportOperation(
    ICompilationUnit compilationUnit, List<String> chosen) throws CoreException {
  CodeGenerationSettings settings =
      JavaPreferencesSettings.getCodeGenerationSettings(compilationUnit.getJavaProject());

  OrganizeImportsOperation operation =
      new OrganizeImportsOperation(
          compilationUnit,
          null,
          settings.importIgnoreLowercase,
          !compilationUnit.isWorkingCopy(),
          true,
          chosen,
          null);

  NullProgressMonitor monitor = new NullProgressMonitor();
  TextEdit edit = operation.createTextEdit(monitor);
  OrganizeImportResult result = DtoFactory.newDto(OrganizeImportResult.class);
  TypeNameMatch[][] choices = operation.getChoices();
  // Apply organize import declarations if operation doesn't have conflicts (choices.length == 0)
  // or all conflicts were resolved (!chosen.isEmpty())
  if ((chosen != null && !chosen.isEmpty()) || choices == null || choices.length == 0) {
    IBuffer buffer = compilationUnit.getBuffer();
    IDocument document = new Document(buffer.getContents());
    DocumentChangeListener documentChangeListener = new DocumentChangeListener(document);
    try {
      edit.apply(document);
    } catch (BadLocationException e) {
      LOG.debug("Applying Organize import text edits goes wrong:", e);
    }
    result.setChanges(documentChangeListener.getChanges());
    return result;
  }

  result.setConflicts(createListOfDTOMatches(choices));
  return result;
}
项目:che    文件:CodeAssist.java   
private List<ConflictImportDTO> createListOfDTOMatches(TypeNameMatch[][] choices) {
  List<ConflictImportDTO> typeMatches = new ArrayList<>();
  for (int i = 0; i < choices.length; i++) {
    List<String> nameMatches = new ArrayList<>();
    TypeNameMatch[] choice = choices[i];
    for (int j = 0; j < choice.length; j++) {
      nameMatches.add(choice[j].getFullyQualifiedName());
    }
    typeMatches.add(DtoFactory.newDto(ConflictImportDTO.class).withTypeMatches(nameMatches));
  }
  return typeMatches;
}
项目:che    文件:ImportOrganizeTest.java   
protected IChooseImportQuery createQuery(
    final String name, final String[] choices, final int[] nEntries) {
  return new IChooseImportQuery() {
    public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
      assertTrue(name + "-query-nchoices1", choices.length == openChoices.length);
      assertTrue(name + "-query-nchoices2", nEntries.length == openChoices.length);
      for (int i = 0; i < nEntries.length; i++) {
        assertTrue(name + "-query-cnt" + i, openChoices[i].length == nEntries[i]);
      }
      TypeNameMatch[] res = new TypeNameMatch[openChoices.length];
      for (int i = 0; i < openChoices.length; i++) {
        TypeNameMatch[] selection = openChoices[i];
        assertNotNull(name + "-query-setset" + i, selection);
        assertTrue(name + "-query-setlen" + i, selection.length > 0);
        TypeNameMatch found = null;
        for (int k = 0; k < selection.length; k++) {
          if (selection[k].getFullyQualifiedName().equals(choices[i])) {
            found = selection[k];
          }
        }
        assertNotNull(name + "-query-notfound" + i, found);
        res[i] = found;
      }
      return res;
    }
  };
}
项目:che    文件:JavaContext.java   
private TypeNameMatch[] findAllTypes(
    String simpleTypeName,
    IJavaSearchScope searchScope,
    SimpleName nameNode,
    IProgressMonitor monitor,
    ICompilationUnit cu)
    throws JavaModelException {
  boolean is50OrHigher = JavaModelUtil.is50OrHigher(cu.getJavaProject());

  int typeKinds = SimilarElementsRequestor.ALL_TYPES;
  if (nameNode != null) {
    typeKinds = ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
  }

  ArrayList<TypeNameMatch> typeInfos = new ArrayList<TypeNameMatch>();
  TypeNameMatchCollector requestor = new TypeNameMatchCollector(typeInfos);
  new SearchEngine()
      .searchAllTypeNames(
          null,
          0,
          simpleTypeName.toCharArray(),
          SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
          getSearchForConstant(typeKinds),
          searchScope,
          requestor,
          IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH,
          monitor);

  ArrayList<TypeNameMatch> typeRefsFound = new ArrayList<TypeNameMatch>(typeInfos.size());
  for (int i = 0, len = typeInfos.size(); i < len; i++) {
    TypeNameMatch curr = typeInfos.get(i);
    if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
      if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr, cu)) {
        typeRefsFound.add(curr);
      }
    }
  }
  return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:che    文件:JavaContext.java   
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
  int flags = curr.getModifiers();
  if (Flags.isAnnotation(flags)) {
    return is50OrHigher && ((typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0);
  }
  if (Flags.isEnum(flags)) {
    return is50OrHigher && ((typeKinds & SimilarElementsRequestor.ENUMS) != 0);
  }
  if (Flags.isInterface(flags)) {
    return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
  }
  return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
}
项目:che    文件:JavaContext.java   
private boolean isVisible(TypeNameMatch curr, ICompilationUnit cu) {
  int flags = curr.getModifiers();
  if (Flags.isPrivate(flags)) {
    return false;
  }
  if (Flags.isPublic(flags) || Flags.isProtected(flags)) {
    return true;
  }
  return curr.getPackageName().equals(cu.getParent().getElementName());
}
项目:che    文件:OrganizeImportsOperation.java   
public void addInfo(TypeNameMatch info) {
  for (int i = this.foundInfos.size() - 1; i >= 0; i--) {
    TypeNameMatch curr = this.foundInfos.get(i);
    if (curr.getTypeContainerName().equals(info.getTypeContainerName())) {
      return; // not added. already contains type with same name
    }
  }
  foundInfos.add(info);
}
项目:che    文件:OrganizeImportsOperation.java   
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
  int flags = curr.getModifiers();
  if (Flags.isAnnotation(flags)) {
    return is50OrHigher && (typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0;
  }
  if (Flags.isEnum(flags)) {
    return is50OrHigher && (typeKinds & SimilarElementsRequestor.ENUMS) != 0;
  }
  if (Flags.isInterface(flags)) {
    return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
  }
  return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
}
项目:che    文件:OrganizeImportsOperation.java   
private boolean isVisible(TypeNameMatch curr) {
  int flags = curr.getModifiers();
  if (Flags.isPrivate(flags)) {
    return false;
  }
  if (Flags.isPublic(flags) || Flags.isProtected(flags)) {
    return true;
  }
  return curr.getPackageName().equals(fCurrPackage.getElementName());
}
项目:che    文件:AddImportsOperation.java   
private TypeNameMatch[] findAllTypes(
    String simpleTypeName,
    IJavaSearchScope searchScope,
    SimpleName nameNode,
    IProgressMonitor monitor)
    throws JavaModelException {
  boolean is50OrHigher = JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());

  int typeKinds = SimilarElementsRequestor.ALL_TYPES;
  if (nameNode != null) {
    typeKinds = ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
  }

  ArrayList<TypeNameMatch> typeInfos = new ArrayList<TypeNameMatch>();
  TypeNameMatchCollector requestor = new TypeNameMatchCollector(typeInfos);
  int matchMode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
  new SearchEngine()
      .searchAllTypeNames(
          null,
          matchMode,
          simpleTypeName.toCharArray(),
          matchMode,
          getSearchForConstant(typeKinds),
          searchScope,
          requestor,
          IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
          monitor);

  ArrayList<TypeNameMatch> typeRefsFound = new ArrayList<TypeNameMatch>(typeInfos.size());
  for (int i = 0, len = typeInfos.size(); i < len; i++) {
    TypeNameMatch curr = typeInfos.get(i);
    if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
      if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
        typeRefsFound.add(curr);
      }
    }
  }
  return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
项目:che    文件:AddImportsOperation.java   
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
  int flags = curr.getModifiers();
  if (Flags.isAnnotation(flags)) {
    return is50OrHigher && (typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0;
  }
  if (Flags.isEnum(flags)) {
    return is50OrHigher && (typeKinds & SimilarElementsRequestor.ENUMS) != 0;
  }
  if (Flags.isInterface(flags)) {
    return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
  }
  return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
}
项目:che    文件:AddImportsOperation.java   
private boolean isVisible(TypeNameMatch curr) {
  int flags = curr.getModifiers();
  if (Flags.isPrivate(flags)) {
    return false;
  }
  if (Flags.isPublic(flags) || Flags.isProtected(flags)) {
    return true;
  }
  return curr.getPackageName().equals(fCompilationUnit.getParent().getElementName());
}
项目:che    文件:TypeContextChecker.java   
private static List<TypeNameMatch> findTypeInfos(
    String typeName, IType contextType, IProgressMonitor pm) throws JavaModelException {
  IJavaSearchScope scope =
      SearchEngine.createJavaSearchScope(
          new IJavaProject[] {contextType.getJavaProject()}, true);
  IPackageFragment currPackage = contextType.getPackageFragment();
  ArrayList<TypeNameMatch> collectedInfos = new ArrayList<TypeNameMatch>();
  TypeNameMatchCollector requestor = new TypeNameMatchCollector(collectedInfos);
  int matchMode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
  new SearchEngine()
      .searchAllTypeNames(
          null,
          matchMode,
          typeName.toCharArray(),
          matchMode,
          IJavaSearchConstants.TYPE,
          scope,
          requestor,
          IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
          pm);

  List<TypeNameMatch> result = new ArrayList<TypeNameMatch>();
  for (Iterator<TypeNameMatch> iter = collectedInfos.iterator(); iter.hasNext(); ) {
    TypeNameMatch curr = iter.next();
    IType type = curr.getType();
    if (type != null) {
      boolean visible = true;
      try {
        visible = JavaModelUtil.isVisible(type, currPackage);
      } catch (JavaModelException e) {
        // Assume visibile if not available
      }
      if (visible) {
        result.add(curr);
      }
    }
  }
  return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeInfoViewer.java   
private int getCamelCaseCategory(TypeNameMatch type) {
    if (fFilter == null)
        return 0;
    if (!fFilter.isCamelCasePattern())
        return 0;
    return fFilter.matchesRawNamePattern(type) ? 0 : 1;
}
项目:Eclipse-Postfix-Code-Completion    文件:TypeInfoViewer.java   
private int getElementTypeCategory(TypeNameMatch type) {
    try {
        if (type.getPackageFragmentRoot().getKind() == IPackageFragmentRoot.K_SOURCE)
            return 0;
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return 1;
}