Java Code Examples for org.eclipse.jdt.core.dom.TypeDeclaration#resolveBinding()

The following examples show how to use org.eclipse.jdt.core.dom.TypeDeclaration#resolveBinding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiBinderJavaValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: UiBinderJavaValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: ClassDiagramExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: ClientBundleValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: RemoteServiceProblemFactory.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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()});
}
 
Example 6
Source File: MethodCallAnalyzer.java    From JDeodorant with MIT License 5 votes vote down vote up
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;
}
 
Example 7
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: ReferenceAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: NewAsyncRemoteServiceInterfaceCreationWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@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);
  }
}
 
Example 10
Source File: StructCache.java    From junion with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}
 
Example 11
Source File: UiBinderJavaValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: RemoteServiceValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
@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;
}
 
Example 13
Source File: CreateAsyncInterfaceProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
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);
}
 
Example 14
Source File: AstVisitor.java    From jdt2famix with Eclipse Public License 1.0 4 votes vote down vote up
@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;
}
 
Example 15
Source File: DIT.java    From ck with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(TypeDeclaration node) {
	ITypeBinding binding = node.resolveBinding();
	if(binding!=null) calculate(binding);

}
 
Example 16
Source File: DOMFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(TypeDeclaration node) {
	if (found(node, node.getName()) && this.resolveBinding)
		this.foundBinding = node.resolveBinding();
	return true;
}
 
Example 17
Source File: UtilTools.java    From apidiff with MIT License 4 votes vote down vote up
public static String getTypeName(TypeDeclaration type){
	return type.resolveBinding() == null ? "" : type.resolveBinding().getQualifiedName();
}