org.eclipse.jdt.core.dom.TypeDeclaration#resolveBinding ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.TypeDeclaration#resolveBinding ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * If true is returned, the type declaration has a resolvable binding.
 */
private boolean shouldValidateType(TypeDeclaration typeDecl) {
  if (typeDecl.isInterface()) {
    return false;
  }

  IType ownerType = getType(typeDecl);
  if (ownerType == null) {
    return false;
  }

  if (!uiBinderToOwner.isOwnerType(ownerType.getFullyQualifiedName('.'))) {
    return false;
  }

  if (typeDecl.resolveBinding() == null) {
    GWTPluginLog.logWarning("Could not resolve binding for "
        + typeDecl.getName().getFullyQualifiedName());
    return false;
  }

  return true;
}
 
/**
 * If true is returned, the type declaration has a resolveable binding.
 */
private boolean shouldValidateType(TypeDeclaration typeDecl) {
  if (!typeDecl.isInterface()) {
    return false;
  }

  ITypeBinding typeBinding = typeDecl.resolveBinding();
  if (typeBinding == null) {
    return false;
  }

  if (!isUiBinder(typeBinding)) {
    return false;
  }

  // Passed all tests, so validate
  return true;
}
 
private static boolean shouldValidateType(TypeDeclaration type) {
  if (!type.isInterface()) {
    return false;
  }

  ITypeBinding typeBinding = type.resolveBinding();
  if (typeBinding == null) {
    return false;
  }

  if (!ClientBundleUtilities.isClientBundle(typeBinding)) {
    return false;
  }

  // Don't actually validate the built-in ClientBundle and
  // ClientBundleWithLookup types.
  String typeName = typeBinding.getQualifiedName();
  if (typeName.equals(ClientBundleUtilities.CLIENT_BUNDLE_TYPE_NAME)
      || typeName.equals(ClientBundleUtilities.CLIENT_BUNDLE_WITH_LOOKUP_TYPE_NAME)) {
    return false;
  }

  // Passed all tests, so validate
  return true;
}
 
