當前位置: 首頁>>代碼示例>>Java>>正文


Java Type.resolveBinding方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.Type.resolveBinding方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.resolveBinding方法的具體用法?Java Type.resolveBinding怎麽用?Java Type.resolveBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.Type的用法示例。


在下文中一共展示了Type.resolveBinding方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTypes

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private Set<String> getTypes(Type oType) {
    Set<String> types = new HashSet<>();
    if (oType == null)
        return types;
    ITypeBinding typeBinding = oType.resolveBinding();
    if (typeBinding == null)
        return types;
    String str = typeBinding.getQualifiedName();
    String[] eles = str.split("[^A-Za-z0-9_\\.]+");
    for (String e : eles) {
        if (e.equals("extends"))
            continue;
        types.add(e);
    }
    return types;
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:17,代碼來源:JavaASTVisitor.java

示例2: addMethodReturnsVoidProposals

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
public static void addMethodReturnsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) throws JavaModelException {
	CompilationUnit astRoot= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (!(selectedNode instanceof ReturnStatement)) {
		return;
	}
	ReturnStatement returnStatement= (ReturnStatement) selectedNode;
	Expression expression= returnStatement.getExpression();
	if (expression == null) {
		return;
	}
	BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
	if (decl instanceof MethodDeclaration) {
		MethodDeclaration methDecl= (MethodDeclaration) decl;
		Type retType= methDecl.getReturnType2();
		if (retType == null || retType.resolveBinding() == null) {
			return;
		}
		TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, IProposalRelevance.METHOD_RETURNS_VOID, proposals);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:22,代碼來源:ReturnTypeSubProcessor.java

示例3: visit

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的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;
}
 
開發者ID:ioanaverebi,項目名稱:Sparrow,代碼行數:24,代碼來源:OutCodeVisitor.java

示例4: getParameters

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private List<IType> getParameters(List list) {
	List<IType> params = new ArrayList<IType>();
	for (Object elem : list) {
		if (elem instanceof SingleVariableDeclaration) {
			SingleVariableDeclaration param = (SingleVariableDeclaration) elem;
			Type type = param.getType();
			if (type != null && type.resolveBinding() != null && type.resolveBinding().getJavaElement() instanceof IType) {
				params.add((IType) type.resolveBinding().getJavaElement());
			} else {
				if (type.resolveBinding() != null && type.isPrimitiveType()) {
					params.add(new PrimitiveTypeHack(type.resolveBinding().getName()));
				}
			}
		}
	}
	return params;
}
 
開發者ID:ioanaverebi,項目名稱:Sparrow,代碼行數:18,代碼來源:OutCodeVisitor.java

