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 bug #980 with fully qualified names and shadowed variables #1026

Merged
merged 23 commits into from
Dec 8, 2016
Merged

Fix bug #980 with fully qualified names and shadowed variables #1026

merged 23 commits into from
Dec 8, 2016

Conversation

surli
Copy link
Collaborator

@surli surli commented Dec 6, 2016

Create a new ImportScanner to be used when autoimport is set to false: then all types are checked if they need to be imported in order to avoid shadowed variable.
Tests has been added to check multiple cases.

monperrus and others added 19 commits November 16, 2016 22:28
…ith an or instead of an and. Now the test is failing, proof that the assertion is checked :)
… a local variable in the same block or by a field (or a variable in another block). First detection implemented but patch not satisfying.
…operties. Some choices have been done concerning some set methods in order to pass the test we should discuss.
… set to true or when it is set to false. When set to false, the scanner will detect name conflict and automatically import necessary types.
…g on CtElement (default behaviour until now).
* A scanner dedicated to import only the necessary packages, @see spoon.test.variable.AccessFullyQualifiedTest
*
*/
public class ImportScannerWithoutAllImports extends ImportScannerImpl implements ImportScanner {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to MinimalImportScanner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -37,63 +37,63 @@
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove file from PR?

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'll check that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fact the file changed a lot because my first patch was in this file which caused the checkstyle mess with imports... Not sure how to remove file from the PR properly.

@@ -58,6 +58,9 @@
@Override
public <C extends CtTypedElement> C setType(CtTypeReference<T> type) {
if (type != null) {
type.setParent(this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

not in this PR?

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 merged with files of the previous PR to avoid a file conflict.

CtFieldReference parentType = (CtFieldReference) parent;
String qualifiedName = parentType.getQualifiedName();

String[] splittedName = qualifiedName.split("(\\.|#)");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need to split the qualified name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To detect names like spoon.launcher and avoid to detect spoonLauncher.

CtFieldReference parentType = (CtFieldReference) parent;
String qualifiedName = parentType.getQualifiedName();

String[] splittedName = qualifiedName.split("(\\.|#)");
Copy link
Collaborator

Choose a reason for hiding this comment

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

required?

spoon.addInputResource("src/test/java/spoon/test/variable/testclasses/BurritosFielded.java");
String output = "target/spooned-" + this.getClass().getSimpleName()+"-Field/";
spoon.setSourceOutputDirectory(output);
spoon.run();
Copy link
Collaborator

Choose a reason for hiding this comment

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

for all replace run by buildModel and then filter + strong assert

@monperrus monperrus merged commit a94e255 into INRIA:master Dec 8, 2016
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.

3 participants