源代码4 项目: txtUML   文件: ClassDiagramExporter.java
@Override
public boolean visit(TypeDeclaration node) {

	if (ElementTypeTeller.isAssociation(node)) {
		ITypeBinding typeBinding = node.resolveBinding();
		if (typeBinding != null) {
			try {
				allLinks.add(loader.loadClass(typeBinding.getQualifiedName()));
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
	}

	return false;
}
 
源代码5 项目: junion   文件: StructCache.java
public static Entry get(TypeDeclaration type) {
	ITypeBinding ib = type.resolveBinding();
	if(ib == null) {
		CompilerError.exec(CompilerError.TYPE_NOT_FOUND, type.toString());
		return null;
	}
	else return get(ib);
}
 
private static IType getType(TypeDeclaration typeDecl) {
  if (typeDecl == null) {
    return null;
  }

  ITypeBinding typeBinding = typeDecl.resolveBinding();
  if (typeBinding == null) {
    return null;
  }

  IJavaElement javaElement = typeBinding.getJavaElement();
  return (javaElement instanceof IType ? (IType) javaElement : null);
}
 
/**
 * Returns a new {@link RemoteServiceProblem} for a
 * {@link RemoteServiceProblemType#MISSING_ASYNC_TYPE}.
 */
static RemoteServiceProblem newMissingAsyncType(
    TypeDeclaration syncTypeDeclaration) {
  ITypeBinding syncTypeBinding = syncTypeDeclaration.resolveBinding();
  String computeAsyncTypeName = RemoteServiceUtilities.computeAsyncTypeName(syncTypeBinding.getName());
  return RemoteServiceProblem.create(syncTypeDeclaration.getName(),
      RemoteServiceProblemType.MISSING_ASYNC_TYPE,
      new String[] {computeAsyncTypeName},
      new String[] {syncTypeBinding.getQualifiedName()});
}
 
@Override
protected void createTypeMembers(IType newType, final ImportsManager imports,
    IProgressMonitor monitor) throws CoreException {
  TypeDeclaration asyncTypeDeclaration = JavaASTUtils.findTypeDeclaration(
      newType.getJavaProject(), newType.getFullyQualifiedName('.'));
  ITypeBinding asyncTypeBinding = asyncTypeDeclaration.resolveBinding();

  ImportManagerAdapter importAdapter = new ImportManagerAdapter() {

    public String addImport(ITypeBinding typeBinding) {
      return imports.addImport(typeBinding);
    }

    public String addImport(String qualifiedTypeName) {
      return imports.addImport(qualifiedTypeName);
    }
  };

  List<IMethodBinding> syncMethodsToConvert = computeSyncMethodsThatNeedAsyncVersions(
      syncTypeBinding, asyncTypeBinding);
  for (IMethodBinding overridableSyncMethod : syncMethodsToConvert) {
    String methodContents = createMethodContents(newType, importAdapter,
        overridableSyncMethod, isAddComments());

    // Create the new method
    newType.createMethod(methodContents, null, false, monitor);
  }
}
 
@Override
public boolean visit(TypeDeclaration node) {
	ITypeBinding binding= node.resolveBinding();
	if (binding != null) {
		binding= binding.getTypeDeclaration();
		if (isMovedMember(binding))
			return false;
	}
	return super.visit(node);
}
 
private boolean shouldParamClassBeStatic(TypeDeclaration enclosingTypeDecl) {
	if (enclosingTypeDecl.isPackageMemberTypeDeclaration()) {
		return true;
	}
	ITypeBinding binding= enclosingTypeDecl.resolveBinding();
	int modifiers= binding != null ? binding.getModifiers() : enclosingTypeDecl.getModifiers();
	return Modifier.isStatic(modifiers);
}
 
源代码11 项目: JDeodorant   文件: MethodCallAnalyzer.java
private MethodDeclaration getInvokedMethodDeclaration(IMethodBinding methodBinding) {
	MethodDeclaration invokedMethodDeclaration = null;
	IMethod iMethod2 = (IMethod)methodBinding.getJavaElement();
	if(iMethod2 != null) {
		IClassFile methodClassFile = iMethod2.getClassFile();
		LibraryClassStorage instance = LibraryClassStorage.getInstance();
		CompilationUnit methodCompilationUnit = instance.getCompilationUnit(methodClassFile);
		Set<TypeDeclaration> methodTypeDeclarations = extractTypeDeclarations(methodCompilationUnit);
		for(TypeDeclaration methodTypeDeclaration : methodTypeDeclarations) {
			ITypeBinding methodTypeDeclarationBinding = methodTypeDeclaration.resolveBinding();
			if(methodTypeDeclarationBinding != null && (methodTypeDeclarationBinding.isEqualTo(methodBinding.getDeclaringClass()) ||
					methodTypeDeclarationBinding.getBinaryName().equals(methodBinding.getDeclaringClass().getBinaryName()))) {
				MethodDeclaration[] methodDeclarations2 = methodTypeDeclaration.getMethods();
				for(MethodDeclaration methodDeclaration2 : methodDeclarations2) {
					if(methodDeclaration2.resolveBinding().isEqualTo(methodBinding) ||
							equalSignature(methodDeclaration2.resolveBinding(), methodBinding)) {
						invokedMethodDeclaration = methodDeclaration2;
						break;
					}
				}
				if(invokedMethodDeclaration != null)
					break;
			}
		}
	}
	return invokedMethodDeclaration;
}
 
源代码12 项目: apidiff   文件: UtilTools.java
public static String getTypeName(TypeDeclaration type){
	return type.resolveBinding() == null ? "" : type.resolveBinding().getQualifiedName();
}
 
源代码13 项目: ck   文件: DIT.java
@Override
public void visit(TypeDeclaration node) {
	ITypeBinding binding = node.resolveBinding();
	if(binding!=null) calculate(binding);

}
 
public static List<IJavaCompletionProposal> createProposals(IInvocationContext context, IProblemLocation problem)
    throws JavaModelException {
  String syncTypeName = problem.getProblemArguments()[0];
  IJavaProject javaProject = context.getCompilationUnit().getJavaProject();
  IType syncType = JavaModelSearch.findType(javaProject, syncTypeName);
  if (syncType == null || !syncType.isInterface()) {
    return Collections.emptyList();
  }

  CompilationUnit cu = context.getASTRoot();
  ASTNode coveredNode = problem.getCoveredNode(cu);
  TypeDeclaration syncTypeDecl = (TypeDeclaration) coveredNode.getParent();
  assert (cu.getAST().hasResolvedBindings());

  ITypeBinding syncTypeBinding = syncTypeDecl.resolveBinding();
  assert (syncTypeBinding != null);

  String asyncName = RemoteServiceUtilities.computeAsyncTypeName(problem.getProblemArguments()[0]);
  AST ast = context.getASTRoot().getAST();
  Name name = ast.newName(asyncName);

  /*
   * HACK: NewCUUsingWizardProposal wants a name that has a parent expression so we create an
   * assignment so that the name has a valid parent
   */
  ast.newAssignment().setLeftHandSide(name);

  IJavaElement typeContainer = syncType.getParent();
  if (typeContainer.getElementType() == IJavaElement.COMPILATION_UNIT) {
    typeContainer = syncType.getPackageFragment();
  }

  // Add a create async interface proposal
  CreateAsyncInterfaceProposal createAsyncInterfaceProposal = new CreateAsyncInterfaceProposal(
      context.getCompilationUnit(), name, K_INTERFACE, typeContainer, 2, syncTypeBinding);

  // Add the stock create interface proposal
  NewCompilationUnitUsingWizardProposal fallbackProposal = new NewCompilationUnitUsingWizardProposal(
      context.getCompilationUnit(), name, K_INTERFACE, context.getCompilationUnit().getParent(), 1);

  return Arrays.<IJavaCompletionProposal>asList(createAsyncInterfaceProposal, fallbackProposal);
}
 
@Override
public boolean visit(TypeDeclaration changedType) {
  if (!changedType.isInterface()) {
    return true;
  }

  ITypeBinding typeBinding = changedType.resolveBinding();
  if (typeBinding == null) {
    return true;
  }

  PairedInterfaceValidator validator;
  String typeQualifiedName = typeBinding.getQualifiedName();
  TypeDeclaration dependentType = null;

  String dependentTypeQualifiedName;

  if (RemoteServiceUtilities.isSynchronousInterface(typeBinding)) {
    dependentTypeQualifiedName = RemoteServiceUtilities.computeAsyncTypeName(typeQualifiedName);
    dependentType = JavaASTUtils.findTypeDeclaration(javaProject,
        dependentTypeQualifiedName);
    validator = synchronousInterfaceValidator;
  } else {
    validator = asynchronousInterfaceValidator;
    dependentTypeQualifiedName = RemoteServiceUtilities.computeSyncTypeName(typeQualifiedName);
    if (dependentTypeQualifiedName == null) {
      // Not an async interface...
      return true;
    }

    dependentType = JavaASTUtils.findTypeDeclaration(javaProject,
        dependentTypeQualifiedName);
  }

  // Add the type dependency (even if the type doesn't yet resolve)
  dependentTypes.add(dependentTypeQualifiedName);

  ITypeBinding dependentTypeBinding = null;
  if (dependentType != null) {
    dependentTypeBinding = dependentType.resolveBinding();
  }

  problems.addAll(validator.validate(changedType, dependentTypeBinding));

  return true;
}
 
源代码16 项目: jdt2famix   文件: AstVisitor.java
@SuppressWarnings("unchecked")
@Override
public boolean visit(TypeDeclaration node) {
	ITypeBinding binding = node.resolveBinding();
	if (binding == null) {
		logNullBinding("type declaration", node.getName(),
				((CompilationUnit) node.getRoot()).getLineNumber(node.getStartPosition()));
		return false;
	}
	Type type = importer.ensureTypeFromTypeBinding(binding);

	org.eclipse.jdt.core.dom.Type superclassType = node.getSuperclassType();
	/*
	 * This is an ugly patch. When the binding to the superclass or super interfaces
	 * cannot be resolved, we try to recover as much info as possible We do it here
	 * because it is hard to pass around the dom type
	 */
	if (binding.getSuperclass() == null && superclassType != null)
		importer.createInheritanceFromSubtypeToSuperDomType(type, superclassType);

	if (superclassType != null)
		type.getSuperInheritances().stream().filter(inheritance -> (inheritance.getSuperclass() instanceof Class
				&& !((Class) inheritance.getSuperclass()).getIsInterface())
				|| (inheritance.getSuperclass() instanceof ParameterizedType
						&& ((ParameterizedType) inheritance.getSuperclass()).getParameterizableClass() != null
						&& !((ParameterizedType) inheritance.getSuperclass()).getParameterizableClass()
								.getIsInterface()))
				.findFirst().ifPresent(in -> importer.createLightweightSourceAnchor(in, superclassType));

	if (binding.getInterfaces().length == 0 && !node.superInterfaceTypes().isEmpty())
		node.superInterfaceTypes().stream().forEach(t -> {
			importer.createInheritanceFromSubtypeToSuperDomType(type, (org.eclipse.jdt.core.dom.Type) t);
		});

	// create source anchors for implemented interfaces references
	createSourceAnchorsForInterfaceInheritance(node, type);

	type.setIsStub(false);
	importer.createSourceAnchor(type, node);
	importer.createLightweightSourceAnchor(type, node.getName());
	importer.ensureCommentFromBodyDeclaration(type, node);
	importer.pushOnContainerStack(type);
	return true;
}
 
public boolean visit(TypeDeclaration node) {
	if (found(node, node.getName()) && this.resolveBinding)
		this.foundBinding = node.resolveBinding();
	return true;
}