Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for ResolvedEnumConstantDeclaration
- Loading branch information
1 parent
999ba88
commit a908cdb
Showing
9 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...rser/symbolsolver/javaparsermodel/declarations/JavaParserAnnotationMemberDeclaration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
package com.github.javaparser.symbolsolver.javaparsermodel.declarations; | |||
|
|||
import com.github.javaparser.ast.body.AnnotationMemberDeclaration; | |||
import com.github.javaparser.ast.expr.Expression; | |||
import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration; | |||
import com.github.javaparser.resolution.types.ResolvedType; | |||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; | |||
|
|||
/** | |||
* @author Federico Tomassetti | |||
*/ | |||
public class JavaParserAnnotationMemberDeclaration implements ResolvedAnnotationMemberDeclaration { | |||
|
|||
private com.github.javaparser.ast.body.AnnotationMemberDeclaration wrappedNode; | |||
private TypeSolver typeSolver; | |||
|
|||
public JavaParserAnnotationMemberDeclaration(AnnotationMemberDeclaration wrappedNode, TypeSolver typeSolver) { | |||
this.wrappedNode = wrappedNode; | |||
this.typeSolver = typeSolver; | |||
} | |||
|
|||
@Override | |||
public Expression getDefaultValue() { | |||
throw new UnsupportedOperationException(); | |||
} | |||
|
|||
@Override | |||
public ResolvedType getType() { | |||
throw new UnsupportedOperationException(); | |||
} | |||
|
|||
@Override | |||
public String getName() { | |||
return wrappedNode.getNameAsString(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...a/com/github/javaparser/symbolsolver/javassistmodel/JavassistEnumConstantDeclaration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
/* | |||
* Copyright 2016 Federico Tomassetti | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package com.github.javaparser.symbolsolver.javassistmodel; | |||
|
|||
import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; | |||
import com.github.javaparser.resolution.types.ResolvedType; | |||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; | |||
import javassist.CtField; | |||
import javassist.bytecode.AccessFlag; | |||
|
|||
/** | |||
* @author Federico Tomassetti | |||
*/ | |||
public class JavassistEnumConstantDeclaration implements ResolvedEnumConstantDeclaration { | |||
|
|||
private CtField ctField; | |||
private TypeSolver typeSolver; | |||
|
|||
public JavassistEnumConstantDeclaration(CtField ctField, TypeSolver typeSolver) { | |||
if (ctField == null) { | |||
throw new IllegalArgumentException(); | |||
} | |||
if ((ctField.getFieldInfo2().getAccessFlags() & AccessFlag.ENUM) != 0) { | |||
throw new IllegalArgumentException("Trying to instantiate a JavassistEnumConstantDeclaration with something which is not an enum field: " + ctField.toString()); | |||
} | |||
this.ctField = ctField; | |||
this.typeSolver = typeSolver; | |||
} | |||
|
|||
|
|||
@Override | |||
public String getName() { | |||
return ctField.getName(); | |||
} | |||
|
|||
@Override | |||
public ResolvedType getType() { | |||
throw new UnsupportedOperationException(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...com/github/javaparser/symbolsolver/reflectionmodel/ReflectionEnumConstantDeclaration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
package com.github.javaparser.symbolsolver.reflectionmodel; | |||
|
|||
import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; | |||
import com.github.javaparser.resolution.types.ResolvedType; | |||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; | |||
|
|||
import java.lang.reflect.Field; | |||
|
|||
public class ReflectionEnumConstantDeclaration implements ResolvedEnumConstantDeclaration { | |||
|
|||
private Field enumConstant; | |||
private TypeSolver typeSolver; | |||
|
|||
public ReflectionEnumConstantDeclaration(Field enumConstant, TypeSolver typeSolver) { | |||
if (!enumConstant.isEnumConstant()) { | |||
throw new IllegalArgumentException("The given field does not represent an enum constant"); | |||
} | |||
this.enumConstant = enumConstant; | |||
this.typeSolver = typeSolver; | |||
} | |||
|
|||
@Override | |||
public String getName() { | |||
return enumConstant.getName(); | |||
} | |||
|
|||
@Override | |||
public ResolvedType getType() { | |||
throw new UnsupportedOperationException(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters