forked from eclipse-jdt/eclipse.jdt.core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creation of extension point to swap out CompilationUnitResolver imple…
…mentations Signed-off-by: Rob Stryker <[email protected]> exsd cleanup Signed-off-by: Rob Stryker <[email protected]> Cleanup Signed-off-by: Rob Stryker <[email protected]> Javadoc for added interface Signed-off-by: Rob Stryker <[email protected]> More docs
- Loading branch information
Rob Stryker
committed
Jun 12, 2024
1 parent
fb7c13b
commit 20af383
Showing
7 changed files
with
417 additions
and
60 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
60 changes: 60 additions & 0 deletions
60
org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolverDiscovery.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,60 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat, Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.dom; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IConfigurationElement; | ||
import org.eclipse.core.runtime.IExtension; | ||
import org.eclipse.core.runtime.IExtensionPoint; | ||
import org.eclipse.core.runtime.ILog; | ||
import org.eclipse.core.runtime.Platform; | ||
import org.eclipse.jdt.core.JavaCore; | ||
|
||
class CompilationUnitResolverDiscovery { | ||
private static final String COMPILATION_UNIT_RESOLVER_EXTPOINT_ID = "compilationUnitResolver" ; //$NON-NLS-1$ | ||
private static boolean ERROR_LOGGED = false; | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
static ICompilationUnitResolver getInstance() { | ||
String compilationUnitResolverId = System.getProperty(ICompilationUnitResolver.class.getSimpleName()); | ||
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, COMPILATION_UNIT_RESOLVER_EXTPOINT_ID); | ||
if (extension != null && compilationUnitResolverId != null && !compilationUnitResolverId.isEmpty()) { | ||
IExtension[] extensions = extension.getExtensions(); | ||
for (IExtension ext : extensions) { | ||
IConfigurationElement[] configElements = ext.getConfigurationElements(); | ||
for (final IConfigurationElement configElement : configElements) { | ||
String elementId = configElement.getAttribute("id"); | ||
if( compilationUnitResolverId.equals(elementId)) { | ||
String elementName =configElement.getName(); | ||
if (!("resolver".equals(elementName))) { //$NON-NLS-1$ | ||
continue; | ||
} | ||
try { | ||
Object executableExtension = configElement.createExecutableExtension("class"); | ||
if( executableExtension instanceof ICompilationUnitResolver icur) { | ||
return icur; | ||
} | ||
} catch (CoreException e) { | ||
e.printStackTrace(); | ||
if( !ERROR_LOGGED) { | ||
ILog.get().error("Could not instantiate ICompilationUnitResolver: '" + elementId + "' with class: " + configElement.getAttribute("class"), e); //$NON-NLS-1$ | ||
ERROR_LOGGED = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return CompilationUnitResolver.FACADE; | ||
} | ||
|
||
} |
Oops, something went wrong.