org.eclipse.jdt.core.search.TypeNameMatch Java Examples

The following examples show how to use org.eclipse.jdt.core.search.TypeNameMatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeInfoViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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();
		}
	});
}
 
Example #2
Source File: TypeContextChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: AbstractSuperTypeSelectionDialog.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Adds selected interfaces to the list.
 */
private void fillWizardPageWithSelectedTypes() {
	final StructuredSelection selection = getSelectedItems();
	if (selection == null) {
		return;
	}
	for (final Iterator<?> iter = selection.iterator(); iter.hasNext();) {
		final Object obj = iter.next();
		if (obj instanceof TypeNameMatch) {
			accessedHistoryItem(obj);
			final TypeNameMatch type = (TypeNameMatch) obj;
			final String qualifiedName = Utilities.getNameWithTypeParameters(type.getType());
			final String message;

			if (addTypeToWizardPage(this.typeWizardPage, qualifiedName)) {
				message = MessageFormat.format(Messages.AbstractSuperTypeSelectionDialog_2,
						TextProcessor.process(qualifiedName, JAVA_ELEMENT_DELIMITERS));
			} else {
				message = MessageFormat.format(Messages.AbstractSuperTypeSelectionDialog_3,
						TextProcessor.process(qualifiedName, JAVA_ELEMENT_DELIMITERS));
			}
			updateStatus(new StatusInfo(IStatus.INFO, message));
		}
	}
}
 
Example #4
Source File: TypeInfoViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public int compare(Object left, Object right) {
	TypeNameMatch leftInfo= (TypeNameMatch)left;
	TypeNameMatch rightInfo= (TypeNameMatch)right;
 	int leftCategory= getCamelCaseCategory(leftInfo);
 	int rightCategory= getCamelCaseCategory(rightInfo);
 	if (leftCategory < rightCategory)
 		return -1;
 	if (leftCategory > rightCategory)
 		return +1;
 	int result= compareName(leftInfo.getSimpleTypeName(), rightInfo.getSimpleTypeName());
 	if (result != 0)
 		return result;
 	result= compareTypeContainerName(leftInfo.getTypeContainerName(), rightInfo.getTypeContainerName());
 	if (result != 0)
 		return result;
 	
 	leftCategory= getElementTypeCategory(leftInfo);
 	rightCategory= getElementTypeCategory(rightInfo);
 	if (leftCategory < rightCategory)
 		return -1;
 	if (leftCategory > rightCategory)
 		return +1;
 	return compareContainerName(leftInfo, rightInfo);
}
 
Example #5
Source File: OriginalEditorSelector.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private SearchResult findTypesBySimpleName(String simpleTypeName, final boolean searchForSources) {
	final SearchResult result = new SearchResult();
	try {
		new SearchEngine().searchAllTypeNames(null, 0, // match all package names
				simpleTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
					IJavaSearchConstants.TYPE,
					SearchEngine.createWorkspaceScope(),
					new TypeNameMatchRequestor() {
						@Override
						public void acceptTypeNameMatch(TypeNameMatch match) {
							IPackageFragmentRoot fragmentRoot = match.getPackageFragmentRoot();
							boolean externalLib = fragmentRoot.isArchive() || fragmentRoot.isExternal();
							if (externalLib ^ searchForSources) {
								result.foundTypes.add(match.getType());
							}
						}
					}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, // wait for the jdt index to be ready
					new NullProgressMonitor());
	} catch (JavaModelException e) {
		logger.error(e.getMessage(), e);
	}
	return result;
}
 
Example #6
Source File: AddImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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()]);
}
 
Example #7
Source File: TypeFilter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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;
	}
}
 
Example #8
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example #9
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example #10
Source File: TypeInfoViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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();
}
 
Example #11
Source File: TypeInfoViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example #12
Source File: TypeInfoFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: JavaContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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()]);
}
 
Example #14
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getContainerName(TypeNameMatch type) {
	IPackageFragmentRoot root= type.getPackageFragmentRoot();
	if (root.isExternal()) {
		IPath path= root.getPath();
		for (int i= 0; i < fInstallLocations.length; i++) {
			if (fInstallLocations[i].isPrefixOf(path)) {
				return fVMNames[i];
			}
		}
		String lib= fLib2Name.get(path);
		if (lib != null)
			return lib;
	}
	StringBuffer buf= new StringBuffer();
	JavaElementLabels.getPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED | JavaElementLabels.ROOT_VARIABLE, buf);
	return buf.toString();
}
 
