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: ModuleFile.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@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 #2
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 #3
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #4
Source File: DerbyClasspathContainer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: SearchUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @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 #6
Source File: StandardPreferenceManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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 #7
Source File: RefactoringASTParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #8
Source File: SarlTaskTagProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: AddResourcesToClientBundleAction.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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 #10
Source File: JdtSourceLookUpProvider.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
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 #11
Source File: DerbyClasspathContainer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #13
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected final IJavaElement getDestinationContainerAsJavaElement() {
	if (getJavaElementDestination() != null)
		return getJavaElementDestination();
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer == null)
		return null;
	IJavaElement je= JavaCore.create(destinationAsContainer);
	if (je != null && je.exists())
		return je;
	return null;
}
 
Example #14
Source File: NewReportProjectWizard.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private IClasspathEntry[] getClassPathEntries( IProject project )
{
	IClasspathEntry[] internalClassPathEntries = getInternalClassPathEntries( project );
	IClasspathEntry[] entries = new IClasspathEntry[internalClassPathEntries.length + 1];
	System.arraycopy( internalClassPathEntries,
			0,
			entries,
			0,
			internalClassPathEntries.length );
	entries[entries.length - 1] = JavaCore.newContainerEntry( new Path( "org.eclipse.jdt.launching.JRE_CONTAINER" ) ); //$NON-NLS-1$
	return entries;
}
 
Example #15
Source File: JavaMarkerResolutionGenerator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static ICompilationUnit getCompilationUnit(IMarker marker) {
  IResource res = marker.getResource();
  if (res instanceof IFile && res.isAccessible()) {
    IJavaElement element = JavaCore.create((IFile) res);
    if (element instanceof ICompilationUnit) {
      return (ICompilationUnit) element;
    }
  }
  return null;
}
 
Example #16
Source File: JavaElementContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	super.inputChanged(viewer, oldInput, newInput);
	fViewer= (TreeViewer)viewer;
	if (oldInput == null && newInput != null) {
		JavaCore.addElementChangedListener(this);
	} else if (oldInput != null && newInput == null) {
		JavaCore.removeElementChangedListener(this);
	}
	fInput= newInput;
}
 
Example #17
Source File: JavadocProjectContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Object[] getElements(Object inputElement) {
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	try {
		return JavaCore.create(root).getJavaProjects();
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
	return new Object[0];
}
 
Example #18
Source File: RenamingNameSuggestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void initializePrefixesAndSuffixes(IJavaProject project) {
	fFieldPrefixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_FIELD_PREFIXES);
	fFieldSuffixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_FIELD_SUFFIXES);
	fStaticFieldPrefixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES);
	fStaticFieldSuffixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES);
	fLocalPrefixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_LOCAL_PREFIXES);
	fLocalSuffixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_LOCAL_SUFFIXES);
	fArgumentPrefixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_ARGUMENT_PREFIXES);
	fArgumentSuffixes = readCommaSeparatedPreference(project, JavaCore.CODEASSIST_ARGUMENT_SUFFIXES);
}
 
Example #19
Source File: CreateJavaTypeQuickfixes.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IJavaProject getJavaProject(URI uri){
	IProject project = projectUtil.getProject(uri);
	if(project == null){
		return null;
	}
	return JavaCore.create(project);
}
 
Example #20
Source File: UserLibraryWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IClasspathEntry getSelection() {
	if (fEditResult != null) {
		if (fOldClasspathEntry != null && fOldClasspathEntry.getPath().equals(fEditResult.getPath())) {
			return JavaCore.newContainerEntry(fEditResult.getPath(), fOldClasspathEntry.getAccessRules(), fOldClasspathEntry.getExtraAttributes(), fOldClasspathEntry.isExported());
		} else {
			return JavaCore.newContainerEntry(fEditResult.getPath(), false);
		}
	}
	return null;
}
 
Example #21
Source File: SARLClasspathContainerInitializer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException {
	if (CONTAINER_ID.equals(containerPath)) {
		final IClasspathContainer container = new SARLClasspathContainer(containerPath);
		JavaCore.setClasspathContainer(containerPath,
				new IJavaProject[] {project},
				new IClasspathContainer[] {container},
				null);
	}
}
 
Example #22
Source File: AbstractProjectsManagerBasedTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected IJavaProject newEmptyProject() throws Exception {
	IProject testProject = ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME);
	assertEquals(false, testProject.exists());
	projectsManager.createJavaProject(testProject, new Path(getWorkingProjectDirectory().getAbsolutePath()).append(TEST_PROJECT_NAME), "src", "bin", new NullProgressMonitor());
	waitForBackgroundJobs();
	return JavaCore.create(testProject);
}
 
