Example usage for org.eclipse.jdt.core.search TypeNameMatch getFullyQualifiedName

List of usage examples for org.eclipse.jdt.core.search TypeNameMatch getFullyQualifiedName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search TypeNameMatch getFullyQualifiedName.

Prototype

public String getFullyQualifiedName() 

Source Link

Document

Returns the matched type's fully qualified name using '.'

Usage

From source file:com.curlap.orb.plugin.common.JavaElementSearcher.java

License:Open Source License

protected TypeNameMatch maskPackageNames(List<TypeNameMatch> foundMatches) {
    List<TypeNameMatch> candidates = new ArrayList<TypeNameMatch>();
    TypeNameMatch currentPackage = null;

    // picking priority:
    //  Consider 3 Hoge classes exist in:
    //    com.curlap.a.Hoge
    //    com.curlap.b.Hoge
    //    com.curlap.c.Hoge
    //  And current target file is in com.curlap.a with using Hoge class in it.
    //  We pick Hoge's package in order of priority blow:
    //    1. import with the class name  e.g.) com.curlap.b.Hoge
    //    2. current package  e.g.) com.curlap.a
    //    3. import with *  e.g.) com.curlap.b.*
    for (TypeNameMatch match : foundMatches) {
        String matchPkgName = match.getPackageName();
        if (currentPackageName.equals(matchPkgName))
            currentPackage = match;//w ww  . j  a  v  a2 s.c  o m

        for (String maskPkgName : packageNamesForMask)
            if (maskPkgName.equals(match.getFullyQualifiedName()))
                return match;
            else if (maskPkgName.endsWith("*") & extractPackageName(maskPkgName).equals(matchPkgName))
                candidates.add(match);
    }
    if (currentPackage != null)
        return currentPackage;
    else if (!candidates.isEmpty())
        return candidates.get(0);
    else
        return null;
}

From source file:org.autorefactor.refactoring.rules.ReplaceQualifiedNamesBySimpleNamesRefactoring.java

License:Open Source License

private void importTypesFromPackage(final String pkgName, ASTNode node) {
    final TypeNameMatchRequestor importTypeCollector = new TypeNameMatchRequestor() {
        @Override/*w  w  w  . j  a  v  a 2s . c om*/
        public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
            final boolean isTopLevelType = typeNameMatch.getType().getDeclaringType() == null;
            if (isTopLevelType) {
                if (!pkgName.equals(typeNameMatch.getPackageName())) {
                    // sanity check failed
                    throw new IllegalStateException("Expected package '" + typeNameMatch.getPackageName()
                            + "' to be equal to '" + pkgName + "'");
                }
                QName qname = QName.valueOf(typeNameMatch.getFullyQualifiedName());
                types.addName(FQN.fromImport(qname, true));
            }
        }
    };

    SubMonitor monitor = SubMonitor.convert(ctx.getProgressMonitor(), 1);
    final SubMonitor childMonitor = monitor.newChild(1);
    try {
        final SearchEngine searchEngine = new SearchEngine();
        searchEngine.searchAllTypeNames(pkgName.toCharArray(), R_EXACT_MATCH, // search in this package
                null, R_EXACT_MATCH, // do not filter by type name
                TYPE, // look for all java types (class, interfaces, enums, etc.)
                createWorkspaceScope(), // search everywhere
                importTypeCollector, WAIT_UNTIL_READY_TO_SEARCH, // wait in case the indexer is indexing
                childMonitor);
    } catch (JavaModelException e) {
        throw new UnhandledException(node, e);
    } finally {
        childMonitor.done();
    }
}

From source file:org.autorefactor.refactoring.rules.SimpleNameRatherThanQualifiedNameRefactoring.java

License:Open Source License

