本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.getJavaElement方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.getJavaElement方法的具體用法?Java ITypeBinding.getJavaElement怎麽用?Java ITypeBinding.getJavaElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ITypeBinding
的用法示例。
在下文中一共展示了ITypeBinding.getJavaElement方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUniqueMethodName
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static String getUniqueMethodName(ASTNode astNode, String suggestedName) throws JavaModelException {
while (astNode != null && !(astNode instanceof TypeDeclaration)) {
astNode = astNode.getParent();
}
if (astNode instanceof TypeDeclaration) {
ITypeBinding typeBinding = ((TypeDeclaration) astNode).resolveBinding();
if (typeBinding == null) {
return suggestedName;
}
IType type = (IType) typeBinding.getJavaElement();
if (type == null) {
return suggestedName;
}
IMethod[] methods = type.getMethods();
int suggestedPostfix = 2;
String resultName = suggestedName;
while (suggestedPostfix < 1000) {
if (!hasMethod(methods, resultName)) {
return resultName;
}
resultName = suggestedName + suggestedPostfix++;
}
}
return suggestedName;
}
示例2: run
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
public void run() {
ITypeBinding typeBinding = Crystal.getInstance().getTypeBindingFromName(fullyQualifiedName);
if(typeBinding!=null){
//get all types & names of fields & methods & class/interface
IJavaElement javaElement = typeBinding.getJavaElement();
if (javaElement != null && ASTUtils.isFromSource(typeBinding)) {
try {
// EditorUtility.openInEditor(javaElement, true);
/*
* code above causes a bug that if several classes are in
* the same java file, always open the first one no matter
* which one the user chooses
*/
JavaUI.openInEditor(javaElement);
// IEditorPart javaEditor = JavaUI.openInEditor(javaElement);
// JavaUI.revealInEditor(javaEditor, javaElement);
} catch (Exception e) {
e.printStackTrace();
}
}
}
super.run();
}
示例3: visit
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
public boolean visit(MethodDeclaration methodDeclaration) {
IBinding binding = methodDeclaration.resolveBinding();
if (binding == null)
return false;
currentMethod = (IMethod) binding.getJavaElement();
if (currentMethod != null) {
methodDetails = new MethodDetails();
String handleIdentifier = currentMethod.getHandleIdentifier();
allDetails.put(handleIdentifier, methodDetails);
methodDetails.setModifiers(methodDeclaration.getModifiers());
methodDetails.setParameters(getParameters(methodDeclaration.parameters()));
Type returnType2 = methodDeclaration.getReturnType2();
if (returnType2 != null) {
ITypeBinding typeBinding = returnType2.resolveBinding();
IJavaElement returnType = typeBinding.getJavaElement();
if (returnType instanceof IType) {
methodDetails.setReturnType((IType) returnType);
}
}
}
return true;
}
示例4: getClassfile
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static IFile getClassfile(ITypeBinding typeBinding) throws CoreException {
// bug 191943
IType type = (IType) typeBinding.getJavaElement();
if (type == null || type.getCompilationUnit() == null || type.getJavaProject() == null || ProjectsManager.DEFAULT_PROJECT_NAME.equals(type.getJavaProject().getProject().getName())) {
return null;
}
IRegion region = JavaCore.newRegion();
region.add(type.getCompilationUnit());
String name = typeBinding.getBinaryName();
if (name != null) {
int packStart = name.lastIndexOf('.');
if (packStart != -1) {
name = name.substring(packStart + 1);
}
} else {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
}
name += ".class"; //$NON-NLS-1$
IResource[] classFiles = JavaCore.getGeneratedResources(region, false);
for (int i = 0; i < classFiles.length; i++) {
IResource resource = classFiles[i];
if (resource.getType() == IResource.FILE && resource.getName().equals(name) && resource.exists()) {
try (InputStream contents = ((IFile) resource).getContents()) {
} catch (Exception e) {
continue;
}
return (IFile) resource;
}
}
return null;
// throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
}
示例5: computeTypeArgumentProposals
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private String[] computeTypeArgumentProposals(CompletionProposal proposal) {
try {
IType type = (IType) resolveJavaElement(
compilationUnit.getJavaProject(), proposal);
if (type == null) {
return new String[0];
}
ITypeParameter[] parameters = type.getTypeParameters();
if (parameters.length == 0) {
return new String[0];
}
String[] arguments = new String[parameters.length];
ITypeBinding expectedTypeBinding = getExpectedTypeForGenericParameters();
if (expectedTypeBinding != null && expectedTypeBinding.isParameterizedType()) {
// in this case, the type arguments we propose need to be compatible
// with the corresponding type parameters to declared type
IType expectedType= (IType) expectedTypeBinding.getJavaElement();
IType[] path= TypeProposalUtils.computeInheritancePath(type, expectedType);
if (path == null) {
// proposed type does not inherit from expected type
// the user might be looking for an inner type of proposed type
// to instantiate -> do not add any type arguments
return new String[0];
}
int[] indices= new int[parameters.length];
for (int paramIdx= 0; paramIdx < parameters.length; paramIdx++) {
indices[paramIdx]= TypeProposalUtils.mapTypeParameterIndex(path, path.length - 1, paramIdx);
}
// for type arguments that are mapped through to the expected type's
// parameters, take the arguments of the expected type
ITypeBinding[] typeArguments= expectedTypeBinding.getTypeArguments();
for (int paramIdx= 0; paramIdx < parameters.length; paramIdx++) {
if (indices[paramIdx] != -1) {
// type argument is mapped through
ITypeBinding binding= typeArguments[indices[paramIdx]];
arguments[paramIdx]= computeTypeProposal(binding, parameters[paramIdx]);
}
}
}
// for type arguments that are not mapped through to the expected type,
// take the lower bound of the type parameter
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] == null) {
arguments[i] = computeTypeProposal(parameters[i]);
}
}
return arguments;
} catch (JavaModelException e) {
return new String[0];
}
}
示例6: findCompilationUnit
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Finds the compilation unit where the type of the given <code>ITypeBinding</code> is defined,
* using the class path defined by the given Java project. Returns <code>null</code>
* if no compilation unit is found (e.g. type binding is from a binary type)
* @param typeBinding the type binding to search for
* @param project the project used as a scope
* @return the compilation unit containing the type
* @throws JavaModelException if an errors occurs in the Java model
*/
public static ICompilationUnit findCompilationUnit(ITypeBinding typeBinding, IJavaProject project) throws JavaModelException {
IJavaElement type= typeBinding.getJavaElement();
if (type instanceof IType) {
return ((IType) type).getCompilationUnit();
} else {
return null;
}
}