Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previous commit (bc5dbad) removed jdt, along with support of the -pro…
…cessor flag. Reimplement support for the flag, using the javac pre-processing step
- Loading branch information
Showing
5 changed files
with
136 additions
and
12 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
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
Binary file added
BIN
+1.99 KB
translator/src/test/resources/com/google/devtools/j2objc/annotations/ExplicitProcessor.jar
Binary file not shown.
68 changes: 68 additions & 0 deletions
68
...rc/test/resources/com/google/devtools/j2objc/annotations/J2ObjCTestExplicitProcessor.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.devtools.j2objc.annotations; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.Set; | ||
|
||
import javax.annotation.processing.AbstractProcessor; | ||
import javax.annotation.processing.RoundEnvironment; | ||
import javax.annotation.processing.SupportedAnnotationTypes; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.SourceVersion; | ||
import javax.tools.Diagnostic; | ||
import javax.tools.JavaFileObject; | ||
|
||
/** | ||
* A test processor for annotation processing. This is the processor in Processor.jar. | ||
*/ | ||
@SupportedAnnotationTypes("com.google.j2objc.annotations.ObjectiveCName") | ||
public class J2ObjCTestExplicitProcessor extends AbstractProcessor { | ||
|
||
@Override | ||
public SourceVersion getSupportedSourceVersion() { | ||
return SourceVersion.latest(); | ||
} | ||
|
||
@Override | ||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
for (TypeElement type: annotations) { | ||
Writer w = null; | ||
try { | ||
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile("ExplicitProcessingResult"); | ||
w = sourceFile.openWriter(); | ||
w.write("public class ExplicitProcessingResult {" | ||
+ " public String getResultForExplicitProcessor() {" | ||
+ " return \"" + type.getSimpleName() + "\";" | ||
+ " }" | ||
+ "}"); | ||
} catch (IOException e) { | ||
processingEnv.getMessager().printMessage( | ||
Diagnostic.Kind.ERROR, "Could not process annotations"); | ||
e.printStackTrace(); | ||
return false; | ||
} finally { | ||
if (w != null) { | ||
try { | ||
w.close(); | ||
} catch (IOException e) {} | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |