use of org.eclipse.jdt.core.dom.TypeDeclaration in project sts4 by spring-projects.
the class AbstractSourceLinks method findTypeRegion.
protected Region findTypeRegion(CompilationUnit cu, String fqName) {
if (cu == null) {
return null;
}
int[] values = new int[] { 0, -1 };
int lastDotIndex = fqName.lastIndexOf('.');
String packageName = fqName.substring(0, lastDotIndex);
String typeName = fqName.substring(lastDotIndex + 1);
if (packageName.equals(cu.getPackage().getName().getFullyQualifiedName())) {
Stack<String> visitedType = new Stack<>();
cu.accept(new ASTVisitor() {
private boolean visitDeclaration(AbstractTypeDeclaration node) {
visitedType.push(node.getName().getIdentifier());
if (values[1] < 0) {
if (String.join("$", visitedType.toArray(new String[visitedType.size()])).equals(typeName)) {
values[0] = node.getName().getStartPosition();
values[1] = node.getName().getLength();
}
}
return values[1] < 0;
}
@Override
public boolean visit(TypeDeclaration node) {
return visitDeclaration(node);
}
@Override
public boolean visit(AnnotationTypeDeclaration node) {
return visitDeclaration(node);
}
@Override
public void endVisit(AnnotationTypeDeclaration node) {
visitedType.pop();
super.endVisit(node);
}
@Override
public void endVisit(TypeDeclaration node) {
visitedType.pop();
super.endVisit(node);
}
});
}
return values[1] < 0 ? null : new Region(values[0], values[1]);
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project sts4 by spring-projects.
the class ComponentSymbolProvider method getBeanName.
private String getBeanName(Annotation node) {
ASTNode parent = node.getParent();
if (parent instanceof TypeDeclaration) {
TypeDeclaration type = (TypeDeclaration) parent;
String beanName = type.getName().toString();
if (beanName.length() > 0 && Character.isUpperCase(beanName.charAt(0))) {
beanName = Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1);
}
return beanName;
}
return null;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project sts4 by spring-projects.
the class ConditionalsLiveHoverProvider method matchesAnnotation.
/**
* @param annotation
* @param jsonKey
* @return true if the annotation matches the information in the json key from
* the running app.
*/
protected boolean matchesAnnotation(Annotation annotation, LiveConditional liveConditional) {
// First check that the annotation matches the live conditional annotation
String annotationName = annotation.resolveTypeBinding().getName();
if (!liveConditional.getMessage().contains(annotationName)) {
return false;
}
// Check that Java type in annotation in editor matches Java information in the live Conditional
ASTNode parent = annotation.getParent();
String typeInfo = liveConditional.getTypeInfo();
if (parent instanceof MethodDeclaration) {
MethodDeclaration methodDec = (MethodDeclaration) parent;
IMethodBinding binding = methodDec.resolveBinding();
String annotationDeclaringClassName = binding.getDeclaringClass().getName();
String annotationMethodName = binding.getName();
return typeInfo.contains(annotationDeclaringClassName) && typeInfo.contains(annotationMethodName);
} else if (parent instanceof TypeDeclaration) {
TypeDeclaration typeDec = (TypeDeclaration) parent;
String annotationDeclaringClassName = typeDec.resolveBinding().getName();
return typeInfo.contains(annotationDeclaringClassName);
}
return false;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project che by eclipse.
the class UnimplementedCodeFix method createMakeTypeAbstractFix.
public static UnimplementedCodeFix createMakeTypeAbstractFix(CompilationUnit root, IProblemLocation problem) {
ASTNode typeNode = getSelectedTypeNode(root, problem);
if (!(typeNode instanceof TypeDeclaration))
return null;
TypeDeclaration typeDeclaration = (TypeDeclaration) typeNode;
MakeTypeAbstractOperation operation = new MakeTypeAbstractOperation(typeDeclaration);
String label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_addabstract_description, BasicElementLabels.getJavaElementName(typeDeclaration.getName().getIdentifier()));
return new UnimplementedCodeFix(label, root, new CompilationUnitRewriteOperation[] { operation });
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project che by eclipse.
the class UnimplementedCodeFix method createCleanUp.
public static ICleanUpFix createCleanUp(CompilationUnit root, boolean addMissingMethod, boolean makeTypeAbstract, IProblemLocation[] problems) {
Assert.isLegal(!addMissingMethod || !makeTypeAbstract);
if (!addMissingMethod && !makeTypeAbstract)
return null;
if (problems.length == 0)
return null;
ArrayList<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
for (int i = 0; i < problems.length; i++) {
IProblemLocation problem = problems[i];
if (addMissingMethod) {
ASTNode typeNode = getSelectedTypeNode(root, problem);
if (typeNode != null && !isTypeBindingNull(typeNode)) {
operations.add(new AddUnimplementedMethodsOperation(typeNode));
}
} else {
ASTNode typeNode = getSelectedTypeNode(root, problem);
if (typeNode instanceof TypeDeclaration) {
operations.add(new MakeTypeAbstractOperation((TypeDeclaration) typeNode));
}
}
}
if (operations.size() == 0)
return null;
String label;
if (addMissingMethod) {
label = CorrectionMessages.UnimplementedMethodsCorrectionProposal_description;
} else {
label = CorrectionMessages.UnimplementedCodeFix_MakeAbstractFix_label;
}
return new UnimplementedCodeFix(label, root, operations.toArray(new CompilationUnitRewriteOperation[operations.size()]));
}
Aggregations