Example #15
Source File: TypeNameMatchLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ImageDescriptor getImageDescriptor(TypeNameMatch typeRef, int flags) {
	if (isSet(SHOW_TYPE_CONTAINER_ONLY, flags)) {
		if (typeRef.getPackageName().equals(typeRef.getTypeContainerName()))
			return JavaPluginImages.DESC_OBJS_PACKAGE;

		// XXX cannot check outer type for interface efficiently (5887)
		return JavaPluginImages.DESC_OBJS_CLASS;

	} else if (isSet(SHOW_PACKAGE_ONLY, flags)) {
		return JavaPluginImages.DESC_OBJS_PACKAGE;
	} else {
		boolean isInner= typeRef.getTypeContainerName().indexOf('.') != -1;
		int modifiers= typeRef.getModifiers();

		ImageDescriptor desc= JavaElementImageProvider.getTypeImageDescriptor(isInner, false, modifiers, false);
		int adornmentFlags= 0;
		if (Flags.isFinal(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.FINAL;
		}
		if (Flags.isAbstract(modifiers) && !Flags.isInterface(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (Flags.isStatic(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.STATIC;
		}
		if (Flags.isDeprecated(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.DEPRECATED;
		}

		return new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
	}
}
 
Example #16
Source File: OpenTypeHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private OpenTypeHistory() {
	super(FILENAME, NODE_ROOT, NODE_TYPE_INFO);
	fTimestampMapping= new HashMap<TypeNameMatch, Long>();
	fNeedsConsistencyCheck= true;
	load();
	fDeltaListener= new TypeHistoryDeltaListener();
	JavaCore.addElementChangedListener(fDeltaListener);
	fUpdateJob= new UpdateJob();
	// It is not necessary anymore that the update job has a rule since
	// markAsInconsistent isn't synchronized anymore. See bugs
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128399 and
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=135278
	// for details.
	fUpdateJob.setPriority(Job.SHORT);
}
 
Example #17
Source File: OrganizeImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example #18
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Image getImage(Object element) {
	if (!(element instanceof TypeNameMatch)) {
		return super.getImage(element);
	}
	ImageDescriptor contributedImageDescriptor= fTypeInfoUtil.getContributedImageDescriptor(element);
	if (contributedImageDescriptor == null) {
		return TypeNameMatchLabelProvider.getImage((TypeNameMatch) element, TypeNameMatchLabelProvider.SHOW_TYPE_ONLY);
	} else {
		return fImageManager.createImage(contributedImageDescriptor);
	}
}
 
Example #19
Source File: TypeFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
	}
}
 
Example #20
Source File: OpenTypeHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setAttributes(Object object, Element typeElement) {
	TypeNameMatch type= (TypeNameMatch) object;
	String handleId= type.getType().getHandleIdentifier();
	typeElement.setAttribute(NODE_HANDLE, handleId);
	typeElement.setAttribute(NODE_MODIFIERS, Integer.toString(type.getModifiers()));
	Long timestamp= fTimestampMapping.get(type);
	if (timestamp == null) {
		typeElement.setAttribute(NODE_TIMESTAMP, Long.toString(IResource.NULL_STAMP));
	} else {
		typeElement.setAttribute(NODE_TIMESTAMP, timestamp.toString());
	}
}
 
Example #21
Source File: OrganizeImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #22
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String getText(Object element) {
	if (element instanceof TypeNameMatch) {
		return BasicElementLabels.getJavaElementName(fTypeInfoUtil.getQualificationText((TypeNameMatch) element));
	}

	return super.getText(element);
}
 
Example #23
Source File: OrganizeImportsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TypeNameMatch[] doChooseImports(TypeNameMatch[][] openChoices, final ISourceRange[] ranges, final JavaEditor editor) {
	// remember selection
	ISelection sel= editor.getSelectionProvider().getSelection();
	TypeNameMatch[] result= null;
	ILabelProvider labelProvider= new TypeNameMatchLabelProvider(TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED);

	MultiElementListSelectionDialog dialog= new MultiElementListSelectionDialog(getShell(), labelProvider) {
		@Override
		protected void handleSelectionChanged() {
			super.handleSelectionChanged();
			// show choices in editor
			doListSelectionChanged(getCurrentPage(), ranges, editor);
		}
	};
	fIsQueryShowing= true;
	dialog.setTitle(ActionMessages.OrganizeImportsAction_selectiondialog_title);
	dialog.setMessage(ActionMessages.OrganizeImportsAction_selectiondialog_message);
	dialog.setElements(openChoices);
	dialog.setComparator(ORGANIZE_IMPORT_COMPARATOR);
	if (dialog.open() == Window.OK) {
		Object[] res= dialog.getResult();
		result= new TypeNameMatch[res.length];
		for (int i= 0; i < res.length; i++) {
			Object[] array= (Object[]) res[i];
			if (array.length > 0) {
				result[i]= (TypeNameMatch) array[0];
				QualifiedTypeNameHistory.remember(result[i].getFullyQualifiedName());
			}
		}
	}
	// restore selection
	if (sel instanceof ITextSelection) {
		ITextSelection textSelection= (ITextSelection) sel;
		editor.selectAndReveal(textSelection.getOffset(), textSelection.getLength());
	}
	fIsQueryShowing= false;
	return result;
}
 
Example #24
Source File: JavaContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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());
}
 
Example #25
Source File: JavaContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #26
Source File: ImportsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ICleanUpFix createCleanUp(final CompilationUnit cu, CodeGenerationSettings settings, boolean organizeImports, RefactoringStatus status) throws CoreException {
if (!organizeImports)
	return null;

final boolean hasAmbiguity[]= new boolean[] { false };
IChooseImportQuery query= new IChooseImportQuery() {
	public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
		hasAmbiguity[0]= true;
		return new TypeNameMatch[0];
	}
};

final ICompilationUnit unit= (ICompilationUnit)cu.getJavaElement();
OrganizeImportsOperation op= new OrganizeImportsOperation(unit, cu, settings.importIgnoreLowercase, false, false, query);
final TextEdit edit= op.createTextEdit(null);
if (hasAmbiguity[0]) {
	status.addInfo(Messages.format(ActionMessages.OrganizeImportsAction_multi_error_unresolvable, getLocationString(cu)));
}

if (op.getParseError() != null) {
	status.addInfo(Messages.format(ActionMessages.OrganizeImportsAction_multi_error_parse, getLocationString(cu)));
	return null;
}

if (edit == null || (edit instanceof MultiTextEdit && edit.getChildrenSize() == 0))
	return null;

return new ImportsFix(edit, unit, FixMessages.ImportsFix_OrganizeImports_Description);
  }
 
