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

add CtTypeMember.getTopLevelType() #1004

Merged
merged 4 commits into from
Nov 26, 2016

Conversation

pvojtechovsky
Copy link
Collaborator

I have added new method

interface CtTypeMember
	/**
	 * Returns top level declaring type of this. 
         * If this is already a TopLevelType, then it returns this
	 */
	<T> CtType<T> getTopLevelType();

I need it for next PR, which brings some new Refactoring methods for changing of the name of the CtVariable based elements.

Please give me feedback, if such method is acceptable. If yes, then I will add test case too.

Note: I also moved some getDeclaringType to more common place in the hierarchy of CtExecutableImpl, so I did not had to copy the implementation of getTopLevelType 3 times.

@@ -30,6 +30,11 @@
* @return declaring class
*/
@DerivedProperty
CtType<?> getDeclaringType();
<T> CtType<T> getDeclaringType();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not backward-compatible. do you really need to add generics?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed that to solve another compilation problem in CtConstructorImpl ... but I will try different solution


/**
* Returns top level declaring type of this. If this is already a TopLevelType, then it returns this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns the top level type declaring this type if an inner type. If this is already a top-level type, then returns itself.

* Returns top level declaring type of this. If this is already a TopLevelType, then it returns this
*/
@DerivedProperty
<T> CtType<T> getTopLevelType();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes a lot of sense. it is OK to me.

@msteinbeck
Copy link
Contributor

I'm looking for exactly the same feature.

@monperrus
Copy link
Collaborator

excellent. Could you add tests?

@msteinbeck
Copy link
Contributor

Is it possible to add a similar method that returns the parent type instead of the top level type?

@pvojtechovsky
Copy link
Collaborator Author

Is it possible to add a similar method that returns the parent type instead of the top level type?

there is getDeclaringType() for that, is not?

@tdurieux
Copy link
Collaborator

or getParent(CtType.Class)

@pvojtechovsky
Copy link
Collaborator Author

Please merge it if it pass. I need this method in #1007

@monperrus monperrus merged commit ddf4db5 into INRIA:master Nov 26, 2016
@pvojtechovsky pvojtechovsky deleted the addGetTopLevelType branch November 28, 2016 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants