Search in sources :

Example 91 with IBinding

use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.

the class JavadocFinder method getAnnotations.

private String getAnnotations(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) throws URISyntaxException, JavaModelException {
    if (!(element instanceof IPackageFragment)) {
        if (!(element instanceof IAnnotatable))
            return null;
        if (((IAnnotatable) element).getAnnotations().length == 0)
            return null;
    }
    IBinding binding = null;
    //TODO
    //getHoveredASTNode(editorInputElement, hoverRegion);
    ASTNode node = null;
    if (node == null) {
    //todo use ast ported parser,that uses our java model
    //            ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
    //            p.setProject(element.getJavaProject());
    //            p.setBindingsRecovery(true);
    //            try {
    //                binding = p.createBindings(new IJavaElement[]{element}, null)[0];
    //            } catch (OperationCanceledException e) {
    //                return null;
    //            }
    } else {
        binding = resolveBinding(node);
    }
    if (binding == null)
        return null;
    IAnnotationBinding[] annotations = binding.getAnnotations();
    if (annotations.length == 0)
        return null;
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < annotations.length; i++) {
        //TODO: skip annotations that don't have an @Documented annotation?
        addAnnotation(buf, element, annotations[i]);
        //$NON-NLS-1$
        buf.append("<br>");
    }
    return buf.toString();
}
Also used : IAnnotatable(org.eclipse.jdt.core.IAnnotatable) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode)

Example 92 with IBinding

use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.

the class JavadocContentAccess2 method handleConstantValue.

private boolean handleConstantValue(IField field, boolean link) throws JavaModelException {
    String text = null;
    ISourceRange nameRange = field.getNameRange();
    if (SourceRange.isAvailable(nameRange)) {
        CompilationUnit cuNode = ASTProvider.createAST(field.getTypeRoot(), null);
        if (cuNode != null) {
            ASTNode nameNode = NodeFinder.perform(cuNode, nameRange);
            if (nameNode instanceof SimpleName) {
                IBinding binding = ((SimpleName) nameNode).resolveBinding();
                if (binding instanceof IVariableBinding) {
                    IVariableBinding variableBinding = (IVariableBinding) binding;
                    Object constantValue = variableBinding.getConstantValue();
                    if (constantValue != null) {
                        if (constantValue instanceof String) {
                            text = ASTNodes.getEscapedStringLiteral((String) constantValue);
                        } else {
                            // Javadoc tool is even worse for chars...
                            text = constantValue.toString();
                        }
                    }
                }
            }
        }
    }
    if (text == null) {
        Object constant = field.getConstant();
        if (constant != null) {
            text = constant.toString();
        }
    }
    if (text != null) {
        text = HTMLPrinter.convertToHTMLContentWithWhitespace(text);
        if (link) {
            String uri;
            try {
                uri = JavaElementLinks.createURI(urlPrefix, field);
                fBuf.append(JavaElementLinks.createLink(uri, text));
            } catch (URISyntaxException e) {
                LOG.error(e.getMessage(), e);
                return false;
            }
        } else {
            handleText(text);
        }
        return true;
    }
    return false;
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) URISyntaxException(java.net.URISyntaxException) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 93 with IBinding

use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.

the class ConstraintVariableFactory method makeExpressionOrTypeVariable.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.IConstraintVariableFactory#makeExpressionVariable(org.eclipse.jdt
	 * .core.dom.Expression, org.eclipse.jdt.internal.corext.refactoring.typeconstraints.IContext)
	 */
