use of org.eclipse.jdt.core.dom.IAnnotationBinding in project j2cl by google.
the class JsInteropUtils method getJsInfo.
/**
* Simply resolve the JsInfo from annotations. Do not do any extra computations. For example, if
* there is no "name" is specified in the annotation, just returns null for JsName.
*/
public static JsInfo getJsInfo(IMethodBinding methodBinding) {
IAnnotationBinding annotation = JsInteropAnnotationUtils.getJsMethodAnnotation(methodBinding);
if (annotation == null) {
annotation = JsInteropAnnotationUtils.getJsConstructorAnnotation(methodBinding);
}
if (annotation == null) {
annotation = JsInteropAnnotationUtils.getJsPropertyAnnotation(methodBinding);
}
boolean isPropertyAccessor = JsInteropAnnotationUtils.getJsPropertyAnnotation(methodBinding) != null;
return getJsInfo(methodBinding, methodBinding.getDeclaringClass(), annotation, isPropertyAccessor);
}
use of org.eclipse.jdt.core.dom.IAnnotationBinding in project lsp4jakarta by eclipse.
the class ReplaceAnnotationProposal method getRewrite.
@Override
protected ASTRewrite getRewrite() throws CoreException {
CompilationUnit fInvocationNode = getInvocationNode();
IBinding fBinding = getBinding();
String[] annotations = getAnnotations();
ASTNode declNode = null;
ASTNode boundNode = fInvocationNode.findDeclaringNode(fBinding);
CompilationUnit newRoot = fInvocationNode;
if (boundNode != null) {
// is same CU
declNode = boundNode;
} else {
newRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
declNode = newRoot.findDeclaringNode(fBinding.getKey());
}
ImportRewrite imports = createImportRewrite(newRoot);
boolean isField = declNode instanceof VariableDeclarationFragment;
if (isField) {
declNode = declNode.getParent();
}
if (declNode instanceof TypeDeclaration || isField) {
AST ast = declNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(declNode, imports);
// remove annotations in the removeAnnotations list
@SuppressWarnings("unchecked") List<? extends ASTNode> children = (List<? extends ASTNode>) (declNode.getParent() instanceof CompilationUnit ? declNode : declNode.getParent()).getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
for (ASTNode child : children) {
if (child instanceof Annotation) {
Annotation annotation = (Annotation) child;
IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
boolean containsAnnotation = Arrays.stream(removeAnnotations).anyMatch(annotationBinding.getName()::contains);
if (containsAnnotation) {
rewrite.remove(child, null);
}
}
}
for (String annotation : annotations) {
Annotation marker = ast.newMarkerAnnotation();
// $NON-NLS-1$
marker.setTypeName(ast.newName(imports.addImport(annotation, importRewriteContext)));
rewrite.getListRewrite(declNode, isField ? FieldDeclaration.MODIFIERS2_PROPERTY : TypeDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
return rewrite;
}
return null;
}
Aggregations