List of usage examples for org.eclipse.jdt.core.search TypeNameMatch getPackageName
public String getPackageName()
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 w w. j av 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:com.curlap.orb.plugin.generator.CurlClassGenerator.java
License:Open Source License
protected String addImportedPackageIfNecessary(Set<String> importPackages, String fullClassName) throws JavaModelException { String importedPackageName = CurlSpecUtil.marshalCurlPackage(fullClassName, true); if (importedPackageName != null) importPackages.add(importedPackageName.toUpperCase()); else {/*from w ww .j av a 2 s . c om*/ TypeNameMatch typeNameMatch = new JavaElementSearcher(iCompilationUnit).searchClassInfo(fullClassName); if (typeNameMatch != null) importPackages.add(typeNameMatch.getPackageName().toUpperCase()); } return CurlSpecUtil.getClassNameFromPackageName(fullClassName); }
From source file:com.curlap.orb.plugin.generator.CurlClassGenerator.java
License:Open Source License
protected String addImportedPackageIfNecessaryWithSignature(Set<String> importPackages, String fullClassName) throws JavaModelException { String importedPackageName = CurlSpecUtil.marshalCurlPackage(fullClassName, true); if (importedPackageName != null) importPackages.add(importedPackageName.toUpperCase()); else {/*from www. jav a 2s . c om*/ TypeNameMatch typeNameMatch = new JavaElementSearcher(iCompilationUnit) .searchClassInfoWithSignature(fullClassName); if (typeNameMatch != null) importPackages.add(typeNameMatch.getPackageName().toUpperCase()); } return CurlSpecUtil.getClassNameFromPackageName(fullClassName); }
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//from w w w . j a v a2 s . co 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)); } } }; 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 ww . ja va2 s . 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)); } } }; 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.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;/*from w w w . ja va 2 s .c om*/ } 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); } }