Java Code Examples for org.eclipse.jdt.ui.SharedASTProvider#getAST()
The following examples show how to use
org.eclipse.jdt.ui.SharedASTProvider#getAST() .
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: QuickAssistLightBulbUpdater.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected void doPropertyChanged(String property) { if (property.equals(PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB)) { if (isSetInPreferences()) { ICompilationUnit cu= getCompilationUnit(); if (cu != null) { installSelectionListener(); Point point= fViewer.getSelectedRange(); CompilationUnit astRoot= SharedASTProvider.getAST(cu, SharedASTProvider.WAIT_ACTIVE_ONLY, null); if (astRoot != null) { doSelectionChanged(point.x, point.y, astRoot); } } } else { uninstallSelectionListener(); } } }
Example 2
Source File: NLSRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private NLSRefactoring(ICompilationUnit cu) { Assert.isNotNull(cu); fCu= cu; CompilationUnit astRoot= SharedASTProvider.getAST(fCu, SharedASTProvider.WAIT_YES, null); NLSHint nlsHint= new NLSHint(fCu, astRoot); fSubstitutions= nlsHint.getSubstitutions(); setAccessorClassName(nlsHint.getAccessorClassName()); setAccessorClassPackage(nlsHint.getAccessorClassPackage()); setIsEclipseNLS(detectIsEclipseNLS()); setResourceBundleName(nlsHint.getResourceBundleName()); setResourceBundlePackage(nlsHint.getResourceBundlePackage()); setSubstitutionPattern(DEFAULT_SUBST_PATTERN); String cuName= fCu.getElementName(); if (fIsEclipseNLS) setPrefix(cuName.substring(0, cuName.length() - 5) + "_"); // A.java -> A_ //$NON-NLS-1$ else setPrefix(cuName.substring(0, cuName.length() - 4)); // A.java -> A. }
Example 3
Source File: OverrideIndicatorManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Opens and reveals the defining method. */ public void open() { CompilationUnit ast= SharedASTProvider.getAST(fJavaElement, SharedASTProvider.WAIT_ACTIVE_ONLY, null); if (ast != null) { ASTNode node= ast.findDeclaringNode(fAstNodeKey); if (node instanceof MethodDeclaration) { try { IMethodBinding methodBinding= ((MethodDeclaration)node).resolveBinding(); IMethodBinding definingMethodBinding= Bindings.findOverriddenMethod(methodBinding, true); if (definingMethodBinding != null) { IJavaElement definingMethod= definingMethodBinding.getJavaElement(); if (definingMethod != null) { JavaUI.openInEditor(definingMethod, true, true); return; } } } catch (CoreException e) { ExceptionHandler.handle(e, JavaEditorMessages.OverrideIndicatorManager_open_error_title, JavaEditorMessages.OverrideIndicatorManager_open_error_messageHasLogEntry); return; } } } String title= JavaEditorMessages.OverrideIndicatorManager_open_error_title; String message= JavaEditorMessages.OverrideIndicatorManager_open_error_message; MessageDialog.openError(JavaPlugin.getActiveWorkbenchShell(), title, message); }
Example 4
Source File: SelectionListenerWithASTManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected final IStatus calculateASTandInform(ITypeRoot input, ITextSelection selection, IProgressMonitor monitor) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } // create AST try { CompilationUnit astRoot= SharedASTProvider.getAST(input, SharedASTProvider.WAIT_ACTIVE_ONLY, monitor); if (astRoot != null && !monitor.isCanceled()) { Object[] listeners; synchronized (PartListenerGroup.this) { listeners= fAstListeners.getListeners(); } for (int i= 0; i < listeners.length; i++) { ((ISelectionListenerWithAST) listeners[i]).selectionChanged(fPart, selection, astRoot); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } } return Status.OK_STATUS; } } catch (OperationCanceledException e) { // thrown when canceling the AST creation } return Status.CANCEL_STATUS; }
Example 5
Source File: CleanUpPostSaveListener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private CompilationUnit createAst(ICompilationUnit unit, Map<String, String> cleanUpOptions, IProgressMonitor monitor) { IJavaProject project= unit.getJavaProject(); if (compatibleOptions(project, cleanUpOptions)) { CompilationUnit ast= SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_NO, monitor); if (ast != null) return ast; } ASTParser parser= CleanUpRefactoring.createCleanUpASTParser(); parser.setSource(unit); Map<String, String> compilerOptions= RefactoringASTParser.getCompilerOptions(unit.getJavaProject()); compilerOptions.putAll(cleanUpOptions); parser.setCompilerOptions(compilerOptions); return (CompilationUnit)parser.createAST(monitor); }
Example 6
Source File: RenameNodeCorrectionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override protected void addEdits(IDocument doc, TextEdit root) throws CoreException { super.addEdits(doc, root); // build a full AST CompilationUnit unit= SharedASTProvider.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, null); ASTNode name= NodeFinder.perform(unit, fOffset, fLength); if (name instanceof SimpleName) { SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name); if (names != null) { for (int i= 0; i < names.length; i++) { SimpleName curr= names[i]; root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName)); } return; } } root.addChild(new ReplaceEdit(fOffset, fLength, fNewName)); }
Example 7
Source File: OccurrencesSearchResultPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void installOnActiveEditor(IWorkbenchPage page) { IEditorPart activeEditor= page.getActiveEditor(); if (activeEditor instanceof ITextEditor) { editorActive(activeEditor); ISelection selection= activeEditor.getSite().getSelectionProvider().getSelection(); ITypeRoot typeRoot= JavaUI.getEditorInputTypeRoot(activeEditor.getEditorInput()); if (typeRoot != null && selection instanceof ITextSelection) { CompilationUnit astRoot= SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_ACTIVE_ONLY, null); if (astRoot != null) { preformEditorSelectionChanged((ITextSelection) selection, astRoot); } } } }
Example 8
Source File: AssistContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public CompilationUnit getASTRoot() { if (fASTRoot == null) { fASTRoot= SharedASTProvider.getAST(fCompilationUnit, fWaitFlag, null); if (fASTRoot == null) { // see bug 63554 fASTRoot= ASTResolving.createQuickFixAST(fCompilationUnit, null); } } return fASTRoot; }
Example 9
Source File: JavaElementHyperlinkDetector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Finds the target for break or continue node. * * @param input the editor input * @param region the region * @return the break or continue target location or <code>null</code> if none * @since 3.7 */ public static OccurrenceLocation findBreakOrContinueTarget(ITypeRoot input, IRegion region) { CompilationUnit astRoot= SharedASTProvider.getAST(input, SharedASTProvider.WAIT_NO, null); if (astRoot == null) return null; ASTNode node= NodeFinder.perform(astRoot, region.getOffset(), region.getLength()); ASTNode breakOrContinueNode= null; boolean labelSelected= false; if (node instanceof SimpleName) { SimpleName simpleName= (SimpleName) node; StructuralPropertyDescriptor location= simpleName.getLocationInParent(); if (location == ContinueStatement.LABEL_PROPERTY || location == BreakStatement.LABEL_PROPERTY) { breakOrContinueNode= simpleName.getParent(); labelSelected= true; } } else if (node instanceof ContinueStatement || node instanceof BreakStatement) breakOrContinueNode= node; if (breakOrContinueNode == null) return null; BreakContinueTargetFinder finder= new BreakContinueTargetFinder(); if (finder.initialize(astRoot, breakOrContinueNode) == null) { OccurrenceLocation[] locations= finder.getOccurrences(); if (locations != null) { if (breakOrContinueNode instanceof BreakStatement && !labelSelected) return locations[locations.length - 1]; // points to the end of target statement return locations[0]; // points to the beginning of target statement } } return null; }
Example 10
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void installOverrideIndicator(boolean provideAST) { uninstallOverrideIndicator(); IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput()); final ITypeRoot inputElement= getInputJavaElement(); if (model == null || inputElement == null) return; fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, null); if (provideAST) { CompilationUnit ast= SharedASTProvider.getAST(inputElement, SharedASTProvider.WAIT_ACTIVE_ONLY, getProgressMonitor()); fOverrideIndicatorManager.reconciled(ast, true, getProgressMonitor()); } }
Example 11
Source File: ClassFileEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void installSemanticHighlighting() { super.installSemanticHighlighting(); Job job= new Job(JavaEditorMessages.OverrideIndicatorManager_intallJob) { /* * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) * @since 3.0 */ @Override protected IStatus run(IProgressMonitor monitor) { CompilationUnit ast= SharedASTProvider.getAST(getInputJavaElement(), SharedASTProvider.WAIT_YES, null); if (fOverrideIndicatorManager != null) fOverrideIndicatorManager.reconciled(ast, true, monitor); if (fSemanticManager != null) { SemanticHighlightingReconciler reconciler= fSemanticManager.getReconciler(); if (reconciler != null) reconciler.reconciled(ast, false, monitor); } if (isMarkingOccurrences()) installOccurrencesFinder(false); return Status.OK_STATUS; } }; job.setPriority(Job.DECORATE); job.setSystem(true); job.schedule(); }
Example 12
Source File: JavaTextSelection.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public CompilationUnit resolvePartialAstAtOffset() { if (fPartialASTRequested) return fPartialAST; fPartialASTRequested= true; // long start= System.currentTimeMillis(); fPartialAST= SharedASTProvider.getAST(fElement, SharedASTProvider.WAIT_YES, null); // System.out.println("Time requesting partial AST: " + (System.currentTimeMillis() - start)); return fPartialAST; }
Example 13
Source File: JavaDebugElementCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override protected List provideCodeMinings(ITextViewer viewer, IJavaStackFrame frame, IProgressMonitor monitor) { List<ICodeMining> minings = new ArrayList<>(); ITextEditor textEditor = super.getAdapter(ITextEditor.class); ITypeRoot unit = EditorUtility.getEditorInputJavaElement(textEditor, true); if (unit == null) { return minings; } CompilationUnit cu = SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_YES, null); JavaDebugElementCodeMiningASTVisitor visitor = new JavaDebugElementCodeMiningASTVisitor(frame, cu, viewer, minings, this); cu.accept(visitor); return minings; }
Example 14
Source File: SurroundWith.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isApplicable(IInvocationContext context) throws CoreException { ICompilationUnit unit= context.getCompilationUnit(); CompilationUnit ast= SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_NO, null); if (ast == null) return true; Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection); context.getASTRoot().accept(analyzer); return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes(); }
Example 15
Source File: JavaASTCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
private void collectCodeMinings(ITypeRoot unit, ITextEditor textEditor, ITextViewer viewer, List<ICodeMining> minings) { CompilationUnit cu = SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_YES, null); JavaCodeMiningASTVisitor visitor = new JavaCodeMiningASTVisitor(cu, textEditor, viewer, minings, this); visitor.setShowParameterName(showParameterName); visitor.setShowParameterType(showParameterType); visitor.setShowParameterOnlyForLiteral(showParameterOnlyForLiteral); visitor.setShowParameterByUsingFilters(showParameterByUsingFilters); visitor.setShowEndStatement(showEndStatement); visitor.setEndStatementMinLineNumber(endStatementMinLineNumber); visitor.setShowJava10VarType(showJava10VarType); cu.accept(visitor); }
Example 16
Source File: StructureSelectionAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static CompilationUnit getAST(ITypeRoot sr) { return SharedASTProvider.getAST(sr, SharedASTProvider.WAIT_YES, null); }
Example 17
Source File: RenameLinkedMode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void start() { if (getActiveLinkedMode() != null) { // for safety; should already be handled in RenameJavaElementAction fgActiveLinkedMode.startFullDialog(); return; } ISourceViewer viewer= fEditor.getViewer(); IDocument document= viewer.getDocument(); fOriginalSelection= viewer.getSelectedRange(); int offset= fOriginalSelection.x; try { CompilationUnit root= SharedASTProvider.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, null); fLinkedPositionGroup= new LinkedPositionGroup(); ASTNode selectedNode= NodeFinder.perform(root, fOriginalSelection.x, fOriginalSelection.y); if (! (selectedNode instanceof SimpleName)) { return; // TODO: show dialog } SimpleName nameNode= (SimpleName) selectedNode; if (viewer instanceof ITextViewerExtension6) { IUndoManager undoManager= ((ITextViewerExtension6)viewer).getUndoManager(); if (undoManager instanceof IUndoManagerExtension) { IUndoManagerExtension undoManagerExtension= (IUndoManagerExtension)undoManager; IUndoContext undoContext= undoManagerExtension.getUndoContext(); IOperationHistory operationHistory= OperationHistoryFactory.getOperationHistory(); fStartingUndoOperation= operationHistory.getUndoOperation(undoContext); } } fOriginalName= nameNode.getIdentifier(); final int pos= nameNode.getStartPosition(); ASTNode[] sameNodes= LinkedNodeFinder.findByNode(root, nameNode); //TODO: copied from LinkedNamesAssistProposal#apply(..): // sort for iteration order, starting with the node @ offset Arrays.sort(sameNodes, new Comparator<ASTNode>() { public int compare(ASTNode o1, ASTNode o2) { return rank(o1) - rank(o2); } /** * Returns the absolute rank of an <code>ASTNode</code>. Nodes * preceding <code>pos</code> are ranked last. * * @param node the node to compute the rank for * @return the rank of the node with respect to the invocation offset */ private int rank(ASTNode node) { int relativeRank= node.getStartPosition() + node.getLength() - pos; if (relativeRank < 0) return Integer.MAX_VALUE + relativeRank; else return relativeRank; } }); for (int i= 0; i < sameNodes.length; i++) { ASTNode elem= sameNodes[i]; LinkedPosition linkedPosition= new LinkedPosition(document, elem.getStartPosition(), elem.getLength(), i); if (i == 0) fNamePosition= linkedPosition; fLinkedPositionGroup.addPosition(linkedPosition); } fLinkedModeModel= new LinkedModeModel(); fLinkedModeModel.addGroup(fLinkedPositionGroup); fLinkedModeModel.forceInstall(); fLinkedModeModel.addLinkingListener(new EditorHighlightingSynchronizer(fEditor)); fLinkedModeModel.addLinkingListener(new EditorSynchronizer()); LinkedModeUI ui= new EditorLinkedModeUI(fLinkedModeModel, viewer); ui.setExitPosition(viewer, offset, 0, Integer.MAX_VALUE); ui.setExitPolicy(new ExitPolicy(document)); ui.enter(); viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y); // by default, full word is selected; restore original selection if (viewer instanceof IEditingSupportRegistry) { IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer; registry.register(fFocusEditingSupport); } openSecondaryPopup(); // startAnimation(); fgActiveLinkedMode= this; } catch (BadLocationException e) { JavaPlugin.log(e); } }
Example 18
Source File: JavaCorrectionAssistant.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static void ensureUpdatedAnnotations(ITextEditor editor) { Object inputElement= editor.getEditorInput().getAdapter(IJavaElement.class); if (inputElement instanceof ICompilationUnit) { SharedASTProvider.getAST((ICompilationUnit) inputElement, SharedASTProvider.WAIT_ACTIVE_ONLY, null); } }
Example 19
Source File: JavadocContentAccess2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean handleConstantValue(IField field, boolean link) throws JavaModelException { String text= null; ISourceRange nameRange= field.getNameRange(); if (SourceRange.isAvailable(nameRange)) { CompilationUnit cuNode= SharedASTProvider.getAST(field.getTypeRoot(), SharedASTProvider.WAIT_ACTIVE_ONLY, null); if (cuNode != null) { ASTNode nameNode= NodeFinder.perform(cuNode, nameRange); if (nameNode instanceof SimpleName) { IBinding binding= ((SimpleName) nameNode).resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding variableBinding= (IVariableBinding) binding; Object constantValue= variableBinding.getConstantValue(); if (constantValue != null) { if (constantValue instanceof String) { text= ASTNodes.getEscapedStringLiteral((String) constantValue); } else { text= constantValue.toString(); // Javadoc tool is even worse for chars... } } } } } } if (text == null) { Object constant= field.getConstant(); if (constant != null) { text= constant.toString(); } } if (text != null) { text= HTMLPrinter.convertToHTMLContentWithWhitespace(text); if (link) { String uri; try { uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, field); fBuf.append(JavaElementLinks.createLink(uri, text)); } catch (URISyntaxException e) { JavaPlugin.log(e); return false; } } else { handleText(text); } return true; } return false; }
Example 20
Source File: JavadocView.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Returns the constant value for a field that is referenced by the currently active type. This * method does may not run in the main UI thread. * * @param activeType the type that is currently active * @param field the field that is being referenced (usually not declared in * <code>activeType</code>) * @param selection the region in <code>activeType</code> that contains the field reference * @param monitor a progress monitor * * @return the constant value for the given field or <code>null</code> if none * @since 3.4 */ private static Object getConstantValueFromActiveEditor(ITypeRoot activeType, IField field, ITextSelection selection, IProgressMonitor monitor) { CompilationUnit unit= SharedASTProvider.getAST(activeType, SharedASTProvider.WAIT_ACTIVE_ONLY, monitor); if (unit == null) return null; ASTNode node= NodeFinder.perform(unit, selection.getOffset(), selection.getLength()); return JavadocHover.getVariableBindingConstValue(node, field); }