Example #27
Source File: TypeSelectionDialog2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void computeResult() {
	TypeNameMatch[] selected= fContent.getSelection();
	if (selected == null || selected.length == 0) {
		setResult(null);
		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.exists()) {
			String title= JavaUIMessages.TypeSelectionDialog_errorTitle; 
			IPackageFragmentRoot root= typeInfo.getPackageFragmentRoot();
			String containerName= JavaElementLabels.getElementLabel(root, JavaElementLabels.ROOT_QUALIFIED);
			String message= Messages.format(JavaUIMessages.TypeSelectionDialog_dialogMessage, new String[] { typeInfo.getFullyQualifiedName(), containerName }); 
			MessageDialog.openError(getShell(), title, message);
			history.remove(typeInfo);
			setResult(null);
		} else {
			history.accessed(typeInfo);
			result.add(type);
		}
	}
	setResult(result);
}
 
Example #28
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getQualifiedText(TypeNameMatch type) {
	StringBuffer result= new StringBuffer();
	result.append(type.getSimpleTypeName());
	String containerName= type.getTypeContainerName();
	result.append(JavaElementLabels.CONCAT_STRING);
	if (containerName.length() > 0) {
		result.append(containerName);
	} else {
		result.append(JavaUIMessages.FilteredTypesSelectionDialog_default_package);
	}
	return result.toString();
}
 
Example #29
Source File: OrganizeImportsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IChooseImportQuery createChooseImportQuery(final JavaEditor editor) {
	return new IChooseImportQuery() {
		public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
			return doChooseImports(openChoices, ranges, editor);
		}
	};
}
 
Example #30
Source File: OpenTypeHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public synchronized TypeNameMatch[] getTypeInfos() {
	Collection<Object> values= getValues();
	int size= values.size();
	TypeNameMatch[] result= new TypeNameMatch[size];
	int i= size - 1;
	for (Iterator<Object> iter= values.iterator(); iter.hasNext();) {
		result[i]= (TypeNameMatch)iter.next();
		i--;
	}
	return result;
}