Example #23
Source File: TranslateNodeTest.java    From juniversal with MIT License 5 votes vote down vote up
public CompilationUnit parseCompilationUnit(String java) {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    parser.setSource(java.toCharArray()); // set source
    parser.setResolveBindings(true); // we need bindings later on
    parser.setEnvironment(new String[0], new String[0], null, true);
    parser.setUnitName("TestClass.java");

    // In order to parse 1.8 code, some compiler options need to be set to 1.8
    Map options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
    parser.setCompilerOptions(options);

    CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null /* IProgressMonitor */);

    IProblem[] problems = compilationUnit.getProblems();
    if (problems.length > 0) {
        StringBuilder problemsText = new StringBuilder();

        for (IProblem problem : problems) {
            if (problem.isError()) {
                problemsText.append(problem.getMessage() + "\n");
            }
        }

        if (problemsText.length() > 0)
            throw new RuntimeException(problemsText.toString());
    }

    return compilationUnit;
}
 
Example #24
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
	if (container != null) {
		return Strings.markLTR(container.getDescription());
	}
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (initializer != null) {
		return Strings.markLTR(initializer.getDescription(containerPath, project));
	}
	return BasicElementLabels.getPathLabel(containerPath, false);
}
 
Example #25
Source File: TypeProposalUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
static boolean isImplicitImport(String qualifier, ICompilationUnit cu) {
	if ("java.lang".equals(qualifier)) { //$NON-NLS-1$
		return true;
	}
	String packageName = cu.getParent().getElementName();
	if (qualifier.equals(packageName)) {
		return true;
	}
	String typeName = JavaCore.removeJavaLikeExtension(cu.getElementName());
	String mainTypeName = concatenateName(packageName, typeName);
	return qualifier.equals(mainTypeName);
}
 
Example #26
Source File: JavaSynchronizationContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Object getModelRoot() {
	if (fModelRoot == null)
		fModelRoot= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
	return fModelRoot;
}
 
Example #27
Source File: BaseBuilderGeneratorIT.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
protected CompilationUnit parseAst(char[] source) {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source);
    Map options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
    parser.setCompilerOptions(options);
    CompilationUnit result = (CompilationUnit) parser.createAST(null);
    return result;
}
 
Example #28
Source File: GeneratorSupport.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
private ResourceLoader createResourceLoader(final IProject project) {
  if (project != null) {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null) {
      IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
      try {
        IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true);
        URL[] urls = new URL[classPathEntries.length];
        for (int i = 0; i < classPathEntries.length; i++) {
          IClasspathEntry entry = classPathEntries[i];
          IPath path = null;
          switch (entry.getEntryKind()) {
          case IClasspathEntry.CPE_PROJECT:
            IJavaProject requiredProject = JavaCore.create((IProject) workspaceRoot.findMember(entry.getPath()));
            if (requiredProject != null) {
              path = workspaceRoot.findMember(requiredProject.getOutputLocation()).getLocation();
            }
            break;
          case IClasspathEntry.CPE_SOURCE:
            path = workspaceRoot.findMember(entry.getPath()).getLocation();
            break;
          default:
            path = entry.getPath();
            break;
          }
          if (path != null) {
            urls[i] = path.toFile().toURI().toURL();
          }
        }
        ClassLoader parentClassLoader = javaProject.getClass().getClassLoader();
        URLClassLoader classLoader = new URLClassLoader(urls, parentClassLoader);
        return new CustomResourceLoader(classLoader);
      } catch (MalformedURLException | CoreException e) {
        LOG.warn("Failed to create class loader for project " + project.getName(), e);
      }
    }
  }
  return new ResourceLoaderImpl(GeneratorSupport.class.getClassLoader());
}
 
Example #29
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {

	fBracketMatcher.setSourceVersion(getPreferenceStore().getString(JavaCore.COMPILER_SOURCE));
	support.setCharacterPairMatcher(fBracketMatcher);
	support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR, HIGHLIGHT_BRACKET_AT_CARET_LOCATION, ENCLOSING_BRACKETS);

	super.configureSourceViewerDecorationSupport(support);
}
 
Example #30
Source File: XbaseBuilderConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void updateVersionCombo() {
	boolean useCompliance = useComplianceButton.getSelection();
	versionCombo.setEnabled(!useCompliance);
	if (useCompliance) {
		String javaSourceOption = javaValue(JavaCore.COMPILER_SOURCE);
		JavaVersion javaVersion = preferenceAccess.fromCompilerSourceLevel(javaSourceOption);
		JavaVersion selectedVersion = JavaVersion.values()[versionCombo.getSelectionIndex()];
		if (javaVersion != selectedVersion) {
			versionCombo.select(javaVersion.ordinal());
		}
	}
}