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

Have Refaster resolve classes against the appropriate modules #1239

Closed
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 @@ -84,8 +84,7 @@ public ClassSymbol resolveClass(CharSequence qualifiedClass)
throws CouldNotResolveImportException {
try {
Symbol symbol =
JavaCompiler.instance(context)
.resolveIdent(symtab().java_base, qualifiedClass.toString());
JavaCompiler.instance(context).resolveBinaryNameOrIdent(qualifiedClass.toString());
if (symbol.equals(symtab().errSymbol) || !(symbol instanceof ClassSymbol)) {
throw new CouldNotResolveImportException(qualifiedClass);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

import com.google.common.base.Joiner;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.parser.Parser;
import com.sun.tools.javac.parser.ParserFactory;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
Expand All @@ -44,6 +46,8 @@ public abstract class AbstractUTreeTest {
public void createContext() {
context = new Context();
JavacFileManager.preRegister(context);
JavaCompiler compiler = JavaCompiler.instance(context);
compiler.initModules(List.nil());
unifier = new Unifier(context);
inliner = unifier.createInliner();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,9 @@ public void placeholderAllowedVars() throws IOException {
public void unnecessaryLambdaParens() throws IOException {
runTest("UnnecessaryLambdaParens");
}

@Test
public void nonJdkType() throws IOException {
runTest("NonJdkTypeTemplate");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2014 The Error Prone Authors.
*
* 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.google.errorprone.refaster.testdata;

import com.google.common.collect.ImmutableList;
import java.util.stream.Stream;

/** Test data for {@code NonJdkTypeTemplate}. */
public class NonJdkTypeTemplateExample {
ImmutableList<Integer> example() {
return ImmutableList.copyOf(Stream.of(1).iterator());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2014 The Error Prone Authors.
*
* 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.google.errorprone.refaster.testdata;

import static com.google.common.collect.ImmutableList.toImmutableList;

import com.google.common.collect.ImmutableList;
import java.util.stream.Stream;

/** Test data for {@code NonJdkTypeTemplate}. */
public class NonJdkTypeTemplateExample {
ImmutableList<Integer> example() {
return Stream.of(1).collect(toImmutableList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2016 The Error Prone Authors.
*
* 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.google.errorprone.refaster.testdata.template;

import static com.google.common.collect.ImmutableList.toImmutableList;

import com.google.common.collect.ImmutableList;
import com.google.errorprone.refaster.ImportPolicy;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.google.errorprone.refaster.annotation.UseImportPolicy;
import java.util.stream.Stream;

/** Example template that uses a non-JDK type. */
public class NonJdkTypeTemplate<T> {
@BeforeTemplate
public ImmutableList<T> before(Stream<T> stream) {
return ImmutableList.copyOf(stream.iterator());
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
public ImmutableList<T> after(Stream<T> stream) {
return stream.collect(toImmutableList());
}
}