use of org.eclipse.jdt.core.dom.StringLiteral in project generator by mybatis.
the class ExistingJavaFileVisitor method isGeneratedAnnotation.
@SuppressWarnings("unchecked")
private boolean isGeneratedAnnotation(Annotation annotation) {
String typeName = annotation.getTypeName().getFullyQualifiedName();
if (isGeneratedType(typeName)) {
if (annotation.isNormalAnnotation()) {
NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
List<MemberValuePair> values = normalAnnotation.values();
for (MemberValuePair pair : values) {
String name = pair.getName().getFullyQualifiedName();
String value = null;
Expression exp = pair.getValue();
if (exp instanceof StringLiteral) {
value = ((StringLiteral) exp).getLiteralValue();
}
if (MyBatisGenerator.class.getName().equals(value) && "value".equals(name)) {
return true;
}
}
} else if (annotation.isSingleMemberAnnotation()) {
SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
Expression exp = singleMemberAnnotation.getValue();
String value = null;
if (exp instanceof StringLiteral) {
value = ((StringLiteral) exp).getLiteralValue();
}
if (MyBatisGenerator.class.getName().equals(value)) {
return true;
}
}
}
return false;
}
use of org.eclipse.jdt.core.dom.StringLiteral in project sts4 by spring-projects.
the class WebfluxPathFinder method visit.
@Override
public boolean visit(MethodInvocation node) {
boolean visitChildren = true;
if (node != this.root) {
IMethodBinding methodBinding = node.resolveMethodBinding();
try {
if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
String name = methodBinding.getName();
if (name != null && WebfluxUtils.REQUEST_PREDICATE_ALL_PATH_METHODS.contains(name)) {
StringLiteral stringLiteral = WebfluxUtils.extractStringLiteralArgument(node);
if (stringLiteral != null) {
Range range = doc.toRange(stringLiteral.getStartPosition(), stringLiteral.getLength());
path.add(new WebfluxRouteElement(stringLiteral.getLiteralValue(), range));
}
}
}
} catch (BadLocationException e) {
// ignore
}
if (WebfluxUtils.isRouteMethodInvocation(methodBinding)) {
visitChildren = false;
}
}
return visitChildren;
}
use of org.eclipse.jdt.core.dom.StringLiteral in project sts4 by spring-projects.
the class ScopeCompletionProcessor method provideCompletions.
@Override
public Collection<ICompletionProposal> provideCompletions(ASTNode node, Annotation annotation, ITypeBinding type, int offset, IDocument doc) {
List<ICompletionProposal> result = new ArrayList<>();
try {
if (node instanceof SimpleName && node.getParent() instanceof MemberValuePair) {
MemberValuePair memberPair = (MemberValuePair) node.getParent();
// case: @Scope(value=<*>)
if ("value".equals(memberPair.getName().toString()) && memberPair.getValue().toString().equals("$missing$")) {
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, offset, offset, "");
result.add(proposal);
}
}
} else // case: @Scope(<*>)
if (node == annotation && doc.get(offset - 1, 2).endsWith("()")) {
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, offset, offset, "");
result.add(proposal);
}
} else if (node instanceof StringLiteral && node.getParent() instanceof Annotation) {
// case: @Scope("...")
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
String prefix = doc.get(node.getStartPosition(), offset - node.getStartPosition());
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
if (completion.getValue().startsWith(prefix)) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, node.getStartPosition(), node.getStartPosition() + node.getLength(), prefix);
result.add(proposal);
}
}
}
} else if (node instanceof StringLiteral && node.getParent() instanceof MemberValuePair) {
MemberValuePair memberPair = (MemberValuePair) node.getParent();
// case: @Scope(value=<*>)
if ("value".equals(memberPair.getName().toString()) && node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
String prefix = doc.get(node.getStartPosition(), offset - node.getStartPosition());
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
if (completion.getValue().startsWith(prefix)) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, node.getStartPosition(), node.getStartPosition() + node.getLength(), prefix);
result.add(proposal);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of org.eclipse.jdt.core.dom.StringLiteral in project sts4 by spring-projects.
the class ActiveProfilesProvider method getLiveHoverHints.
@Override
public Collection<Range> getLiveHoverHints(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
if (runningApps.length > 0) {
Builder<Range> ranges = ImmutableList.builder();
nameRange(doc, annotation).ifPresent(ranges::add);
Set<String> allActiveProfiles = getAllActiveProfiles(runningApps);
annotation.accept(new ASTVisitor() {
@Override
public boolean visit(StringLiteral node) {
String value = ASTUtils.getLiteralValue(node);
if (value != null && allActiveProfiles.contains(value)) {
rangeOf(doc, node).ifPresent(ranges::add);
}
return true;
}
});
return ranges.build();
}
return ImmutableList.of();
}
use of org.eclipse.jdt.core.dom.StringLiteral in project eclipse-cs by checkstyle.
the class StringLiteralEqualityQuickfix method handleGetCorrectingASTVisitor.
/**
* {@inheritDoc}
*/
@Override
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartPosition) {
return new ASTVisitor() {
@SuppressWarnings("unchecked")
@Override
public boolean visit(InfixExpression node) {
if (containsPosition(lineInfo, node.getStartPosition())) {
StringLiteral literal = null;
Expression otherOperand = null;
if (node.getLeftOperand() instanceof StringLiteral) {
literal = (StringLiteral) node.getLeftOperand();
otherOperand = node.getRightOperand();
} else if (node.getRightOperand() instanceof StringLiteral) {
literal = (StringLiteral) node.getRightOperand();
otherOperand = node.getLeftOperand();
} else {
return true;
}
Expression replacementNode = null;
MethodInvocation equalsInvocation = node.getAST().newMethodInvocation();
// $NON-NLS-1$
equalsInvocation.setName(node.getAST().newSimpleName("equals"));
equalsInvocation.setExpression((Expression) ASTNode.copySubtree(node.getAST(), literal));
equalsInvocation.arguments().add(ASTNode.copySubtree(node.getAST(), otherOperand));
// expression
if (node.getOperator().equals(InfixExpression.Operator.NOT_EQUALS)) {
PrefixExpression prefixExpression = node.getAST().newPrefixExpression();
prefixExpression.setOperator(PrefixExpression.Operator.NOT);
prefixExpression.setOperand(equalsInvocation);
replacementNode = prefixExpression;
} else {
replacementNode = equalsInvocation;
}
replaceNode(node, replacementNode);
}
return true;
}
/**
* Replaces the given node with the replacement node (using reflection
* since I am not aware of a proper API to do this).
*
* @param node
* the node to replace
* @param replacementNode
* the replacement
*/
private void replaceNode(ASTNode node, ASTNode replacementNode) {
try {
if (node.getLocationInParent().isChildProperty()) {
String property = node.getLocationInParent().getId();
String capitalizedProperty = property.substring(0, 1).toUpperCase() + property.substring(1);
String setterMethodName = "set" + capitalizedProperty;
Class<?> testClass = node.getClass();
while (testClass != null) {
try {
Method setterMethod = node.getParent().getClass().getMethod(setterMethodName, testClass);
setterMethod.invoke(node.getParent(), replacementNode);
break;
} catch (NoSuchMethodException e) {
testClass = testClass.getSuperclass();
}
}
} else if (node.getLocationInParent().isChildListProperty()) {
Method listMethod = node.getParent().getClass().getMethod(node.getLocationInParent().getId(), (Class<?>[]) null);
@SuppressWarnings("unchecked") List<ASTNode> list = (List<ASTNode>) listMethod.invoke(node.getParent(), (Object[]) null);
list.set(list.indexOf(node), replacementNode);
}
} catch (InvocationTargetException e) {
CheckstyleLog.log(e);
} catch (IllegalAccessException e) {
CheckstyleLog.log(e);
} catch (NoSuchMethodException e) {
CheckstyleLog.log(e);
}
}
};
}
Aggregations