示例5: removeExceptionFromNodeList

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private void removeExceptionFromNodeList(ExceptionInfo toRemove, List<Type> list) {
  ITypeBinding typeToRemove = toRemove.getTypeBinding();
  for (Iterator<Type> iter = list.iterator(); iter.hasNext(); ) {
    Type currentExcType = iter.next();
    ITypeBinding currentType = currentExcType.resolveBinding();
    /* Maybe remove all subclasses of typeToRemove too.
     * Problem:
     * - B extends A;
     * - A.m() throws IOException, Exception;
     * - B.m() throws IOException, AWTException;
     * Removing Exception should remove AWTException,
     * but NOT remove IOException (or a subclass of JavaModelException). */
    // if (Bindings.isSuperType(typeToRemove, currentType))
    if (currentType == null) continue; // newly added or unresolvable type
    if (Bindings.equals(currentType, typeToRemove)
        || toRemove.getElement().getElementName().equals(currentType.getName())) {
      getASTRewrite().remove(currentExcType, fDescription);
      registerImportRemoveNode(currentExcType);
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:22,代碼來源:ChangeSignatureProcessor.java

示例6: addExceptionToNodeList

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private void addExceptionToNodeList(
    ExceptionInfo exceptionInfo, ListRewrite exceptionListRewrite) {
  String fullyQualified = exceptionInfo.getFullyQualifiedName();
  for (Iterator<? extends ASTNode> iter = exceptionListRewrite.getOriginalList().iterator();
      iter.hasNext(); ) {
    Type exType = (Type) iter.next();
    // XXX: existing superclasses of the added exception are redundant and could be removed
    ITypeBinding typeBinding = exType.resolveBinding();
    if (typeBinding == null) continue; // newly added or unresolvable type
    if (typeBinding.getQualifiedName().equals(fullyQualified)) return; // don't add it again
  }
  String importedType = getImportRewrite().addImport(exceptionInfo.getFullyQualifiedName());
  getImportRemover().registerAddedImport(importedType);
  ASTNode exNode = getASTRewrite().createStringPlaceholder(importedType, ASTNode.SIMPLE_TYPE);
  exceptionListRewrite.insertLast(exNode, fDescription);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:17,代碼來源:ChangeSignatureProcessor.java

示例7: getTypesUsedInDeclaration

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
public static Set<ITypeBinding> getTypesUsedInDeclaration(MethodDeclaration methodDeclaration) {
  if (methodDeclaration == null) return new HashSet<ITypeBinding>(0);
  Set<ITypeBinding> result = new HashSet<ITypeBinding>();
  ITypeBinding binding = null;
  Type returnType = methodDeclaration.getReturnType2();
  if (returnType != null) {
    binding = returnType.resolveBinding();
    if (binding != null) result.add(binding);
  }

  for (Iterator<SingleVariableDeclaration> iter = methodDeclaration.parameters().iterator();
      iter.hasNext(); ) {
    binding = iter.next().getType().resolveBinding();
    if (binding != null) result.add(binding);
  }

  for (Iterator<Type> iter = methodDeclaration.thrownExceptionTypes().iterator();
      iter.hasNext(); ) {
    binding = iter.next().resolveBinding();
    if (binding != null) result.add(binding);
  }
  return result;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:24,代碼來源:ReferenceFinderUtil.java

示例8: checkTempTypeForLocalTypeUsage

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private RefactoringStatus checkTempTypeForLocalTypeUsage() {
  VariableDeclarationStatement vds = getTempDeclarationStatement();
  if (vds == null)
    return RefactoringStatus.createFatalErrorStatus(
        RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);
  Type type = vds.getType();
  ITypeBinding binding = type.resolveBinding();
  if (binding == null)
    return RefactoringStatus.createFatalErrorStatus(
        RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);

  IMethodBinding declaringMethodBinding = getMethodDeclaration().resolveBinding();
  ITypeBinding[] methodTypeParameters =
      declaringMethodBinding == null
          ? new ITypeBinding[0]
          : declaringMethodBinding.getTypeParameters();
  LocalTypeAndVariableUsageAnalyzer analyzer =
      new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters);
  type.accept(analyzer);
  boolean usesLocalTypes = !analyzer.getUsageOfEnclosingNodes().isEmpty();
  fTempTypeUsesClassTypeVariables = analyzer.getClassTypeVariablesUsed();
  if (usesLocalTypes)
    return RefactoringStatus.createFatalErrorStatus(
        RefactoringCoreMessages.PromoteTempToFieldRefactoring_uses_type_declared_locally);
  return null;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:PromoteTempToFieldRefactoring.java

示例9: getInferredTypeArguments

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
public static ITypeBinding[] getInferredTypeArguments(Expression invocation) {
  IMethodBinding methodBinding;
  switch (invocation.getNodeType()) {
    case ASTNode.METHOD_INVOCATION:
      methodBinding = ((MethodInvocation) invocation).resolveMethodBinding();
      return methodBinding == null ? null : methodBinding.getTypeArguments();
    case ASTNode.SUPER_METHOD_INVOCATION:
      methodBinding = ((SuperMethodInvocation) invocation).resolveMethodBinding();
      return methodBinding == null ? null : methodBinding.getTypeArguments();
    case ASTNode.CLASS_INSTANCE_CREATION:
      Type type = ((ClassInstanceCreation) invocation).getType();
      ITypeBinding typeBinding = type.resolveBinding();
      return typeBinding == null ? null : typeBinding.getTypeArguments();

    default:
      throw new IllegalArgumentException(invocation.toString());
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:19,代碼來源:Invocations.java

示例10: visit

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
@Override
public boolean visit(VariableDeclarationExpression node) {
  if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
    Type type = node.getType();
    ITypeBinding resourceTypeBinding = type.resolveBinding();
    if (resourceTypeBinding != null) {
      IMethodBinding methodBinding =
          Bindings.findMethodInHierarchy(
              resourceTypeBinding, "close", new ITypeBinding[0]); // $NON-NLS-1$
      if (methodBinding != null) {
        addExceptions(methodBinding.getExceptionTypes(), node.getAST());
      }
    }
  }
  return super.visit(node);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:17,代碼來源:AbstractExceptionAnalyzer.java

示例11: normalizeTypeAndAddImport

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
/**
 * Generates the normalized form and adds the required imports for a given
 * {@link Type}.
 */
public static Type normalizeTypeAndAddImport(AST ast, Type type,
    ImportRewrite imports) {
  ITypeBinding binding = type.resolveBinding();

  // Eliminate type variables in the generated type
  // TODO(): maybe leave the type variables, if we can verify that the type
  // parameters on the target type are exactly the same as those on the source
  // type (all names and type bounds are identical)
  if (JavaASTUtils.containsTypeVariable(type)) {
    binding = binding.getErasure();
  }

  // Report the type binding to the import rewriter, which will record the
  // import and give us either a SimpleType or a QualifiedType to use.
  return imports.addImport(binding, ast);
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:21,代碼來源:JavaASTUtils.java

示例12: getOwnerTypeBinding

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static ITypeBinding getOwnerTypeBinding(
    TypeDeclaration uiBinderSubtype) {
  List<Type> superInterfaces = uiBinderSubtype.superInterfaceTypes();
  for (Type superInterface : superInterfaces) {
    ITypeBinding binding = superInterface.resolveBinding();
    if (binding != null) {
      if (binding.getErasure().getQualifiedName().equals(
          UiBinderConstants.UI_BINDER_TYPE_NAME)) {
        if (superInterface instanceof ParameterizedType) {
          ParameterizedType uiBinderType = (ParameterizedType) superInterface;
          List<Type> typeArgs = uiBinderType.typeArguments();
          if (typeArgs.size() == 2) {
            Type ownerType = typeArgs.get(1);
            return ownerType.resolveBinding();
          }
        }
      }
    }
  }
  return null;
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:23,代碼來源:UiBinderJavaValidator.java

示例13: visitTypeDeclaration

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private RastNode visitTypeDeclaration(AbstractTypeDeclaration node, List<Type> supertypes, String nodeType) {
    	RastNode type;
        String typeName = node.getName().getIdentifier();
        if (node.isPackageMemberTypeDeclaration()) {
            type = model.createType(typeName, packageName, containerStack.peek(), sourceFilePath, node, nodeType);
        } else {
        	type = model.createInnerType(typeName, containerStack.peek(), sourceFilePath, node, nodeType);
        }

        Set<String> annotations = extractAnnotationTypes(node.modifiers());
        if (annotations.contains("Deprecated")) {
        	type.addStereotypes(Stereotype.DEPRECATED);
        }

        for (Type superType : supertypes) {
            ITypeBinding superTypeBinding = superType.resolveBinding();
            extractSupertypesForPostProcessing(type, superTypeBinding);
        }

//        final List<String> references = new ArrayList<String>();
//        node.accept(new DependenciesAstVisitor(true) {
//            @Override
//            protected void onTypeAccess(ASTNode node, ITypeBinding binding) {
//                String typeKey = AstUtils.getKeyFromTypeBinding(binding);
//                references.add(typeKey);
//            }
//        });
//        postProcessReferences.put(type, references);

        return type;
    }
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:32,代碼來源:BindingsRecoveryAstVisitor.java

示例14: visitTypeDeclaration

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private SDType visitTypeDeclaration(AbstractTypeDeclaration node, List<Type> supertypes) {
        SDType type;
        String typeName = node.getName().getIdentifier();
        if (node.isLocalTypeDeclaration()) {
            type = model.createAnonymousType(containerStack.peek(), sourceFilePath, typeName);
        } else {
            type = model.createType(typeName, containerStack.peek(), sourceFilePath);
        }
        //type.setSourceCode(srbForTypes.buildSourceRepresentation(fileContent, node.getStartPosition(), node.getLength()));
        type.setSourceCode(srbForTypes.buildSourceRepresentation(type, fileContent, node));

        Set<String> annotations = extractAnnotationTypes(node.modifiers());
        type.setDeprecatedAnnotation(annotations.contains("Deprecated"));

        for (Type superType : supertypes) {
            ITypeBinding superTypeBinding = superType.resolveBinding();
            extractSupertypesForPostProcessing(type, superTypeBinding);
        }

//        final List<String> references = new ArrayList<String>();
//        node.accept(new DependenciesAstVisitor(true) {
//            @Override
//            protected void onTypeAccess(ASTNode node, ITypeBinding binding) {
//                String typeKey = AstUtils.getKeyFromTypeBinding(binding);
//                references.add(typeKey);
//            }
//        });
//        postProcessReferences.put(type, references);

        return type;
    }
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:32,代碼來源:BindingsRecoveryAstVisitor.java

示例15: addExceptionToThrows

import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private static void addExceptionToThrows(AST ast, MethodDeclaration methodDeclaration, ASTRewrite rewrite, Type type2) {
	ITypeBinding binding = type2.resolveBinding();
	if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) {
		Type newType = (Type) ASTNode.copySubtree(ast, type2);

		ListRewrite listRewriter = rewrite.getListRewrite(methodDeclaration, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY);
		listRewriter.insertLast(newType, null);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:10,代碼來源:QuickAssistProcessor.java


注:本文中的org.eclipse.jdt.core.dom.Type.resolveBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。