本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTParser.createBindings方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTParser.createBindings方法的具體用法?Java ASTParser.createBindings怎麽用?Java ASTParser.createBindings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ASTParser
的用法示例。
在下文中一共展示了ASTParser.createBindings方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getParameterTypeNamesForSeeTag
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
try {
ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
parser.setProject(overridden.getJavaProject());
IBinding[] bindings = parser.createBindings(new IJavaElement[] { overridden }, null);
if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
}
} catch (IllegalStateException e) {
// method does not exist
}
// fall back code. Not good for generic methods!
String[] paramTypes = overridden.getParameterTypes();
String[] paramTypeNames = new String[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) {
paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
}
return paramTypeNames;
}
示例2: resolveType
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static ITypeBinding resolveType(IJavaProject javaProject,
String qualifiedTypeName) throws JavaModelException {
IType type = javaProject.findType(qualifiedTypeName);
if (type == null || !type.exists()) {
return null;
}
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setProject(javaProject);
IBinding[] bindings = parser.createBindings(new IJavaElement[] {type}, null);
if (bindings == null) {
return null;
}
return (ITypeBinding) bindings[0];
}
示例3: getParameterTypeNamesForSeeTag
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
try {
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(overridden.getJavaProject());
IBinding[] bindings= parser.createBindings(new IJavaElement[] { overridden }, null);
if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
return getParameterTypeNamesForSeeTag((IMethodBinding)bindings[0]);
}
} catch (IllegalStateException e) {
// method does not exist
}
// fall back code. Not good for generic methods!
String[] paramTypes= overridden.getParameterTypes();
String[] paramTypeNames= new String[paramTypes.length];
for (int i= 0; i < paramTypes.length; i++) {
paramTypeNames[i]= Signature.toString(Signature.getTypeErasure(paramTypes[i]));
}
return paramTypeNames;
}
示例4: parse
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public void parse() {
if (this.member != null) {
if (this.member instanceof IType) {
this.elements.add(this.unit.findDeclaringNode(((IType)this.member).getKey()));
}
else if (this.member instanceof IMethod) {
final ASTParser parser = ASTParser.newParser(4);
parser.setProject(((IMethod)this.member).getJavaProject());
parser.setResolveBindings(true);
final IBinding binding = parser.createBindings(new IJavaElement[] { (IMethod)this.member }, (IProgressMonitor)null)[0];
if (binding instanceof IMethodBinding) {
final ASTNode method = this.unit.findDeclaringNode(((IMethodBinding)binding).getKey());
this.elements.add(method);
}
}
}
else {
for (final Object o : this.unit.types()) {
if (!(o instanceof TypeDeclaration)) {
continue;
}
this.elements.add((ASTNode)o);
}
}
}
示例5: createBoxed
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
StandardType createBoxed(PrimitiveType type, IJavaProject focus) {
String fullyQualifiedName= BOXED_PRIMITIVE_NAMES[type.getId()];
try {
IType javaElementType= focus.findType(fullyQualifiedName);
StandardType result= fStandardTypes.get(javaElementType);
if (result != null)
return result;
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(focus);
IBinding[] bindings= parser.createBindings(new IJavaElement[] {javaElementType} , null);
return createStandardType((ITypeBinding)bindings[0]);
} catch (JavaModelException e) {
// fall through
}
return null;
}
示例6: createBinding
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Uses an {@link ASTParser} to create the {@link IMethodBinding} of the given {@link IMethod}.
*
* Further info: http://wiki.eclipse.org/JDT/FAQ#From_an_IJavaElement_to_an_IBinding
*
* @param method
* the {@link IMethod}
* @return the create {@link IMethodBinding}.
*/
public static IMethodBinding createBinding(final IMethod method) {
final ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setProject(method.getJavaProject());
final IBinding[] bindings = parser.createBindings(new IJavaElement[] { method }, new NullProgressMonitor());
if (bindings.length > 0 && bindings[0] instanceof IMethodBinding) {
return (IMethodBinding) bindings[0];
}
return null;
}
示例7: checkInitialConditions
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
// TargetProvider must get an untampered AST with original invocation node
// SourceProvider must get a tweaked AST with method body / parameter names replaced
RefactoringStatus result = new RefactoringStatus();
if (fMethod == null) {
if (!(fSelectionTypeRoot instanceof ICompilationUnit))
return RefactoringStatus.createFatalErrorStatus(
RefactoringCoreMessages.ReplaceInvocationsRefactoring_cannot_replace_in_binary);
ICompilationUnit cu = (ICompilationUnit) fSelectionTypeRoot;
CompilationUnit root = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, true);
fSelectionNode = getTargetNode(cu, root, fSelectionStart, fSelectionLength);
if (fSelectionNode == null)
return RefactoringStatus.createFatalErrorStatus(
RefactoringCoreMessages.ReplaceInvocationsRefactoring_select_method_to_apply);
if (fSelectionNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
MethodDeclaration methodDeclaration = (MethodDeclaration) fSelectionNode;
fTargetProvider = TargetProvider.create(methodDeclaration);
fMethodBinding = methodDeclaration.resolveBinding();
} else {
MethodInvocation methodInvocation = (MethodInvocation) fSelectionNode;
fTargetProvider = TargetProvider.create(cu, methodInvocation);
fMethodBinding = methodInvocation.resolveMethodBinding();
}
if (fMethodBinding == null)
return RefactoringStatus.createFatalErrorStatus(
RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
fMethod = (IMethod) fMethodBinding.getJavaElement();
} else {
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(fMethod.getJavaProject());
IBinding[] bindings = parser.createBindings(new IJavaElement[] {fMethod}, null);
fMethodBinding = (IMethodBinding) bindings[0];
if (fMethodBinding == null)
return RefactoringStatus.createFatalErrorStatus(
RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
fTargetProvider = TargetProvider.create(fMethodBinding);
}
result.merge(fTargetProvider.checkActivation());
return result;
}
示例8: createStandardType
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private StandardType createStandardType(String fullyQualifiedName, IJavaProject focus) {
try {
IType javaElementType = focus.findType(fullyQualifiedName);
StandardType result = fStandardTypes.get(javaElementType);
if (result != null) return result;
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(focus);
IBinding[] bindings = parser.createBindings(new IJavaElement[] {javaElementType}, null);
return createStandardType((ITypeBinding) bindings[0]);
} catch (JavaModelException e) {
// fall through
}
return null;
}
示例9: createStandardType
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private StandardType createStandardType(String fullyQualifiedName, IJavaProject focus) {
try {
IType javaElementType= focus.findType(fullyQualifiedName);
StandardType result= fStandardTypes.get(javaElementType);
if (result != null)
return result;
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(focus);
IBinding[] bindings= parser.createBindings(new IJavaElement[] {javaElementType} , null);
return createStandardType((ITypeBinding)bindings[0]);
} catch (JavaModelException e) {
// fall through
}
return null;
}
示例10: getAnnotations
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static String getAnnotations(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) throws URISyntaxException, JavaModelException {
if (!(element instanceof IAnnotatable))
return null;
if (((IAnnotatable)element).getAnnotations().length == 0)
return null;
IBinding binding;
ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion);
if (node == null) {
ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
p.setProject(element.getJavaProject());
try {
binding= p.createBindings(new IJavaElement[] { element }, null)[0];
} catch (OperationCanceledException e) {
return null;
}
} else {
binding= resolveBinding(node);
}
if (binding == null)
return null;
IAnnotationBinding[] annotations= binding.getAnnotations();
if (annotations.length == 0)
return null;
StringBuffer buf= new StringBuffer();
for (int i= 0; i < annotations.length; i++) {
//TODO: skip annotations that don't have an @Documented annotation?
addAnnotation(buf, element, annotations[i]);
buf.append("<br>"); //$NON-NLS-1$
}
return buf.toString();
}
示例11: createBindings
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static IBinding[] createBindings(ICompilationUnit cu,
IJavaElement... javaElements) {
ASTParser parser = createASTParser(cu);
return parser.createBindings(javaElements, null);
}
示例12: createChangeManager
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Creates the text change manager for this processor.
*
* @param monitor
* the progress monitor to display progress
* @param status
* the refactoring status
* @return the created text change manager
* @throws JavaModelException
* if the method declaration could not be found
* @throws CoreException
* if the changes could not be generated
*/
protected final TextEditBasedChangeManager createChangeManager(final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException, CoreException {
Assert.isNotNull(status);
Assert.isNotNull(monitor);
try {
monitor.beginTask("", 300); //$NON-NLS-1$
monitor.setTaskName(RefactoringCoreMessages.UseSuperTypeProcessor_creating);
final TextEditBasedChangeManager manager= new TextEditBasedChangeManager();
final IJavaProject project= fSubType.getJavaProject();
final ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setWorkingCopyOwner(fOwner);
parser.setResolveBindings(true);
parser.setProject(project);
parser.setCompilerOptions(RefactoringASTParser.getCompilerOptions(project));
if (fSubType.isBinary() || fSubType.isReadOnly()) {
final IBinding[] bindings= parser.createBindings(new IJavaElement[] { fSubType, fSuperType }, new SubProgressMonitor(monitor, 50));
if (bindings != null && bindings.length == 2 && bindings[0] instanceof ITypeBinding && bindings[1] instanceof ITypeBinding) {
solveSuperTypeConstraints(null, null, fSubType, (ITypeBinding) bindings[0], (ITypeBinding) bindings[1], new SubProgressMonitor(monitor, 100), status);
if (!status.hasFatalError())
rewriteTypeOccurrences(manager, null, null, null, null, new HashSet<String>(), status, new SubProgressMonitor(monitor, 150));
}
} else {
parser.createASTs(new ICompilationUnit[] { fSubType.getCompilationUnit() }, new String[0], new ASTRequestor() {
@Override
public final void acceptAST(final ICompilationUnit unit, final CompilationUnit node) {
try {
final CompilationUnitRewrite subRewrite= new CompilationUnitRewrite(fOwner, unit, node);
final AbstractTypeDeclaration subDeclaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(fSubType, subRewrite.getRoot());
if (subDeclaration != null) {
final ITypeBinding subBinding= subDeclaration.resolveBinding();
if (subBinding != null) {
final ITypeBinding superBinding= findTypeInHierarchy(subBinding, fSuperType.getFullyQualifiedName('.'));
if (superBinding != null) {
solveSuperTypeConstraints(subRewrite.getCu(), subRewrite.getRoot(), fSubType, subBinding, superBinding, new SubProgressMonitor(monitor, 100), status);
if (!status.hasFatalError()) {
rewriteTypeOccurrences(manager, this, subRewrite, subRewrite.getCu(), subRewrite.getRoot(), new HashSet<String>(), status, new SubProgressMonitor(monitor, 200));
final TextChange change= subRewrite.createChange(true);
if (change != null)
manager.manage(subRewrite.getCu(), change);
}
}
}
}
} catch (CoreException exception) {
JavaPlugin.log(exception);
status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.UseSuperTypeProcessor_internal_error));
}
}
@Override
public final void acceptBinding(final String key, final IBinding binding) {
// Do nothing
}
}, new NullProgressMonitor());
}
return manager;
} finally {
monitor.done();
}
}
示例13: checkInitialConditions
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
// TargetProvider must get an untampered AST with original invocation node
// SourceProvider must get a tweaked AST with method body / parameter names replaced
RefactoringStatus result= new RefactoringStatus();
if (fMethod == null) {
if (! (fSelectionTypeRoot instanceof ICompilationUnit))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReplaceInvocationsRefactoring_cannot_replace_in_binary);
ICompilationUnit cu= (ICompilationUnit) fSelectionTypeRoot;
CompilationUnit root= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, true);
fSelectionNode= getTargetNode(cu, root, fSelectionStart, fSelectionLength);
if (fSelectionNode == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReplaceInvocationsRefactoring_select_method_to_apply);
if (fSelectionNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
MethodDeclaration methodDeclaration= (MethodDeclaration) fSelectionNode;
fTargetProvider= TargetProvider.create(methodDeclaration);
fMethodBinding= methodDeclaration.resolveBinding();
} else {
MethodInvocation methodInvocation= (MethodInvocation) fSelectionNode;
fTargetProvider= TargetProvider.create(cu, methodInvocation);
fMethodBinding= methodInvocation.resolveMethodBinding();
}
if (fMethodBinding == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
fMethod= (IMethod) fMethodBinding.getJavaElement();
} else {
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(fMethod.getJavaProject());
IBinding[] bindings= parser.createBindings(new IJavaElement[] { fMethod }, null);
fMethodBinding= (IMethodBinding) bindings[0];
if (fMethodBinding == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
fTargetProvider= TargetProvider.create(fMethodBinding);
}
result.merge(fTargetProvider.checkActivation());
return result;
}
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:45,代碼來源:ReplaceInvocationsRefactoring.java
示例14: getAnnotations
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static String getAnnotations(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) throws URISyntaxException, JavaModelException {
if (!(element instanceof IPackageFragment)) {
if (!(element instanceof IAnnotatable))
return null;
if (((IAnnotatable)element).getAnnotations().length == 0)
return null;
}
IBinding binding;
ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion);
if (node == null) {
ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
p.setProject(element.getJavaProject());
p.setBindingsRecovery(true);
try {
binding= p.createBindings(new IJavaElement[] { element }, null)[0];
} catch (OperationCanceledException e) {
return null;
}
} else {
binding= resolveBinding(node);
}
if (binding == null)
return null;
IAnnotationBinding[] annotations= binding.getAnnotations();
if (annotations.length == 0)
return null;
StringBuffer buf= new StringBuffer();
for (int i= 0; i < annotations.length; i++) {
//TODO: skip annotations that don't have an @Documented annotation?
addAnnotation(buf, element, annotations[i]);
buf.append("<br>"); //$NON-NLS-1$
}
return buf.toString();
}