private void importTypesFromPackage(final String pkgName, ASTNode node) {
    final TypeNameMatchRequestor importTypeCollector = new TypeNameMatchRequestor() {
        @Override/*w w  w.j av  a 2  s  .c  o  m*/
        public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
            final boolean isTopLevelType = typeNameMatch.getType().getDeclaringType() == null;
            if (isTopLevelType) {
                if (!pkgName.equals(typeNameMatch.getPackageName())) {
                    // sanity check failed
                    throw new IllegalStateException("Expected package '" + typeNameMatch.getPackageName()
                            + "' to be equal to '" + pkgName + "'");
                }
                QName qname = QName.valueOf(typeNameMatch.getFullyQualifiedName());
                types.addName(FQN.fromImport(qname, true));
            }
        }
    };

    try {
        final SearchEngine searchEngine = new SearchEngine();
        searchEngine.searchAllTypeNames(pkgName.toCharArray(), R_EXACT_MATCH, // search in this package
                null, R_EXACT_MATCH, // do not filter by type name
                TYPE, // look for all java types (class, interfaces, enums, etc.)
                createWorkspaceScope(), // search everywhere
                importTypeCollector, WAIT_UNTIL_READY_TO_SEARCH, // wait in case the indexer is indexing
                ctx.getProgressMonitor());
    } catch (JavaModelException e) {
        throw new UnhandledException(node, e);
    }
}

From source file:org.codehaus.groovy.eclipse.refactoring.actions.TypeSearch.java

License:Apache License

/**
 * Use a SearchEngine to look for the types
 * This will not find inner types, however
 *
 * @see OrganizeImportsOperation.TypeReferenceProcessor#process(org.eclipse.core.runtime.IProgressMonitor)
 * @param missingType/*from  w w w  .  j a v  a2  s.  c  o m*/
 * @throws JavaModelException
 */
public void searchForTypes(GroovyCompilationUnit unit,
        Map<String, OrganizeGroovyImports.UnresolvedTypeData> missingTypes) throws JavaModelException {
    char[][] allTypes = new char[missingTypes.size()][];
    int i = 0;
    for (String simpleName : missingTypes.keySet()) {
        allTypes[i++] = simpleName.toCharArray();
    }
    final List<TypeNameMatch> typesFound = new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector collector = new TypeNameMatchCollector(typesFound);
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { unit.getJavaProject() });
    new SearchEngine().searchAllTypeNames(null, allTypes, scope, collector,
            IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);

    for (TypeNameMatch match : typesFound) {
        UnresolvedTypeData data = missingTypes.get(match.getSimpleTypeName());
        if (data == null) {
            GroovyCore.logException(
                    "GRECLIPSE-735: Match not found in missing types: " + match.getFullyQualifiedName(),
                    new Exception());
            continue;
        }
        if (isOfKind(match, data.isAnnotation)) {
            data.addInfo(match);
        }
    }
}

From source file:org.eclipse.ajdt.internal.corext.util.OpenTypeHistory.java

License:Open Source License

public synchronized TypeNameMatch[] getFilteredTypeInfos(TypeInfoFilter filter) {
    Collection values = getValues();
    List result = new ArrayList();
    for (Iterator iter = values.iterator(); iter.hasNext();) {
        TypeNameMatch type = (TypeNameMatch) iter.next();
        if ((filter == null || filter.matchesHistoryElement(type))
                && !TypeFilter.isFiltered(type.getFullyQualifiedName()))
            result.add(type);// w  w  w  .j  a v  a 2  s  . c om
    }
    Collections.reverse(result);
    return (TypeNameMatch[]) result.toArray(new TypeNameMatch[result.size()]);

}

From source file:org.eclipse.ajdt.internal.ui.dialogs.TypeSelectionDialog2.java

License:Open Source License

protected void computeResult() {
    TypeNameMatch[] selected = fContent.getSelection();
    if (selected == null || selected.length == 0) {
        setResult(null);/* w w  w . ja v  a 2s  .c o m*/
        return;
    }

    // If the scope is null then it got computed by the type selection component.
    if (fScope == null) {
        fScope = fContent.getScope();
    }

    OpenTypeHistory history = OpenTypeHistory.getInstance();
    List result = new ArrayList(selected.length);
    for (int i = 0; i < selected.length; i++) {
        TypeNameMatch typeInfo = selected[i];
        IType type = typeInfo.getType();
        if (type == null) {
            String title = JavaUIMessages.TypeSelectionDialog_errorTitle;
            String message = Messages.format(JavaUIMessages.TypeSelectionDialog_dialogMessage,
                    typeInfo.getFullyQualifiedName());
            MessageDialog.openError(getShell(), title, message);
            history.remove(typeInfo);
            setResult(null);
        } else {
            history.accessed(typeInfo);
            result.add(type);
        }
    }
    setResult(result);
}

