List of usage examples for org.eclipse.jdt.core.search TypeNameMatch getModifiers
public abstract int getModifiers();
From source file:org.codehaus.groovy.eclipse.refactoring.actions.TypeSearch.java
License:Apache License
/** * If looking for an annotation, then filter out non-annoations, * otherwise everything is acceptable.// ww w .j a v a2s .c om * * @param match * @param isAnnotation * @return */ protected boolean isOfKind(TypeNameMatch match, boolean isAnnotation) { return isAnnotation ? Flags.isAnnotation(match.getModifiers()) : true; }
From source file:org.eclipse.ajdt.internal.corext.util.OpenTypeHistory.java
License:Open Source License
private synchronized void internalCheckConsistency(IProgressMonitor monitor) throws OperationCanceledException { // Setting fNeedsConsistencyCheck is necessary here since // markAsInconsistent isn't synchronized. fNeedsConsistencyCheck = true;// www .j a v a 2s . co m List typesToCheck = new ArrayList(getKeys()); monitor.beginTask(CorextMessages.TypeInfoHistory_consistency_check, typesToCheck.size()); monitor.setTaskName(CorextMessages.TypeInfoHistory_consistency_check); for (Iterator iter = typesToCheck.iterator(); iter.hasNext();) { TypeNameMatch type = (TypeNameMatch) iter.next(); long currentTimestamp = getContainerTimestamp(type); Long lastTested = (Long) fTimestampMapping.get(type); if (lastTested != null && currentTimestamp != IResource.NULL_STAMP && currentTimestamp == lastTested.longValue() && !isContainerDirty(type)) continue; try { IType jType = type.getType(); if (jType == null || !jType.exists()) { remove(type); } else { // copy over the modifiers since they may have changed int modifiers = jType.getFlags(); if (modifiers != type.getModifiers()) { replace(type, SearchEngine.createTypeNameMatch(jType, modifiers)); } else { fTimestampMapping.put(type, new Long(currentTimestamp)); } } } catch (JavaModelException e) { remove(type); } if (monitor.isCanceled()) throw new OperationCanceledException(); monitor.worked(1); } monitor.done(); fNeedsConsistencyCheck = false; }
From source file:org.eclipse.ajdt.internal.corext.util.OpenTypeHistory.java
License:Open Source License
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 = (Long) fTimestampMapping.get(type); if (timestamp == null) { typeElement.setAttribute(NODE_TIMESTAMP, Long.toString(IResource.NULL_STAMP)); } else {//from ww w . ja v a 2 s . co m typeElement.setAttribute(NODE_TIMESTAMP, timestamp.toString()); } }
From source file:org.eclipse.jst.jsp.ui.internal.handlers.AddImportHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { final IEditorSite site = HandlerUtil.getActiveEditor(event).getEditorSite(); final ISelectionProvider provider = site.getSelectionProvider(); final ISelection selection = provider != null ? provider.getSelection() : null; if (selection instanceof IStructuredSelection && selection instanceof ITextSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; final int offset = ((ITextSelection) selection).getOffset(); final Object firstElement = structuredSelection.getFirstElement(); if (firstElement instanceof IDOMNode) { final IDOMModel model = ((IDOMNode) firstElement).getModel(); INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class); if (adapter != null) { JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument() .getAdapterFor(IJSPTranslation.class); final JSPTranslationExtension translation = translationAdapter.getJSPTranslation(); translation.reconcileCompilationUnit(); final ICompilationUnit cu = translation.getCompilationUnit(); CompilationUnit astRoot = SharedASTProvider.getAST(cu, SharedASTProvider.WAIT_YES, null); if (astRoot != null) { final ASTNode node = NodeFinder.perform(astRoot, translation.getJavaOffset(offset), 0); if (node != null) { SimpleName name = null; if (node.getNodeType() == ASTNode.SIMPLE_NAME) { name = (SimpleName) node; } else if (node.getNodeType() == ASTNode.QUALIFIED_NAME) { name = ((QualifiedName) node).getName(); }//from w w w. ja v a2 s . com if (name != null) { IBinding binding = name.resolveBinding(); if (binding instanceof ITypeBinding && (binding.getJavaElement() == null || !binding.getJavaElement().exists())) { // Look it up! ITypeBinding typeBinding = (ITypeBinding) binding; final IImportContainer importContainer = cu.getImportContainer(); if (!importContainer.getImport(typeBinding.getQualifiedName()).exists()) { final List typesFound = new ArrayList(); final TypeNameMatchRequestor collector = new TypeNameMatcher(typesFound); IJavaSearchScope scope = SearchEngine .createJavaSearchScope(new IJavaElement[] { cu.getJavaProject() }); final int mode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; try { new SearchEngine().searchAllTypeNames(null, mode, name.getIdentifier().toCharArray(), mode, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, collector, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); final int length = typesFound.size(); final List elements = new ArrayList(); for (int i = 0; i < length; i++) { final TypeNameMatch match = (TypeNameMatch) typesFound.get(i); final int modifiers = match.getModifiers(); if (!Flags.isPrivate(modifiers) && !Flags.isPackageDefault(modifiers)) { elements.add(match); } } TypeNameMatch match = null; // If there's only one match, insert it; otherwise, open the dialog to choose from the list if (elements.size() == 1) { match = (TypeNameMatch) elements.get(0); } else if (elements.size() > 1) { ElementListSelectionDialog dialog = new ElementListSelectionDialog( site.getShell(), LABEL_PROVIDER); dialog.setElements( elements.toArray(new TypeNameMatch[elements.size()])); dialog.setTitle(JSPUIMessages.AddImportHandler_title); dialog.setMessage(JSPUIMessages.AddImportHandler_label); if (dialog.open() == Window.OK) { final Object result = dialog.getFirstResult(); if (result instanceof TypeNameMatch) { match = (TypeNameMatch) result; } } } addImport(match, model.getStructuredDocument()); } catch (JavaModelException e) { Logger.logException("Exception while determining import.", e); //$NON-NLS-1$ } } } } } } } } } return null; }
From source file:org.eclipse.jst.jsp.ui.internal.java.views.TypeNameLabelProvider.java
License:Open Source License
private ImageDescriptor getImageDescriptor(TypeNameMatch match) { // TODO use isInner // final boolean isInner = match.getTypeContainerName().indexOf('.') != -1; final int modifiers = match.getModifiers(); ImageDescriptor desc = getTypeImageDescriptor(modifiers); int adornmentFlags = 0; if (Flags.isFinal(modifiers)) { adornmentFlags |= JavaElementImageDescriptor.FINAL; }/* ww w.ja va 2 s . c om*/ 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, BIG_SIZE); }