org.eclipse.jdt.core.JavaCore Java Examples
The following examples show how to use
org.eclipse.jdt.core.JavaCore.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BinaryRefactoringHistoryWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Configures the classpath of the project before refactoring. * * @param project * the java project * @param root * the package fragment root to refactor * @param folder * the temporary source folder * @param monitor * the progress monitor to use * @throws IllegalStateException * if the plugin state location does not exist * @throws CoreException * if an error occurs while configuring the class path */ private static void configureClasspath(final IJavaProject project, final IPackageFragmentRoot root, final IFolder folder, final IProgressMonitor monitor) throws IllegalStateException, CoreException { try { monitor.beginTask(JarImportMessages.JarImportWizard_prepare_import, 200); final IClasspathEntry entry= root.getRawClasspathEntry(); final IClasspathEntry[] entries= project.getRawClasspath(); final List<IClasspathEntry> list= new ArrayList<IClasspathEntry>(); list.addAll(Arrays.asList(entries)); final IFileStore store= EFS.getLocalFileSystem().getStore(JavaPlugin.getDefault().getStateLocation().append(STUB_FOLDER).append(project.getElementName())); if (store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) store.delete(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); store.mkdir(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); folder.createLink(store.toURI(), IResource.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); addExclusionPatterns(list, folder.getFullPath()); for (int index= 0; index < entries.length; index++) { if (entries[index].equals(entry)) list.add(index, JavaCore.newSourceEntry(folder.getFullPath())); } project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), false, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } finally { monitor.done(); } }
Example #2
Source File: SarlTaskTagProvider.java From sarl with Apache License 2.0 | 6 votes |
@Override public TaskTags getTaskTags(Resource resource) { final IPreferenceValues prefs = this.preferenceValuesProvider.getPreferenceValues(resource); final String namePref = prefs.getPreference(new PreferenceKey( JavaCore.COMPILER_TASK_TAGS, "TODO,FIXME,XXX")); //$NON-NLS-1$ final String prioritiesPref = prefs.getPreference(new PreferenceKey( JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,HIGH,NORMAL")); //$NON-NLS-1$ final String caseSensitivePref = prefs.getPreference(new PreferenceKey( JavaCore.COMPILER_TASK_CASE_SENSITIVE, JavaCore.ENABLED)); final List<TaskTag> tags = PreferenceTaskTagProvider.parseTags(namePref, prioritiesPref); final TaskTags taskTags = new TaskTags(); taskTags.setCaseSensitive(caseSensitivePref.equals(JavaCore.ENABLED)); taskTags.getTaskTags().addAll(tags); return taskTags; }
Example #3
Source File: SearchUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * @param match * the search match * @return the enclosing {@link ICompilationUnit} of the given match, or null * iff none */ public static ICompilationUnit getCompilationUnit(SearchMatch match) { IJavaElement enclosingElement = getEnclosingJavaElement(match); if (enclosingElement != null) { if (enclosingElement instanceof ICompilationUnit) { return (ICompilationUnit) enclosingElement; } ICompilationUnit cu = (ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { return cu; } } IJavaElement jElement = JavaCore.create(match.getResource()); if (jElement != null && jElement.exists() && jElement.getElementType() == IJavaElement.COMPILATION_UNIT) { return (ICompilationUnit) jElement; } return null; }
Example #4
Source File: ComplianceConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IExecutionEnvironment getEE() { if (fProject == null) return null; try { IClasspathEntry[] entries= JavaCore.create(fProject).getRawClasspath(); for (int i= 0; i < entries.length; i++) { IClasspathEntry entry= entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String eeId= JavaRuntime.getExecutionEnvironmentId(entry.getPath()); if (eeId != null) { return JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId); } } } } catch (CoreException e) { JavaPlugin.log(e); } return null; }
Example #5
Source File: StandardPreferenceManager.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void updateParallelBuild(int maxConcurrentBuilds) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceDescription description = workspace.getDescription(); if (description.getMaxConcurrentBuilds() == maxConcurrentBuilds) { return; } description.setMaxConcurrentBuilds(maxConcurrentBuilds); try { workspace.setDescription(description); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Problems setting maxConcurrentBuilds from workspace.", e); } String stringValue = maxConcurrentBuilds != 1 ? Boolean.TRUE.toString() : Boolean.FALSE.toString(); IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); pref.put(MavenPreferenceConstants.P_BUILDER_USE_NULL_SCHEDULING_RULE, stringValue); pref = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID); }
Example #6
Source File: RefactoringASTParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the compiler options used for creating the refactoring AST. * <p> * Turns all errors and warnings into ignore and disables task tags. The customizable set of * compiler options only contains additional Eclipse options. The standard JDK compiler options * can't be changed anyway. * * @param element an element (not the Java model) * @return compiler options */ public static Map<String, String> getCompilerOptions(IJavaElement element) { IJavaProject project= element.getJavaProject(); Map<String, String> options= project.getOptions(true); for (Iterator<String> iter= options.keySet().iterator(); iter.hasNext();) { String key= iter.next(); String value= options.get(key); if (JavaCore.ERROR.equals(value) || JavaCore.WARNING.equals(value)) { // System.out.println("Ignoring - " + key); options.put(key, JavaCore.IGNORE); } } options.put(JavaCore.COMPILER_PB_MAX_PER_UNIT, "0"); //$NON-NLS-1$ options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$ return options; }
Example #7
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Handles the exception thrown from JDT Core when the attached Javadoc * cannot be retrieved due to accessibility issues or location URL issue. This exception is not * logged but the exceptions occurred due to other reasons are logged. * * @param e the exception thrown when retrieving the Javadoc fails * @return the String message for why the Javadoc could not be retrieved * @since 3.9 */ public static String handleFailedJavadocFetch(CoreException e) { IStatus status= e.getStatus(); if (JavaCore.PLUGIN_ID.equals(status.getPlugin())) { Throwable cause= e.getCause(); int code= status.getCode(); // See bug 120559, bug 400060 and bug 400062 if (code == IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC_TIMEOUT || (code == IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC && (cause instanceof FileNotFoundException || cause instanceof SocketException || cause instanceof UnknownHostException || cause instanceof ProtocolException))) return CorextMessages.JavaDocLocations_error_gettingAttachedJavadoc; } JavaPlugin.log(e); return CorextMessages.JavaDocLocations_error_gettingJavadoc; }
Example #8
Source File: JdtSourceLookUpProvider.java From java-debug with Eclipse Public License 1.0 | 6 votes |
private static IClassFile resolveClassFile(String uriString) { if (uriString == null || uriString.isEmpty()) { return null; } try { URI uri = new URI(uriString); if (uri != null && JDT_SCHEME.equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) { String handleId = uri.getQuery(); IJavaElement element = JavaCore.create(handleId); IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); return cf; } } catch (URISyntaxException e) { // ignore } return null; }
Example #9
Source File: ModuleFile.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
@Override protected String doGetPackageName() { IFolder moduleFolder = (IFolder) getFile().getParent(); IJavaElement javaElement = JavaCore.create(moduleFolder); // Maven module name - maven 1 or maven 2 plugins String mavenModuleName = WebAppProjectProperties.getGwtMavenModuleName(moduleFolder.getProject()); // not null, then it must be a gwt maven project 2 String shortName = WebAppProjectProperties.getGwtMavenModuleShortName(moduleFolder.getProject()); if (mavenModuleName != null && !mavenModuleName.isEmpty() && shortName != null && !shortName.isEmpty() && mavenModuleName.contains(".")) { String gwtMavenPackage2 = mavenModuleName.replaceAll("(.*)\\..*", "$1"); return gwtMavenPackage2; } if (javaElement != null) { if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { return javaElement.getElementName(); } } else { // TODO: handle super-source case here } return ""; }
Example #10
Source File: DerbyClasspathContainer.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public DerbyClasspathContainer() { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); Bundle bundle = Platform.getBundle(CommonNames.CORE_PATH); Enumeration en = bundle.findEntries("/", "*.jar", true); String rootPath = null; try { rootPath = FileLocator.resolve(FileLocator.find(bundle, new Path("/"), null)).getPath(); } catch(IOException e) { Logger.log(e.getMessage(), IStatus.ERROR); } while(en.hasMoreElements()) { IClasspathEntry cpe = JavaCore.newLibraryEntry(new Path(rootPath+'/'+((URL)en.nextElement()).getFile()), null, null); entries.add(cpe); } IClasspathEntry[] cpes = new IClasspathEntry[entries.size()]; _entries = (IClasspathEntry[])entries.toArray(cpes); }
Example #11
Source File: DerbyClasspathContainer.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public DerbyClasspathContainer() { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); Bundle bundle = Platform.getBundle(CommonNames.CORE_PATH); Enumeration en = bundle.findEntries("/", "*.jar", true); String rootPath = null; try { rootPath = FileLocator.resolve(FileLocator.find(bundle, new Path("/"), null)).getPath(); } catch(IOException e) { Logger.log(e.getMessage(), IStatus.ERROR); } while(en.hasMoreElements()) { IClasspathEntry cpe = JavaCore.newLibraryEntry(new Path(rootPath+'/'+((URL)en.nextElement()).getFile()), null, null); entries.add(cpe); } IClasspathEntry[] cpes = new IClasspathEntry[entries.size()]; _entries = (IClasspathEntry[])entries.toArray(cpes); }
Example #12
Source File: AddResourcesToClientBundleAction.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private static IType findFirstTopLevelClientBundleType(IFile file) { try { IJavaElement element = JavaCore.create(file); if (element instanceof ICompilationUnit) { ICompilationUnit cu = (ICompilationUnit) element; if (cu.exists()) { for (IType type : cu.getTypes()) { if (ClientBundleUtilities.isClientBundle(cu.getJavaProject(), type)) { return type; } } } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } return null; }
Example #13
Source File: PackagesView.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Answers if the given <code>element</code> is a valid * input for this part. * * @param element the object to test * @return <true> if the given element is a valid input */ @Override protected boolean isValidInput(Object element) { if (element instanceof IJavaProject || (element instanceof IPackageFragmentRoot && ((IJavaElement)element).getElementName() != IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) try { IJavaProject jProject= ((IJavaElement)element).getJavaProject(); if (jProject != null) return jProject.getProject().hasNature(JavaCore.NATURE_ID); } catch (CoreException ex) { return false; } return false; }
Example #14
Source File: AbstractGhidraLaunchShortcut.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void launch(IEditorPart editor, String mode) { IEditorInput input = editor.getEditorInput(); IResource resource = input.getAdapter(IResource.class); if (resource != null) { launch(JavaCore.create(resource.getProject()), mode); } }
Example #15
Source File: FormatterMojo.java From formatter-maven-plugin with Apache License 2.0 | 5 votes |
/** * Return the options to be passed when creating {@link CodeFormatter} instance. * * @return the formatting options or null if not config file found * * @throws MojoExecutionException * the mojo execution exception */ private Map<String, String> getFormattingOptions(String newConfigFile) throws MojoExecutionException { if (this.useEclipseDefaults) { getLog().info("Using Ecipse Defaults"); // Use defaults only for formatting Map<String, String> options = new HashMap<>(); options.put(JavaCore.COMPILER_SOURCE, this.compilerSource); options.put(JavaCore.COMPILER_COMPLIANCE, this.compilerCompliance); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, this.compilerTargetPlatform); return options; } return getOptionsFromConfigFile(newConfigFile); }
Example #16
Source File: IDEReportClasspathResolver.java From birt with Eclipse Public License 1.0 | 5 votes |
public String[] resolveClasspath( Object adaptable ) { IProject project = adaptProject( adaptable ); // IWorkspace space = ResourcesPlugin.getWorkspace( ); // IWorkspaceRoot root = space.getRoot( ); String value = PreferenceFactory.getInstance( ) .getPreferences( ReportPlugin.getDefault( ), project ) .getString( ReportPlugin.CLASSPATH_PREFERENCE ); List<IClasspathEntry> list = IDEClassPathBlock.getEntries( value ); List<String> strs = getAllClassPathFromEntries( list ); try { if ( project == null || !project.hasNature( JavaCore.NATURE_ID )) { return strs.toArray( new String[strs.size( )] ); } } catch ( CoreException e ) { return strs.toArray( new String[strs.size( )] ); } //Set<String> paths = getProjectClasspath( project ); List<String> temp = getProjectClasspath( project, true, true ); for (int i=0; i<temp.size( ); i++) { addToList( strs, temp.get( i ) ); } return strs.toArray( new String[strs.size( )] ); }
Example #17
Source File: XtendBuilderParticipantTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * https://bugs.eclipse.org/bugs/show_bug.cgi?id=400193 */ @Test public void testSourceRelativeOutput() throws Exception { IProject project = testHelper.getProject(); String srcFolder = "/foo/bar/bug"; JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), srcFolder); String path = srcFolder + "/Foo.xtend"; String fullFileName = project.getName() + path; IFile sourceFile = testHelper.createFileImpl(fullFileName, "class Foo {}"); assertTrue(sourceFile.exists()); waitForBuild(); IFile generatedFile = project.getFile("foo/bar/xtend-gen/Foo.java"); assertTrue(generatedFile.exists()); IFile traceFile = testHelper.getProject().getFile("foo/bar/xtend-gen/.Foo.java._trace"); assertTrue(traceFile.exists()); IFile classFile = testHelper.getProject().getFile("/bin/Foo.class"); assertTrue(classFile.exists()); List<IPath> traceFiles = traceMarkers.findTraceFiles(sourceFile); assertTrue(traceFiles.contains(traceFile.getFullPath())); sourceFile.delete(false, new NullProgressMonitor()); waitForBuild(); assertFalse(generatedFile.exists()); assertFalse(traceFile.exists()); }
Example #18
Source File: ImportOrganizeTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Before public void setup() throws Exception { importProjects("maven/quickstart"); project = WorkspaceHelper.getProject("quickstart"); javaProject = JavaCore.create(project); Hashtable<String, String> options= TestOptions.getDefaultOptions(); options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, String.valueOf(99)); javaProject.setOptions(options); fSourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src/main/java")); File src = fSourceFolder.getResource().getLocation().toFile(); src.mkdirs(); project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); }
Example #19
Source File: MethodBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private JavaElement getUnresolvedJavaElement() { if (JavaCore.getPlugin() == null) { return null; } if (!(this.resolver instanceof DefaultBindingResolver)) return null; DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver; if (!defaultBindingResolver.fromJavaProject) return null; return Util.getUnresolvedJavaElement( this.binding, defaultBindingResolver.workingCopyOwner, defaultBindingResolver.getBindingsToNodesMap()); }
Example #20
Source File: ParentChecker.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isDescendantOf(IResource subResource, IJavaElement superElement) { IResource parent= subResource.getParent(); while(parent != null){ IJavaElement el= JavaCore.create(parent); if (el != null && el.exists() && el.equals(superElement)) { return true; } parent= parent.getParent(); } return false; }
Example #21
Source File: Repository.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected CreateBonitaBPMProjectOperation newProjectWorkspaceOperation(final String projectName, final IWorkspace workspace) { return new CreateBonitaBPMProjectOperation(workspace, projectName) .addNature(BonitaProjectNature.NATURE_ID) .addNature("org.eclipse.xtext.ui.shared.xtextNature") .addNature(JavaCore.NATURE_ID) .addNature("org.eclipse.pde.PluginNature") .addNature("org.eclipse.jdt.groovy.core.groovyNature") .addBuilder("org.eclipse.jdt.core.javabuilder") .addBuilder("org.eclipse.xtext.ui.shared.xtextBuilder") .addBuilder("org.eclipse.pde.ManifestBuilder") .addBuilder("org.eclipse.pde.SchemaBuilder") .addBuilder("org.eclipse.wst.validation.validationbuilder"); }
Example #22
Source File: ReorgCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String getVMInstallCompliance(IVMInstall install) { if (install instanceof IVMInstall2) { String compliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, JavaCore.VERSION_1_3); return compliance; } return JavaCore.VERSION_1_1; }
Example #23
Source File: StringCleanUp.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Map<String, String> getRequiredOptions() { Map<String, String> result= new Hashtable<String, String>(); if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS) || isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)) result.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING); return result; }
Example #24
Source File: ASTProcessor.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Parses the provided file, using the given libraryPaths and sourcePaths as context. The libraries may be either * jar files or references to directories containing class files. * * The sourcePaths must be a reference to the top level directory for sources (eg, for a file * src/main/java/org/example/Foo.java, the source path would be src/main/java). * * The wildcard resolver provides a fallback for processing wildcard imports that the underlying parser was unable * to resolve. */ public static List<ClassReference> analyze(WildcardImportResolver importResolver, Set<String> libraryPaths, Set<String> sourcePaths, Path sourceFile) { ASTParser parser = ASTParser.newParser(AST.JLS11); parser.setEnvironment(libraryPaths.toArray(new String[libraryPaths.size()]), sourcePaths.toArray(new String[sourcePaths.size()]), null, true); parser.setBindingsRecovery(false); parser.setResolveBindings(true); Map options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); parser.setCompilerOptions(options); String fileName = sourceFile.getFileName().toString(); parser.setUnitName(fileName); try { parser.setSource(FileUtils.readFileToString(sourceFile.toFile()).toCharArray()); } catch (IOException e) { throw new ASTException("Failed to get source for file: " + sourceFile.toString() + " due to: " + e.getMessage(), e); } parser.setKind(ASTParser.K_COMPILATION_UNIT); CompilationUnit cu = (CompilationUnit) parser.createAST(null); ReferenceResolvingVisitor visitor = new ReferenceResolvingVisitor(importResolver, cu, sourceFile.toString()); cu.accept(visitor); return visitor.getJavaClassReferences(); }
Example #25
Source File: WizardAction.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
/** * The action has been activated. The argument of the method represents the 'real' action sitting in the workbench UI. * * @see IWorkbenchWindowActionDelegate#run */ @Override public void run(final IAction action) { final AnalysisKickOff akf = new AnalysisKickOff(); akf.setUp(JavaCore.create(Utils.getCurrentlySelectedIProject())); akf.run(); }
Example #26
Source File: DiagnosticsCommandTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@After public void tearDown() throws Exception { JavaLanguageServerPlugin.getNonProjectDiagnosticsState().setGlobalErrorLevel(originalGlobalErrorLevel); javaClient.disconnect(); for (ICompilationUnit cu : JavaCore.getWorkingCopies(null)) { cu.discardWorkingCopy(); } }
Example #27
Source File: JavaModelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public ResourceMapping[] getMappings(final IResource resource, final ResourceMappingContext context, final IProgressMonitor monitor) throws CoreException { final IJavaElement element= JavaCore.create(resource); if (element != null) return new ResourceMapping[] { JavaElementResourceMapping.create(element)}; final Object adapted= resource.getAdapter(ResourceMapping.class); if (adapted instanceof ResourceMapping) return new ResourceMapping[] { ((ResourceMapping) adapted)}; return new ResourceMapping[] { new JavaResourceMapping(resource)}; }
Example #28
Source File: TypeMismatchQuickFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test @Ignore("Requires LocalCorrectionsSubProcessor") public void testTypeMismatchForParameterizedType() throws Exception { Map<String, String> tempOptions = new HashMap<>(fJProject1.getOptions(false)); tempOptions.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING); tempOptions.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING); fJProject1.setOptions(tempOptions); IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("import java.util.*;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" List list= new ArrayList<Integer>();\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("import java.util.*;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" List<Integer> list= new ArrayList<Integer>();\n"); buf.append(" }\n"); buf.append("}\n"); Expected e1 = new Expected("Remove unused import", buf.toString()); assertCodeActionExists(cu, e1); }
Example #29
Source File: UserJavaProject.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
/** * Convert a project to javaProject if its nature is Java * * @param project * @return javaProject * @throws CoreException */ private IJavaProject toJavaProject(final IProject project) throws CoreException { IJavaProject javaProject = null; if (project.hasNature(JavaCore.NATURE_ID)) { javaProject = JavaCore.create(project); } else { Activator.getDefault().logError(Constants.NOT_JAVA_PROJECT); } return javaProject; }
Example #30
Source File: ReferencesHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private IJavaSearchScope createSearchScope() throws JavaModelException { IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects(); int scope = IJavaSearchScope.SOURCES; if (preferenceManager.isClientSupportsClassFileContent()) { scope |= IJavaSearchScope.APPLICATION_LIBRARIES; } return SearchEngine.createJavaSearchScope(projects, scope); }