Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some tests #448

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCAnnotatedType;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCLambda;
import com.sun.tools.javac.tree.JCTree.JCMemberReference;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
Expand Down Expand Up @@ -240,7 +242,7 @@ ITypeBinding resolveType(Type type) {
}
return this.bindings.getTypeBinding(ident.type);
}
if (jcTree instanceof JCFieldAccess access && access.type != null) {
if (jcTree instanceof JCFieldAccess access) {
return this.bindings.getTypeBinding(access.type);
}
if (jcTree instanceof JCPrimitiveTypeTree primitive && primitive.type != null) {
Expand Down Expand Up @@ -383,6 +385,19 @@ IMethodBinding resolveMethod(MethodDeclaration method) {
return null;
}

@Override
IMethodBinding resolveMethod(LambdaExpression lambda) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(lambda);
if (javacElement instanceof JCLambda jcLambda) {
JavacTypeBinding typeBinding = this.bindings.getTypeBinding(jcLambda.type);
if (typeBinding != null && typeBinding.getDeclaredMethods().length == 1) {
return typeBinding.getDeclaredMethods()[0];
}
}
return null;
}

@Override
IMethodBinding resolveMethod(MethodReference methodReference) {
resolve();
Expand Down Expand Up @@ -726,4 +741,14 @@ ITypeBinding resolveWellKnownType(String typeName) {
}
return this.bindings.getTypeBinding(type);
}

@Override
IAnnotationBinding resolveAnnotation(Annotation annotation) {
resolve();
var javac = this.converter.domToJavac.get(annotation);
if (javac instanceof JCAnnotation jcAnnotation) {
return this.bindings.getAnnotationBinding(jcAnnotation.attribute, null);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,19 @@ private TypeParameter convert(JCTypeParameter typeParameter) {
int end = typeParameter.pos + typeParameter.getName().length();
simpleName.setSourceRange(start, end - start);
ret.setName(simpleName);
int annotationsStart = start;
List bounds = typeParameter.bounds;
Iterator i = bounds.iterator();
List<JCExpression> bounds = typeParameter.getBounds();
Iterator<JCExpression> i = bounds.iterator();
while(i.hasNext()) {
JCTree t = (JCTree)i.next();
Type type = convertToType(t);
ret.typeBounds().add(type);
end = typeParameter.getEndPosition(this.javacCompilationUnit.endPositions);
}
if (typeParameter.getAnnotations() != null && this.ast.apiLevel() >= AST.JLS8) {
typeParameter.getAnnotations().stream()
.map(this::convert)
.forEach(ret.modifiers()::add);
}
// org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations = typeParameter.annotations;
// if (annotations != null) {
// if (annotations[0] != null)
Expand Down Expand Up @@ -798,6 +802,20 @@ private MethodDeclaration convertMethodDecl(JCMethodDecl javac, ASTNode parent)
// Compact constructor does not show the parameters even though javac finds them
javac.getParameters().stream().map(this::convertVariableDeclaration).forEach(res.parameters()::add);
}
if (javac.getReceiverParameter() != null) {
Type receiverType = convertToType(javac.getReceiverParameter().getType());
if (receiverType instanceof AnnotatableType annotable) {
javac.getReceiverParameter().getModifiers().getAnnotations().stream() //
.map(this::convert)
.forEach(annotable.annotations()::add);
}
if (receiverType != null) {
res.setReceiverType(receiverType);
}
if (javac.getReceiverParameter().getNameExpression() instanceof JCFieldAccess qualifiedName) {
res.setReceiverQualifier((SimpleName)toName(qualifiedName.getExpression()));
}
}

if( javac.getTypeParameters() != null ) {
Iterator<JCTypeParameter> i = javac.getTypeParameters().iterator();
Expand Down Expand Up @@ -924,7 +942,10 @@ private VariableDeclaration convertVariableDeclaration(JCVariableDecl javac) {
// the array dimensions are part of the type
if (javac.getType() != null) {
if( !(javac.getType() instanceof JCErroneous)) {
res.setType(convertToType(javac.getType()));
Type type = convertToType(javac.getType());
if (type != null) {
res.setType(type);
}
}
}
}
Expand Down Expand Up @@ -1415,6 +1436,7 @@ private Expression convertExpressionImpl(JCExpression javac) {
}
if (javac instanceof JCLambda jcLambda) {
LambdaExpression res = this.ast.newLambdaExpression();
commonSettings(res, javac);
jcLambda.getParameters().stream()
.filter(JCVariableDecl.class::isInstance)
.map(JCVariableDecl.class::cast)
Expand Down Expand Up @@ -2318,10 +2340,12 @@ Type convertToType(JCTree javac) {
return res;
}
if (javac instanceof JCAnnotatedType jcAnnotatedType) {
boolean createNameQualifiedType = jcAnnotatedType.getAnnotations() != null && jcAnnotatedType.getAnnotations().size() > 0;
Type res = null;
if( createNameQualifiedType && this.ast.apiLevel >= AST.JLS8_INTERNAL) {
JCExpression jcpe = jcAnnotatedType.underlyingType;
JCExpression jcpe = jcAnnotatedType.getUnderlyingType();
if( jcAnnotatedType.getAnnotations() != null //
&& !jcAnnotatedType.getAnnotations().isEmpty() //
&& this.ast.apiLevel >= AST.JLS8_INTERNAL
&& !(jcpe instanceof JCWildcard)) {
if( jcpe instanceof JCFieldAccess jcfa2) {
if( jcfa2.selected instanceof JCAnnotatedType || jcfa2.selected instanceof JCTypeApply) {
QualifiedType nameQualifiedType = new QualifiedType(this.ast);
Expand All @@ -2348,7 +2372,7 @@ Type convertToType(JCTree javac) {
annotatableType.annotations().add(convert(annotation));
}
} else if (res instanceof ArrayType arrayType) {
if (!arrayType.dimensions().isEmpty()) {
if (this.ast.apiLevel() >= AST.JLS8 && !arrayType.dimensions().isEmpty()) {
for (JCAnnotation annotation : jcAnnotatedType.getAnnotations()) {
((Dimension)arrayType.dimensions().get(0)).annotations().add(convert(annotation));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.jdt.internal.javac.dom;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
Expand Down Expand Up @@ -85,7 +87,9 @@ public IJavaElement getJavaElement() {
@Override
public String getKey() {
StringBuilder builder = new StringBuilder();
builder.append(this.recipient.getKey());
if (this.recipient != null) {
builder.append(this.recipient.getKey());
}
builder.append('@');
builder.append(this.getAnnotationType().getKey());
return builder.toString();
Expand Down Expand Up @@ -118,4 +122,14 @@ public String getName() {
return getAnnotationType().getName();
}

@Override
public String toString() {
String res = '@' + getName();
if (getAllMemberValuePairs().length > 0) {
res += '(' + Arrays.stream(getAllMemberValuePairs()).map(IMemberValuePairBinding::toString).collect(Collectors.joining(",")) + ')';
} else if (Arrays.stream(getAnnotationType().getDeclaredMethods()).anyMatch(method -> "value".equals(method.getName()) && method.getParameterNames().length == 0)) {
res += "()";
}
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ public boolean isDefault() {
return this.value == this.method.methodSymbol.defaultValue;
}

@Override
public String toString() {
return getName() + " = " + getValue().toString(); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
*******************************************************************************/
package org.eclipse.jdt.internal.javac.dom;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
Expand Down Expand Up @@ -401,4 +403,31 @@ public String[] getParameterNames() {
.toArray(String[]::new);
}

@Override
public String toString() {
return modifiersAsString() + getReturnType().getName() + ' ' + getName().toString() + '('
+ Arrays.stream(getParameterTypes()).map(ITypeBinding::getName).collect(Collectors.joining(","))
+ ") ";
}

protected String modifiersAsString() {
String res = "";
int modifiers = getModifiers();
if (Modifier.isPublic(modifiers)) {
res += "public ";
}
if (Modifier.isProtected(modifiers)) {
res += "protected ";
}
if (Modifier.isPrivate(modifiers)) {
res += "private ";
}
if (Modifier.isStatic(modifiers)) {
res += "static ";
}
if (Modifier.isAbstract(modifiers)) {
res += "abstract ";
}
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
package org.eclipse.jdt.internal.javac.dom;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import javax.lang.model.type.NullType;
Expand Down Expand Up @@ -94,7 +95,7 @@ public int hashCode() {

@Override
public IAnnotationBinding[] getAnnotations() {
return typeSymbol.getAnnotationMirrors().stream()
return this.type.getAnnotationMirrors().stream()
.map(am -> this.resolver.bindings.getAnnotationBinding(am, this))
.toArray(IAnnotationBinding[]::new);
}
Expand Down Expand Up @@ -446,7 +447,7 @@ public String getQualifiedName() {
return "null";
}
if (this.type instanceof ArrayType at) {
return at.elemtype.tsym.getQualifiedName().toString() + "[]";
return this.resolver.bindings.getTypeBinding(at.getComponentType()).getQualifiedName() + "[]";
}

StringBuilder res = new StringBuilder(this.type.toString());
Expand Down Expand Up @@ -706,4 +707,13 @@ public IModuleBinding getModule() {
return null;
}

@Override
public String toString() {
return Arrays.stream(getAnnotations()) //
.map(Object::toString) //
.map(ann -> ann + " ") //
.collect(Collectors.joining())
+ getQualifiedName();
}

}
Loading