From source file:org.eclipse.ajdt.internal.ui.editor.actions.AJOrganizeImportsOperation.java

License:Open Source License

/**
 * Runs the operation./*from w  w w. j a v  a2  s  .c  om*/
 * @throws OperationCanceledException Runtime error thrown when operation is canceled.
 */
public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    try {
        fNumberOfImportsAdded = 0;
        fNumberOfImportsRemoved = 0;

        monitor.beginTask(Messages.format(CodeGenerationMessages.OrganizeImportsOperation_description,
                fCompilationUnit.getElementName()), 10);

        CompilationUnit astRoot = fASTRoot;
        if (astRoot == null) {
            astRoot = SharedASTProvider.getAST(fCompilationUnit, SharedASTProvider.WAIT_YES,
                    new SubProgressMonitor(monitor, 2));
        } else {
            monitor.worked(2);
        }

        ImportRewrite importsRewrite = StubUtility.createImportRewrite(astRoot, false);

        Set<String> oldSingleImports = new HashSet<String>();
        Set<String> oldDemandImports = new HashSet<String>();
        List<SimpleName> typeReferences = new ArrayList<SimpleName>();
        List<SimpleName> staticReferences = new ArrayList<SimpleName>();

        if (!collectReferences(astRoot, typeReferences, staticReferences, oldSingleImports, oldDemandImports)) {
            return;
        }

        monitor.worked(1);

        TypeReferenceProcessor processor = new TypeReferenceProcessor(oldSingleImports, oldDemandImports,
                astRoot, importsRewrite, fIgnoreLowerCaseNames);

        Iterator<SimpleName> refIterator = typeReferences.iterator();
        while (refIterator.hasNext()) {
            SimpleName typeRef = refIterator.next();
            processor.add(typeRef);
        }

        boolean hasOpenChoices = processor.process(new SubProgressMonitor(monitor, 3));
        addStaticImports(staticReferences, importsRewrite);

        if (hasOpenChoices && fChooseImportQuery != null) {
            TypeNameMatch[][] choices = processor.getChoices();
            ISourceRange[] ranges = processor.getChoicesSourceRanges();
            TypeNameMatch[] chosen = fChooseImportQuery.chooseImports(choices, ranges);
            if (chosen == null) {
                // cancel pressed by the user
                throw new OperationCanceledException();
            }
            for (int i = 0; i < chosen.length; i++) {
                TypeNameMatch typeInfo = chosen[i];
                importsRewrite.addImport(typeInfo.getFullyQualifiedName());
            }
        }

        TextEdit edit = importsRewrite.rewriteImports(new SubProgressMonitor(monitor, 3));
        JavaModelUtil.applyEdit(fCompilationUnit, edit, fDoSave, new SubProgressMonitor(monitor, 1));

        determineImportDifferences(importsRewrite, oldSingleImports, oldDemandImports);
        processor = null;
    } finally {
        monitor.done();
    }
}

From source file:org.eclipse.jst.jsp.ui.internal.handlers.AddImportHandler.java

License:Open Source License

private void addImport(TypeNameMatch match, IDocument document) {
    if (match != null) {
        new PageImport(match.getFullyQualifiedName()).add(document);
    }// ww w.j a v  a  2 s. c om
}

From source file:org.flowerplatform.editor.model.java.JavaTypeNameRequestor.java

License:Open Source License

@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
    String fullyQualifiedName = match.getFullyQualifiedName();
    String simpleName = match.getSimpleTypeName();
    String pck = match.getPackageName();
    String containerType = match.getTypeContainerName();
    if (containerType.length() > 0) {
        pck = containerType;/* w  w  w.j a  v a2  s.  co m*/
    }
    String iconUrl = getIconUrl(match.getType());
    ContentAssistItem item = new ContentAssistItem(fullyQualifiedName, simpleName, pck, iconUrl);
    matches.add(item);

    if (matches.size() == IContentAssist.MAX_TYPES_COUNT) {
        progressMonitor.setCanceled(true);
    }
}