Skip to content

Instantly share code, notes, and snippets.

@develar
Created January 21, 2015 19:20
Show Gist options
  • Save develar/ede9c34ce18def7096f6 to your computer and use it in GitHub Desktop.
Save develar/ede9c34ce18def7096f6 to your computer and use it in GitHub Desktop.
final class JavaToJavaScriptDebugAware extends JavaScriptDebugAware {
@Nullable
@Override
public XLineBreakpointType<?> getBreakpointTypeClass(@NotNull Project project) {
return XBreakpointType.EXTENSION_POINT_NAME.findExtension(JavaLineBreakpointType.class);
}
@Nullable
@Override
public MemberFilter createMemberFilter(@Nullable final NameMapper nameMapper, @NotNull PsiElement element, int end) {
if (nameMapper != null && element.getContainingFile().getLanguage() == JavaLanguage.INSTANCE) {
PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false);
if (method != null) {
for (PsiParameter parameter : method.getParameterList().getParameters()) {
nameMapper.map(parameter);
}
PsiCodeBlock body = method.getBody();
if (body != null) {
body.accept(new JavaRecursiveElementVisitor() {
@Override
public void visitLocalVariable(PsiLocalVariable variable) {
nameMapper.map(variable);
}
});
}
final Map<String, String> nameMappings = nameMapper.getNameMappings();
if (nameMappings != null) {
return new MemberFilter() {
@Override
public boolean isMemberVisible(@NotNull Variable variable, boolean filterFunctions) {
return true;
}
@NotNull
@Override
public Collection<Variable> getAdditionalVariables() {
return Collections.emptyList();
}
@NotNull
@Override
public String getName(@NotNull Variable variable) {
String name = variable.getName();
String sourceName = nameMappings.get(name);
return sourceName == null ? name : sourceName;
}
@Override
public boolean hasNameMappings() {
return true;
}
};
}
}
}
return null;
}
@Nullable
@Override
public PsiElement getNavigationElementForSourcemapInspector(@NotNull PsiFile file) {
if (file instanceof PsiJavaFile) {
PsiClass[] classes = ((PsiJavaFile)file).getClasses();
if (classes.length > 0) {
return classes[0].getNavigationElement();
}
}
return null;
}
@Nullable
@Override
protected LanguageFileType getFileType(@NotNull FileTypeRequestReason reason) {
return reason == FileTypeRequestReason.EVALUATION_INFO ? JavaFileType.INSTANCE : null;
}
@Nullable
@Override
public ExpressionInfo getEvaluationInfo(@NotNull PsiElement elementAtOffset, @NotNull Document document, @NotNull ExpressionInfoFactory expressionInfoFactory) {
if (elementAtOffset instanceof PsiIdentifier) {
return new ExpressionInfo(elementAtOffset.getTextRange());
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment