use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.
the class ReplacementBuilder method process.
String process(MatchResult match, ReplacementInfoImpl replacementInfo, FileType type) {
if (parameterizations == null) {
return replacement;
}
final StringBuilder result = new StringBuilder(replacement);
final HashMap<String, MatchResult> matchMap = new HashMap<>();
fill(match, matchMap);
final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(type);
assert profile != null;
int offset = 0;
for (final ParameterInfo info : parameterizations) {
MatchResult r = matchMap.get(info.getName());
if (info.isReplacementVariable()) {
offset = Replacer.insertSubstitution(result, offset, info, generateReplacement(info, match));
} else if (r != null) {
offset = profile.handleSubstitution(info, r, result, offset, matchMap);
} else {
offset = profile.handleNoSubstitution(info, offset, result);
}
}
replacementInfo.variableMap = matchMap;
return result.toString();
}
use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.
the class ReplacementPreviewDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JComponent centerPanel = new JPanel(new BorderLayout());
PsiFile file = null;
final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(myFileType);
if (profile != null) {
file = profile.createCodeFragment(project, "", null);
}
if (file != null) {
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
replacement = UIUtil.createEditor(document, project, true, null);
DaemonCodeAnalyzer.getInstance(project).setHighlightingEnabled(file, false);
} else {
final EditorFactory factory = EditorFactory.getInstance();
final Document document = factory.createDocument("");
replacement = factory.createEditor(document, project, myFileType, false);
}
centerPanel.add(BorderLayout.NORTH, new JLabel(SSRBundle.message("replacement.code")));
centerPanel.add(BorderLayout.CENTER, replacement.getComponent());
centerPanel.setMaximumSize(new Dimension(640, 480));
return centerPanel;
}
use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.
the class GlobalCompilingVisitor method compile.
void compile(PsiElement[] elements, CompileContext context) {
myCodeBlockLevel = 0;
this.context = context;
final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(context.getOptions().getFileType());
assert profile != null;
profile.compile(elements, this);
if (context.getPattern().getStrategy() == null) {
System.out.println();
}
}
use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.
the class MatcherImplUtil method createSourceTreeFromText.
public static PsiElement[] createSourceTreeFromText(String text, PatternTreeContext context, FileType fileType, String extension, Project project, boolean physical) {
if (fileType instanceof LanguageFileType) {
Language language = ((LanguageFileType) fileType).getLanguage();
StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
if (profile != null) {
return profile.createPatternTree(text, context, fileType, null, null, extension, project, physical);
}
}
return PsiElement.EMPTY_ARRAY;
}
Aggregations