本文整理汇总了Java中org.eclipse.jdt.ui.SharedASTProvider类的典型用法代码示例。如果您正苦于以下问题:Java SharedASTProvider类的具体用法?Java SharedASTProvider怎么用?Java SharedASTProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SharedASTProvider类属于org.eclipse.jdt.ui包,在下文中一共展示了SharedASTProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getForStatement
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
private static ForStatement getForStatement(ICompilationUnit cu) {
CompilationUnit ast =
SharedASTProvider.getAST(cu, SharedASTProvider.WAIT_YES, new NullProgressMonitor());
final ForStatement[] statement = new ForStatement[1];
ast.accept(
new GenericVisitor() {
protected boolean visitNode(ASTNode node) {
if (node instanceof ForStatement) {
statement[0] = (ForStatement) node;
return false;
} else {
return super.visitNode(node);
}
}
});
return statement[0];
}
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ConvertForLoopQuickFixTest.java
示例2: parseWithASTProvider
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
/**
* Tries to get the shared AST from the ASTProvider. If the shared AST is not available, parses
* the type root with a RefactoringASTParser that uses settings similar to the ASTProvider.
*
* @param typeRoot the type root
* @param resolveBindings whether bindings are to be resolved if a new AST needs to be created
* @param pm an {@link IProgressMonitor}, or <code>null</code>
* @return the parsed CompilationUnit
*/
public static CompilationUnit parseWithASTProvider(
ITypeRoot typeRoot, boolean resolveBindings, IProgressMonitor pm) {
CompilationUnit cuNode =
SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_ACTIVE_ONLY, pm);
if (cuNode != null) {
return cuNode;
} else {
return new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
.parse(
typeRoot,
null,
resolveBindings,
ASTProvider.SHARED_AST_STATEMENT_RECOVERY,
ASTProvider.SHARED_BINDING_RECOVERY,
pm);
}
}
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:RefactoringASTParser.java
示例3: addEdits
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
@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));
}
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:RenameNodeCorrectionProposal.java
示例4: NLSRefactoring
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
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.
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:NLSRefactoring.java
示例5: createAst
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
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);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:CleanUpPostSaveListener.java
示例6: installOccurrencesFinder
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
protected void installOccurrencesFinder(boolean forceUpdate) {
fMarkOccurrenceAnnotations= true;
fPostSelectionListenerWithAST= new ISelectionListenerWithAST() {
public void selectionChanged(IEditorPart part, ITextSelection selection, CompilationUnit astRoot) {
updateOccurrenceAnnotations(selection, astRoot);
}
};
SelectionListenerWithASTManager.getDefault().addListener(this, fPostSelectionListenerWithAST);
if (forceUpdate && getSelectionProvider() != null) {
fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection();
ITypeRoot inputJavaElement= getInputJavaElement();
if (inputJavaElement != null)
updateOccurrenceAnnotations((ITextSelection)fForcedMarkOccurrencesSelection, SharedASTProvider.getAST(inputJavaElement, SharedASTProvider.WAIT_NO, getProgressMonitor()));
}
if (fOccurrencesFinderJobCanceler == null) {
fOccurrencesFinderJobCanceler= new OccurrencesFinderJobCanceler();
fOccurrencesFinderJobCanceler.install();
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:JavaEditor.java
示例7: open
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
/**
* 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);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:OverrideIndicatorManager.java
示例8: getRecoveredAST
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
private CompilationUnit getRecoveredAST(IDocument document, int offset, Document recoveredDocument) {
CompilationUnit ast= SharedASTProvider.getAST(fCompilationUnit, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
if (ast != null) {
recoveredDocument.set(document.get());
return ast;
}
char[] content= document.get().toCharArray();
// clear prefix to avoid compile errors
int index= offset - 1;
while (index >= 0 && Character.isJavaIdentifierPart(content[index])) {
content[index]= ' ';
index--;
}
recoveredDocument.set(new String(content));
final ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setSource(content);
parser.setUnitName(fCompilationUnit.getElementName());
parser.setProject(fCompilationUnit.getJavaProject());
return (CompilationUnit) parser.createAST(new NullProgressMonitor());
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:OverrideCompletionProposal.java
示例9: getHoverRegion
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
if (!(getEditor() instanceof JavaEditor))
return null;
ITypeRoot je= getEditorInputJavaElement();
if (je == null)
return null;
// Never wait for an AST in UI thread.
CompilationUnit ast= SharedASTProvider.getAST(je, SharedASTProvider.WAIT_NO, null);
if (ast == null)
return null;
ASTNode node= NodeFinder.perform(ast, offset, 1);
if (node instanceof StringLiteral) {
StringLiteral stringLiteral= (StringLiteral)node;
return new Region(stringLiteral.getStartPosition(), stringLiteral.getLength());
} else if (node instanceof SimpleName) {
SimpleName simpleName= (SimpleName)node;
return new Region(simpleName.getStartPosition(), simpleName.getLength());
}
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:NLSStringHover.java
示例10: getJavaAnnotationFixes
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) {
ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation);
ICompilationUnit cu= javaAnnotation.getCompilationUnit();
if (cu == null)
return NO_PROPOSALS;
ISourceViewer sourceViewer= null;
if (viewer instanceof ISourceViewer)
sourceViewer= (ISourceViewer) viewer;
IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProvider.WAIT_ACTIVE_ONLY);
if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location))
return NO_PROPOSALS;
ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>();
JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals);
Collections.sort(proposals, new CompletionProposalComparator());
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ProblemHover.java
示例11: doPropertyChanged
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
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();
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:QuickAssistLightBulbUpdater.java
示例12: addEdits
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
@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));
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:RenameNodeCorrectionProposal.java
示例13: calculateASTandInform
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:SelectionListenerWithASTManager.java
示例14: getConstantValueFromActiveEditor
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
/**
* 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.
* <p>
* XXX: This method was part of the JavadocHover#getConstantValue(IField field, IRegion hoverRegion)
* method (lines 299-314).
* </p>
* @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) {
Object constantValue= null;
CompilationUnit unit= SharedASTProvider.getAST(activeType, SharedASTProvider.WAIT_ACTIVE_ONLY, monitor);
if (unit == null)
return null;
ASTNode node= NodeFinder.perform(unit, selection.getOffset(), selection.getLength());
if (node != null && node.getNodeType() == ASTNode.SIMPLE_NAME) {
IBinding binding= ((SimpleName)node).resolveBinding();
if (binding != null && binding.getKind() == IBinding.VARIABLE) {
IVariableBinding variableBinding= (IVariableBinding)binding;
if (field.equals(variableBinding.getJavaElement())) {
constantValue= variableBinding.getConstantValue();
}
}
}
return constantValue;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:35,代码来源:JavadocView.java
示例15: getMemberFromOffset
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
public static IMember getMemberFromOffset(ITextEditor javaEditor, int offset) throws JavaModelException {
ITypeRoot element= JavaUI.getEditorInputTypeRoot(javaEditor.getEditorInput());
CompilationUnit ast = SharedASTProvider.getAST(element, SharedASTProvider.WAIT_YES, null);
NodeFinder finder= new NodeFinder(ast, offset, 0);
ASTNode node= finder.getCoveringNode();
while(node != null) {
if(node instanceof Initializer) {
TypeDeclaration typeDeclaration = (TypeDeclaration) node.getParent();
IType type = (IType) typeDeclaration.resolveBinding().getJavaElement();
for(IInitializer initializer : type.getInitializers()) {
if(node.getStartPosition() == initializer.getSourceRange().getOffset()
&& Flags.isStatic(initializer.getFlags())) {
return initializer;
}
}
}
if(node instanceof MethodDeclaration) {
IMethodBinding binding = ((MethodDeclaration) node).resolveBinding();
return (IMethod) binding.getJavaElement();
}
node = node.getParent();
}
return null;
}
开发者ID:masao-kunii,项目名称:byteman-editor,代码行数:26,代码来源:JavaUtils.java
示例16: resolvePartialAstAtOffset
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
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;
}
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:JavaTextSelection.java
示例17: getRecoveredAST
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
private CompilationUnit getRecoveredAST(
IDocument document, int offset, Document recoveredDocument) {
CompilationUnit ast =
SharedASTProvider.getAST(fCompilationUnit, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
if (ast != null) {
recoveredDocument.set(document.get());
return ast;
}
char[] content = document.get().toCharArray();
// clear prefix to avoid compile errors
int index = offset - 1;
while (index >= 0 && Character.isJavaIdentifierPart(content[index])) {
content[index] = ' ';
index--;
}
recoveredDocument.set(new String(content));
final CheASTParser parser = CheASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setSource(content);
parser.setUnitName(fCompilationUnit.getElementName());
parser.setProject(fCompilationUnit.getJavaProject());
return (CompilationUnit) parser.createAST(new NullProgressMonitor());
}
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:OverrideCompletionProposal.java
示例18: AssistContext
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
private AssistContext(
ICompilationUnit cu,
ISourceViewer sourceViewer, /* IEditorPart editor,*/
int offset,
int length,
SharedASTProvider.WAIT_FLAG waitFlag) {
super(sourceViewer, offset, length);
Assert.isLegal(cu != null);
Assert.isLegal(waitFlag != null);
fCompilationUnit = cu;
// fEditor = editor;
fWaitFlag = waitFlag;
}
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:AssistContext.java
示例19: getASTRoot
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
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;
}
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:AssistContext.java
示例20: getResourceBundleName
import org.eclipse.jdt.ui.SharedASTProvider; //导入依赖的package包/类
public static String getResourceBundleName(ITypeBinding accessorClassBinding) {
IJavaElement je= accessorClassBinding.getJavaElement();
if (!(je instanceof IType))
return null;
ITypeRoot typeRoot= ((IType) je).getTypeRoot();
CompilationUnit astRoot= SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_YES, null);
return getResourceBundleName(astRoot);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:NLSHintHelper.java
注:本文中的org.eclipse.jdt.ui.SharedASTProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论