当前位置: 首页>>代码示例>>Java>>正文


Java IBinding类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.IBinding的典型用法代码示例。如果您正苦于以下问题:Java IBinding类的具体用法?Java IBinding怎么用?Java IBinding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IBinding类属于org.eclipse.jdt.core.dom包,在下文中一共展示了IBinding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNewCastTypeNode

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
	AST ast= rewrite.getAST();

	ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);

	if (fCastType != null) {
		return importRewrite.addImport(fCastType, ast,context, TypeLocation.CAST);
	}

	ASTNode node= fNodeToCast;
	ASTNode parent= node.getParent();
	if (parent instanceof CastExpression) {
		node= parent;
		parent= parent.getParent();
	}
	while (parent instanceof ParenthesizedExpression) {
		node= parent;
		parent= parent.getParent();
	}
	if (parent instanceof MethodInvocation) {
		MethodInvocation invocation= (MethodInvocation) node.getParent();
		if (invocation.getExpression() == node) {
			IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node);
			ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext);
			if (bindings.length > 0) {
				ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());

				Type newTypeNode= importRewrite.addImport(first, ast, context, TypeLocation.CAST);
				return newTypeNode;
			}
		}
	}
	Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
	return newCastType;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:CastCorrectionProposal.java

示例2: handleSimpleName

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
private void handleSimpleName(SimpleName node) {
  ASTNode firstExpression = node.getParent();
  if (firstExpression instanceof FieldAccess) {
    while (firstExpression instanceof FieldAccess) {
      firstExpression = ((FieldAccess) firstExpression).getExpression();
    }
    if (!(firstExpression instanceof SimpleName)) return;

    node = (SimpleName) firstExpression;
  } else if (firstExpression instanceof SuperFieldAccess) return;

  StructuralPropertyDescriptor parentDescription = node.getLocationInParent();
  if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY
      || parentDescription == SwitchCase.EXPRESSION_PROPERTY) return;

  IBinding binding = node.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return;

  handleVariable(node, (IVariableBinding) binding);
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:CodeStyleFix.java

