use of org.jetbrains.annotations.NonNls in project intellij-community by JetBrains.
the class GroovyGenerateEqualsHelper method createEquals.
private PsiMethod createEquals() throws IncorrectOperationException {
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject);
String[] nameSuggestions = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, PsiType.getJavaLangObject(myClass.getManager(), myClass.getResolveScope())).names;
final String objectBaseName = nameSuggestions.length > 0 ? nameSuggestions[0] : BASE_OBJECT_PARAMETER_NAME;
myParameterName = getUniqueLocalVarName(objectBaseName, myEqualsFields);
//todo isApplicable it
final PsiType classType = TypesUtil.createType(myClass.getQualifiedName(), myClass.getContext());
nameSuggestions = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, classType).names;
String instanceBaseName = nameSuggestions.length > 0 && nameSuggestions[0].length() < 10 ? nameSuggestions[0] : BASE_OBJECT_LOCAL_NAME;
myClassInstanceName = getUniqueLocalVarName(instanceBaseName, myEqualsFields);
@NonNls StringBuffer buffer = new StringBuffer();
buffer.append("boolean equals(").append(myParameterName).append(") {\n");
addEqualsPrologue(buffer);
if (myEqualsFields.length > 0) {
addClassInstance(buffer);
ArrayList<PsiField> equalsFields = new ArrayList<>();
ContainerUtil.addAll(equalsFields, myEqualsFields);
Collections.sort(equalsFields, EqualsFieldsComparator.INSTANCE);
for (PsiField field : equalsFields) {
if (!field.hasModifierProperty(PsiModifier.STATIC)) {
final PsiType type = field.getType();
if (type instanceof PsiArrayType) {
addArrayEquals(buffer, field);
} else if (type instanceof PsiPrimitiveType) {
if (PsiType.DOUBLE.equals(type) || PsiType.FLOAT.equals(type)) {
addDoubleFieldComparison(buffer, field);
} else {
addFieldComparison(buffer, field);
}
} else {
if (type instanceof PsiClassType) {
final PsiClass aClass = ((PsiClassType) type).resolve();
if (aClass != null && aClass.isEnum()) {
addFieldComparison(buffer, field);
continue;
}
}
addFieldComparison(buffer, field);
}
}
}
}
buffer.append("\nreturn true\n}");
GrMethod result = myFactory.createMethodFromText(buffer.toString());
final PsiParameter parameter = result.getParameterList().getParameters()[0];
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS);
try {
result = ((GrMethod) CodeStyleManager.getInstance(myProject).reformat(result));
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return result;
}
use of org.jetbrains.annotations.NonNls in project intellij-community by JetBrains.
the class ForToEachIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrForStatement parentStatement = (GrForStatement) element;
final GrForInClause clause = (GrForInClause) parentStatement.getClause();
final GrVariable var = clause.getDeclaredVariable();
final GrStatement body = parentStatement.getBody();
final String bodyText;
if (body instanceof GrBlockStatement) {
final String text = body.getText();
bodyText = text.substring(1, text.length() - 1);
} else {
bodyText = body.getText();
}
GrExpression collection = clause.getIteratedExpression();
assert collection != null;
@NonNls final String statement = "x.each{" + var.getText() + " -> " + bodyText + " }";
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(parentStatement.getProject());
final GrMethodCallExpression eachExpression = (GrMethodCallExpression) factory.createTopElementFromText(statement);
((GrReferenceExpression) eachExpression.getInvokedExpression()).getQualifierExpression().replaceWithExpression(collection, true);
parentStatement.replaceWithStatement(eachExpression);
}
use of org.jetbrains.annotations.NonNls in project intellij-community by JetBrains.
the class IdeaCommitHandler method trackDeletedFile.
private void trackDeletedFile(@NotNull ProgressEvent event) {
@NonNls final String filePath = "file://" + event.getFile().getAbsolutePath().replace(File.separatorChar, '/');
VirtualFile virtualFile = ApplicationManager.getApplication().runReadAction((Computable<VirtualFile>) () -> VirtualFileManager.getInstance().findFileByUrl(filePath));
if (virtualFile != null) {
myDeletedFiles.add(virtualFile);
}
}
use of org.jetbrains.annotations.NonNls in project intellij-community by JetBrains.
the class DomRootInvocationHandler method setEmptyXmlTag.
@Override
protected XmlTag setEmptyXmlTag() {
final XmlTag[] result = new XmlTag[] { null };
getManager().runChange(() -> {
try {
final String namespace = getXmlElementNamespace();
@NonNls final String nsDecl = StringUtil.isEmpty(namespace) ? "" : " xmlns=\"" + namespace + "\"";
final XmlFile xmlFile = getFile();
final XmlTag tag = XmlElementFactory.getInstance(xmlFile.getProject()).createTagFromText("<" + getXmlElementName() + nsDecl + "/>");
result[0] = ((XmlDocument) xmlFile.getDocument().replace(((XmlFile) tag.getContainingFile()).getDocument())).getRootTag();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
return result[0];
}
use of org.jetbrains.annotations.NonNls in project intellij-community by JetBrains.
the class XmlUtil method getDefaultNamespaces.
@Nullable
@NonNls
public static String[][] getDefaultNamespaces(final XmlDocument document) {
final XmlFile file = getContainingFile(document);
final XmlTag tag = document.getRootTag();
if (tag == null)
return null;
@NotNull final XmlFileNSInfoProvider[] nsProviders = Extensions.getExtensions(XmlFileNSInfoProvider.EP_NAME);
if (file != null) {
NextProvider: for (XmlFileNSInfoProvider nsProvider : nsProviders) {
final String[][] pairs = nsProvider.getDefaultNamespaces(file);
if (pairs != null && pairs.length > 0) {
for (final String[] nsMapping : pairs) {
if (nsMapping == null || nsMapping.length != 2 || nsMapping[0] == null || nsMapping[1] == null) {
LOG.debug("NSInfoProvider " + nsProvider + " gave wrong info about " + file.getVirtualFile());
continue NextProvider;
}
}
return pairs;
}
}
}
String namespace = getDtdUri(document);
if (namespace != null) {
boolean overrideNamespaceFromDocType = false;
if (file != null) {
for (XmlFileNSInfoProvider provider : nsProviders) {
try {
if (provider.overrideNamespaceFromDocType(file)) {
overrideNamespaceFromDocType = true;
break;
}
} catch (AbstractMethodError ignored) {
}
}
}
if (!overrideNamespaceFromDocType)
return new String[][] { new String[] { "", namespace } };
}
if ("taglib".equals(tag.getName())) {
return new String[][] { new String[] { "", TAGLIB_1_2_URI } };
}
if (file != null) {
final Language language = file.getLanguage();
if (language.isKindOf(HTMLLanguage.INSTANCE) || language == XHTMLLanguage.INSTANCE) {
return new String[][] { new String[] { "", XHTML_URI } };
}
}
return null;
}
Aggregations