public ConstraintVariable makeExpressionOrTypeVariable(Expression expression, IContext context) {
    IBinding binding = ExpressionVariable.resolveBinding(expression);
    if (binding instanceof ITypeBinding) {
        ICompilationUnit cu = ASTCreator.getCu(expression);
        Assert.isNotNull(cu);
        CompilationUnitRange range = new CompilationUnitRange(cu, expression);
        return makeTypeVariable((ITypeBinding) getKey(binding), expression.toString(), range);
    }
    if (ASTNodes.isLiteral(expression)) {
        Integer nodeType = new Integer(expression.getNodeType());
        if (!fLiteralMap.containsKey(nodeType)) {
            fLiteralMap.put(nodeType, new ExpressionVariable(expression));
            if (REPORT)
                nrCreated++;
        } else {
            if (REPORT)
                nrRetrieved++;
        }
        if (REPORT)
            dumpConstraintStats();
        return fLiteralMap.get(nodeType);
    }
    // For ExpressionVariables, there are two cases. If the expression has a binding
    // we use that as the key. Otherwise, we use the CompilationUnitRange. See
    // also ExpressionVariable.equals()
    ExpressionVariable ev;
    Object key;
    if (binding != null) {
        key = getKey(binding);
    } else {
        key = new CompilationUnitRange(ASTCreator.getCu(expression), expression);
    }
    ev = fExpressionMap.get(key);
    if (ev != null) {
        if (REPORT)
            nrRetrieved++;
    } else {
        ev = new ExpressionVariable(expression);
        fExpressionMap.put(key, ev);
        if (REPORT)
            nrCreated++;
        if (REPORT)
            dumpConstraintStats();
    }
    return ev;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 94 with IBinding

use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.

the class ImportRemover method getPotentialRemoves.

private HashMap<String, IBinding> getPotentialRemoves(List<SimpleName> removedRefs) {
    HashMap<String, IBinding> potentialRemoves = new HashMap<String, IBinding>();
    for (Iterator<SimpleName> iterator = removedRefs.iterator(); iterator.hasNext(); ) {
        SimpleName name = iterator.next();
        if (fAddedImports.contains(name.getIdentifier()) || hasAddedStaticImport(name))
            continue;
        IBinding binding = name.resolveBinding();
        if (binding != null)
            potentialRemoves.put(name.getIdentifier(), binding);
    }
    return potentialRemoves;
}
Also used : HashMap(java.util.HashMap) IBinding(org.eclipse.jdt.core.dom.IBinding) SimpleName(org.eclipse.jdt.core.dom.SimpleName)

Example 95 with IBinding

use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.

the class ImportRemover method getImportsToRemove.

public IBinding[] getImportsToRemove() {
    ArrayList<SimpleName> importNames = new ArrayList<SimpleName>();
    ArrayList<SimpleName> staticNames = new ArrayList<SimpleName>();
    ImportReferencesCollector.collect(fRoot, fProject, null, importNames, staticNames);
    List<SimpleName> removedRefs = new ArrayList<SimpleName>();
    List<SimpleName> unremovedRefs = new ArrayList<SimpleName>();
    divideTypeRefs(importNames, staticNames, removedRefs, unremovedRefs);
    if (removedRefs.size() == 0)
        return new IBinding[0];
    HashMap<String, IBinding> potentialRemoves = getPotentialRemoves(removedRefs);
    for (Iterator<SimpleName> iterator = unremovedRefs.iterator(); iterator.hasNext(); ) {
        SimpleName name = iterator.next();
        potentialRemoves.remove(name.getIdentifier());
    }
    Collection<IBinding> importsToRemove = potentialRemoves.values();
    return importsToRemove.toArray(new IBinding[importsToRemove.size()]);
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) ArrayList(java.util.ArrayList)

Aggregations

IBinding (org.eclipse.jdt.core.dom.IBinding)103 SimpleName (org.eclipse.jdt.core.dom.SimpleName)59 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)48 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)41 ASTNode (org.eclipse.jdt.core.dom.ASTNode)40 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)25 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)25 Name (org.eclipse.jdt.core.dom.Name)20 Expression (org.eclipse.jdt.core.dom.Expression)19 ArrayList (java.util.ArrayList)16 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)14 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)13 CastExpression (org.eclipse.jdt.core.dom.CastExpression)12 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)11 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)11 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)11 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)11 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)11 AST (org.eclipse.jdt.core.dom.AST)10 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)10