示例3: handleFragments

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
private boolean handleFragments(List<VariableDeclarationFragment> list, ASTNode declaration) {
  List<VariableDeclarationFragment> toChange = new ArrayList<VariableDeclarationFragment>();

  for (Iterator<VariableDeclarationFragment> iter = list.iterator(); iter.hasNext(); ) {
    VariableDeclarationFragment fragment = iter.next();
    SimpleName name = fragment.getName();
    IBinding resolveBinding = name.resolveBinding();
    if (canAddFinal(resolveBinding, declaration)) {
      IVariableBinding varbinding = (IVariableBinding) resolveBinding;
      if (varbinding.isField()) {
        if (fieldCanBeFinal(fragment, varbinding)) toChange.add(fragment);
      } else {
        if (!fWrittenVariables.containsKey(resolveBinding)) toChange.add(fragment);
      }
    }
  }

  if (toChange.size() == 0) return false;

  ModifierChangeOperation op =
      new ModifierChangeOperation(declaration, toChange, Modifier.FINAL, Modifier.NONE);
  fResult.add(op);
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:VariableDeclarationFix.java

示例4: addType

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
private void addType(IBinding binding, String type, int startPosition) {
  if (type.isEmpty()) {
    return;
  }

  // If 'binding' refers to anything defined in this compilationUnit, don't add it.
  if (compilationUnit.findDeclaringNode(binding) != null) {
    return;
  }

  symbols.put(
      type,
      Metadata.create(
          compilationUnit.getLineNumber(startPosition),
          compilationUnit.getColumnNumber(startPosition),
          false));
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:18,代码来源:ReferencedClassesParser.java

示例5: getBindingLabel

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
/**
 * Returns the label for a Java element with the flags as defined by {@link JavaElementLabels}.
 * @param binding The binding to render.
 * @param flags The text flags as defined in {@link JavaElementLabels}
 * @return the label of the binding
 */
public static String getBindingLabel(IBinding binding, long flags) {
	StringBuffer buffer= new StringBuffer(60);
	if (binding instanceof ITypeBinding) {
		getTypeLabel(((ITypeBinding) binding), flags, buffer);
	} else if (binding instanceof IMethodBinding) {
		getMethodLabel(((IMethodBinding) binding), flags, buffer);
	} else if (binding instanceof IVariableBinding) {
		final IVariableBinding variable= (IVariableBinding) binding;
		if (variable.isField()) {
			getFieldLabel(variable, flags, buffer);
		} else {
			getLocalVariableLabel(variable, flags, buffer);
		}
	}
	return Strings.markLTR(buffer.toString());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:BindingLabelProvider.java

示例6: equals

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
/**
 * Checks if the two arrays of bindings have the same length and
 * their elements are equal. Uses
 * <code>Bindings.equals(IBinding, IBinding)</code> to compare.
 * @param b1 the first array of bindings. Must not be <code>null</code>.
 * @param b2 the second array of bindings.
 * @return boolean
 */
public static boolean equals(IBinding[] b1, IBinding[] b2) {
	Assert.isNotNull(b1);
	if (b1 == b2) {
		return true;
	}
	if (b2 == null) {
		return false;
	}
	if (b1.length != b2.length) {
		return false;
	}
	for (int i= 0; i < b1.length; i++) {
		if (! Bindings.equals(b1[i], b2[i])) {
			return false;
		}
	}
	return true;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:Bindings.java

示例7: getImportName

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
public static String getImportName(IBinding binding) {
	ITypeBinding declaring= null;
	switch (binding.getKind()) {
	case IBinding.TYPE:
		return getRawQualifiedName((ITypeBinding) binding);
	case IBinding.PACKAGE:
		return binding.getName() + ".*"; //$NON-NLS-1$
	case IBinding.METHOD:
		declaring= ((IMethodBinding) binding).getDeclaringClass();
		break;
	case IBinding.VARIABLE:
		declaring= ((IVariableBinding) binding).getDeclaringClass();
		if (declaring == null) {
			return binding.getName(); // array.length
		}

		break;
	default:
		return binding.getName();
	}
	return JavaModelUtil.concatenateName(getRawQualifiedName(declaring), binding.getName());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:Bindings.java

示例8: getEnclosingDeclaration

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
public static IBinding getEnclosingDeclaration(ASTNode node) {
	while(node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			return ((AbstractTypeDeclaration)node).resolveBinding();
		} else if (node instanceof AnonymousClassDeclaration) {
			return ((AnonymousClassDeclaration)node).resolveBinding();
		} else if (node instanceof MethodDeclaration) {
			return ((MethodDeclaration)node).resolveBinding();
		} else if (node instanceof FieldDeclaration) {
			List<?> fragments= ((FieldDeclaration)node).fragments();
			if (fragments.size() > 0) {
				return ((VariableDeclarationFragment)fragments.get(0)).resolveBinding();
			}
		} else if (node instanceof VariableDeclarationFragment) {
			IVariableBinding variableBinding= ((VariableDeclarationFragment)node).resolveBinding();
			if (variableBinding.getDeclaringMethod() != null || variableBinding.getDeclaringClass() != null)
			{
				return variableBinding;
				// workaround for incomplete wiring of DOM bindings: keep searching when variableBinding is unparented
			}
		}
		node= node.getParent();
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodes.java

示例9: findByNode

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
/**
 * Find all nodes connected to the given name node. If the node has a binding then all nodes connected
 * to this binding are returned. If the node has no binding, then all nodes that also miss a binding and have
 * the same name are returned.
 * @param root The root of the AST tree to search
 * @param name The node to find linked nodes for
 * @return Return
 */
public static SimpleName[] findByNode(ASTNode root, SimpleName name) {
	IBinding binding = name.resolveBinding();
	if (binding != null) {
		return findByBinding(root, binding);
	}
	SimpleName[] names= findByProblems(root, name);
	if (names != null) {
		return names;
	}
	int parentKind= name.getParent().getNodeType();
	if (parentKind == ASTNode.LABELED_STATEMENT || parentKind == ASTNode.BREAK_STATEMENT || parentKind == ASTNode.CONTINUE_STATEMENT) {
		ArrayList<SimpleName> res= new ArrayList<>();
		LabelFinder nodeFinder= new LabelFinder(name, res);
		root.accept(nodeFinder);
		return res.toArray(new SimpleName[res.size()]);
	}
	return new SimpleName[] { name };
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:LinkedNodeFinder.java

示例10: visit

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
@Override
public boolean visit(SimpleName node) {
	IBinding binding= node.resolveBinding();
	if (binding == null) {
		return false;
	}
	binding= getDeclaration(binding);

	if (fBinding == binding) {
		fResult.add(node);
	} else if (binding.getKind() != fBinding.getKind()) {
		return false;
	} else if (binding.getKind() == IBinding.METHOD) {
		IMethodBinding curr= (IMethodBinding) binding;
		IMethodBinding methodBinding= (IMethodBinding) fBinding;
		if (methodBinding.overrides(curr) || curr.overrides(methodBinding)) {
			fResult.add(node);
		}
	}
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:LinkedNodeFinder.java

示例11: addStaticImports

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
private void addStaticImports(
		Collection<SimpleName> staticReferences,
		ImportRewrite importRewrite,
		UnresolvableImportMatcher unresolvableImportMatcher) {
	for (SimpleName name : staticReferences) {
		IBinding binding= name.resolveBinding();
		if (binding != null) {
			importRewrite.addStaticImport(binding);
		} else {
			// This could be an unresolvable reference to a static member.
			String identifier= name.getIdentifier();
			Set<String> unresolvableImports= unresolvableImportMatcher.matchStaticImports(identifier);
			for (String unresolvableImport : unresolvableImports) {
				int lastDotIndex= unresolvableImport.lastIndexOf('.');
				// It's OK to skip invalid imports.
				if (lastDotIndex != -1) {
					String declaringTypeName= unresolvableImport.substring(0, lastDotIndex);
					String simpleName= unresolvableImport.substring(lastDotIndex + 1);
					// Whether name refers to a field or to a method is unknown.
					boolean isField= false;
					importRewrite.addStaticImport(declaringTypeName, simpleName, isField, UNRESOLVABLE_IMPORT_CONTEXT);
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:OrganizeImportsOperation.java

示例12: getParameterTypeNamesForSeeTag

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:StubUtility.java

示例13: rewriteAST

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	IBinding binding= fUnusedName.resolveBinding();
	CompilationUnit root= (CompilationUnit) fUnusedName.getRoot();
	String displayString= FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description;
	TextEditGroup group= createTextEditGroup(displayString, cuRewrite);

	if (binding.getKind() == IBinding.TYPE) {
		ITypeBinding decl= ((ITypeBinding) binding).getTypeDeclaration();
		ASTNode declaration= root.findDeclaringNode(decl);
		if (declaration.getParent() instanceof TypeDeclarationStatement) {
			declaration= declaration.getParent();
		}
		rewrite.remove(declaration, group);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:UnusedCodeFix.java

示例14: getDisplayString

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
private String getDisplayString(IBinding binding) {
	switch (binding.getKind()) {
	case IBinding.TYPE:
		return FixMessages.UnusedCodeFix_RemoveUnusedType_description;
	case IBinding.METHOD:
		if (((IMethodBinding) binding).isConstructor()) {
			return FixMessages.UnusedCodeFix_RemoveUnusedConstructor_description;
		} else {
			return FixMessages.UnusedCodeFix_RemoveUnusedPrivateMethod_description;
		}
	case IBinding.VARIABLE:
		if (((IVariableBinding) binding).isField()) {
			return FixMessages.UnusedCodeFix_RemoveUnusedField_description;
		} else {
			return FixMessages.UnusedCodeFix_RemoveUnusedVariabl_description;
		}
	default:
		return ""; //$NON-NLS-1$
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:UnusedCodeFix.java

示例15: createUnusedMemberFix

import org.eclipse.jdt.core.dom.IBinding; //导入依赖的package包/类
public static UnusedCodeFix createUnusedMemberFix(CompilationUnit compilationUnit, IProblemLocation problem, boolean removeAllAssignements) {
	if (isUnusedMember(problem)) {
		SimpleName name= getUnusedName(compilationUnit, problem);
		if (name != null) {
			IBinding binding= name.resolveBinding();
			if (binding != null) {
				if (isFormalParameterInEnhancedForStatement(name)) {
					return null;
				}

				String label= getDisplayString(name, binding, removeAllAssignements);
				RemoveUnusedMemberOperation operation= new RemoveUnusedMemberOperation(new SimpleName[] { name }, removeAllAssignements);
				return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, removeAllAssignements));
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:UnusedCodeFix.java


注:本文中的org.eclipse.jdt.core.dom.IBinding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。