Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
get rid of reflective code. eclipse/xtext-core#506
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <[email protected]>
  • Loading branch information
cdietrich committed Feb 10, 2018
1 parent 7828a7e commit 6161407
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,27 +354,11 @@ protected JvmDeclaredType createType(IType jdtType, IJavaProject javaProject) {
+ "', but got '" + binding.toString() + "'.");
}
}



private static Boolean canTolerateMissingType = null;

/**
* @since 2.8
*/
protected void setMayTolerateMissingType(ITypeBinding typeBinding) {
// mayTolerateMissingType is only available since Juno. (introduced with https://github.com/eclipse/eclipse.jdt.core/commit/2d89f0516f5e5910bcd18015e8090ed0805dbb4e)
// check if it's there once.
if (canTolerateMissingType == null) {
canTolerateMissingType = Boolean.FALSE;
try {
LookupEnvironment.class.getDeclaredField("mayTolerateMissingType");
canTolerateMissingType = Boolean.TRUE;
} catch (NoSuchFieldException e) {}
}
// not supported. go out.
if (canTolerateMissingType == Boolean.FALSE)
return;
try {
Field field = typeBinding.getClass().getDeclaredField("binding");
field.setAccessible(true);
Expand All @@ -384,7 +368,7 @@ protected void setMayTolerateMissingType(ITypeBinding typeBinding) {
Field declaredField = binaryTypeBinding.getClass().getDeclaredField("environment");
declaredField.setAccessible(true);
LookupEnvironment env = (LookupEnvironment) declaredField.get(binaryTypeBinding);
env.getClass().getField("mayTolerateMissingType").set(env, true);
env.mayTolerateMissingType = true;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*******************************************************************************/
package org.eclipse.xtext.common.types.xtext.ui;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
Expand All @@ -24,7 +23,6 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
Expand Down Expand Up @@ -243,13 +241,9 @@ protected IJavaSearchScope createSearchScope(IJavaProject project, JvmType super
return new IntersectingJavaSearchScope(); // empty intersection
}
try {
// Method is available in JDT 3.6 or better
// more than twice as fast as the older alternative
Method method = SearchEngine.class.getMethod("createStrictHierarchyScope", IJavaProject.class, IType.class, Boolean.TYPE, Boolean.TYPE, WorkingCopyOwner.class);
method.setAccessible(true);
IJavaSearchScope result = (IJavaSearchScope) method.invoke(null, project, type, Boolean.TRUE, Boolean.TRUE, null);
IJavaSearchScope result = SearchEngine.createStrictHierarchyScope(project, type, Boolean.TRUE, Boolean.TRUE, null);
return result;
} catch (Exception e) {
} catch (JavaModelException e) {
final Collection<JvmType> superTypes = superTypeCollector.collect(superType);
for(JvmType collectedSuperType: superTypes) {
superTypeNames.add(collectedSuperType.getIdentifier());
Expand Down

0 comments on commit 6161407

Please sign in to comment.