Created
February 11, 2013 04:44
-
-
Save zaki50/4752673 to your computer and use it in GitHub Desktop.
プロジェクト作成時などに、 gen フォルダはデフォルトで警告無視となるようにします。 Eclipse JUNO 以降でのみ効果あり。
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
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java | |
index 19a7101..d7409da 100644 | |
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java | |
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java | |
@@ -210,6 +210,8 @@ public class NewProjectCreator { | |
private static final String LAYOUT_TEMPLATE = "layout.template"; //$NON-NLS-1$ | |
private static final String MAIN_LAYOUT_XML = "main.xml"; //$NON-NLS-1$ | |
+ private static final String KEY_IGNORE_WARNINGS = "ignore_optional_problems"; //$NON-NLS-1$ | |
+ | |
private final NewProjectWizardState mValues; | |
private final IRunnableContext mRunnableContext; | |
@@ -719,7 +721,8 @@ public class NewProjectCreator { | |
// Setup class path: mark folders as source folders | |
IJavaProject javaProject = JavaCore.create(project); | |
- setupSourceFolders(javaProject, sourceFolders, monitor); | |
+ setupSourceFolder(javaProject, sourceFolders[0], monitor); | |
+ setupGenSourceFolder(javaProject, sourceFolders[1], monitor); | |
if (((Boolean) parameters.get(PARAM_IS_NEW_PROJECT)).booleanValue()) { | |
// Create files in the project if they don't already exist | |
@@ -1326,12 +1329,39 @@ public class NewProjectCreator { | |
* Adds the given folder to the project's class path. | |
* | |
* @param javaProject The Java Project to update. | |
- * @param sourceFolders Template Parameters. | |
+ * @param sourceFolder Source folder path to add. | |
* @param monitor An existing monitor. | |
* @throws JavaModelException if the classpath could not be set. | |
*/ | |
- private void setupSourceFolders(IJavaProject javaProject, String[] sourceFolders, | |
+ private void setupSourceFolder(IJavaProject javaProject, String sourceFolder, | |
IProgressMonitor monitor) throws JavaModelException { | |
+ setupSourceFolder(javaProject, sourceFolder, false, monitor); | |
+ } | |
+ | |
+ /** | |
+ * Adds the given folder to the project's class path as a generated source folder. | |
+ * | |
+ * @param javaProject The Java Project to update. | |
+ * @param sourceFolder Source folder path to add. | |
+ * @param monitor An existing monitor. | |
+ * @throws JavaModelException if the classpath could not be set. | |
+ */ | |
+ private void setupGenSourceFolder(IJavaProject javaProject, String sourceFolder, | |
+ IProgressMonitor monitor) throws JavaModelException { | |
+ setupSourceFolder(javaProject, sourceFolder, true, monitor); | |
+ } | |
+ | |
+ /** | |
+ * Adds the given folder to the project's class path. | |
+ * | |
+ * @param javaProject The Java Project to update. | |
+ * @param sourceFolder Source folder path to add. | |
+ * @param forGenerated whether {@code sourceFolder} is for generated code. | |
+ * @param monitor An existing monitor. | |
+ * @throws JavaModelException if the classpath could not be set. | |
+ */ | |
+ private void setupSourceFolder(IJavaProject javaProject, String sourceFolder, | |
+ boolean forGenerated, IProgressMonitor monitor) throws JavaModelException { | |
IProject project = javaProject.getProject(); | |
// get the list of entries. | |
@@ -1340,15 +1370,23 @@ public class NewProjectCreator { | |
// remove the project as a source folder (This is the default) | |
entries = removeSourceClasspath(entries, project); | |
- // add the source folders. | |
- for (String sourceFolder : sourceFolders) { | |
- IFolder srcFolder = project.getFolder(sourceFolder); | |
+ IFolder srcFolder = project.getFolder(sourceFolder); | |
- // remove it first in case. | |
- entries = removeSourceClasspath(entries, srcFolder); | |
- entries = ProjectHelper.addEntryToClasspath(entries, | |
- JavaCore.newSourceEntry(srcFolder.getFullPath())); | |
+ // remove it first in case. | |
+ entries = removeSourceClasspath(entries, srcFolder); | |
+ | |
+ // add the source folder. | |
+ IClasspathEntry srcEntry; | |
+ if (forGenerated) { | |
+ // suppress compiler warnings in the folder | |
+ srcEntry = JavaCore.newSourceEntry(srcFolder.getFullPath(), new IPath[] {}, | |
+ new IPath[] {}, null, new IClasspathAttribute[] { | |
+ JavaCore.newClasspathAttribute(KEY_IGNORE_WARNINGS, "true") | |
+ }); | |
+ } else { | |
+ srcEntry = JavaCore.newSourceEntry(srcFolder.getFullPath()); | |
} | |
+ entries = ProjectHelper.addEntryToClasspath(entries, srcEntry); | |
javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment