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();
}
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;
}
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;
}
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;
}
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()]);
}
Aggregations