mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SrcToPsiMap works with ASTNodes instead of TreeElements.
This commit is contained in:
@@ -47,13 +47,13 @@ public class DebugUtil {
|
||||
private static void treeToBuffer(StringBuffer buffer, ASTNode root, int indent, boolean skipWhiteSpaces) {
|
||||
if (skipWhiteSpaces && root.getElementType() == ElementType.WHITE_SPACE) return;
|
||||
|
||||
for(int i = 0; i < indent; i++){
|
||||
for (int i = 0; i < indent; i++) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (root instanceof CompositeElement){
|
||||
if (root instanceof CompositeElement) {
|
||||
buffer.append(SourceTreeToPsiMap.treeElementToPsi(root).toString());
|
||||
}
|
||||
else{
|
||||
else {
|
||||
String text = root.getText();
|
||||
text = StringUtil.replace(text, "\n", "\\n");
|
||||
text = StringUtil.replace(text, "\r", "\\r");
|
||||
@@ -61,33 +61,35 @@ public class DebugUtil {
|
||||
buffer.append(root.toString() + "('" + text + "')");
|
||||
}
|
||||
buffer.append("\n");
|
||||
if (root instanceof CompositeElement){
|
||||
if (root instanceof CompositeElement) {
|
||||
ChameleonTransforming.transformChildren(root);
|
||||
ASTNode child = root.getFirstChildNode();
|
||||
|
||||
if (child == null){
|
||||
for(int i = 0; i < indent + 2; i++){
|
||||
if (child == null) {
|
||||
for (int i = 0; i < indent + 2; i++) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
buffer.append("<empty list>\n");
|
||||
}
|
||||
else while(child != null){
|
||||
treeToBuffer(buffer, child, indent + 2, skipWhiteSpaces);
|
||||
child = child.getTreeNext();
|
||||
else {
|
||||
while (child != null) {
|
||||
treeToBuffer(buffer, child, indent + 2, skipWhiteSpaces);
|
||||
child = child.getTreeNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void treeToBufferWithUserData(StringBuffer buffer, TreeElement root, int indent, boolean skipWhiteSpaces) {
|
||||
if (skipWhiteSpaces && root.getElementType() == ElementType.WHITE_SPACE) return;
|
||||
|
||||
for(int i = 0; i < indent; i++){
|
||||
for (int i = 0; i < indent; i++) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (root instanceof CompositeElement){
|
||||
if (root instanceof CompositeElement) {
|
||||
buffer.append(SourceTreeToPsiMap.treeElementToPsi(root).toString());
|
||||
}
|
||||
else{
|
||||
else {
|
||||
String text = root.getText();
|
||||
text = StringUtil.replace(text, "\n", "\\n");
|
||||
text = StringUtil.replace(text, "\r", "\\r");
|
||||
@@ -96,16 +98,16 @@ public class DebugUtil {
|
||||
}
|
||||
buffer.append(root.getUserDataString());
|
||||
buffer.append("\n");
|
||||
if (root instanceof CompositeElement || root instanceof ChameleonElement){
|
||||
if (root instanceof CompositeElement || root instanceof ChameleonElement) {
|
||||
PsiElement[] children = SourceTreeToPsiMap.treeElementToPsi(root).getChildren();
|
||||
|
||||
for(int i = 0; i < children.length; i++){
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
PsiElement child = children[i];
|
||||
treeToBufferWithUserData(buffer, SourceTreeToPsiMap.psiElementToTree(child), indent + 2, skipWhiteSpaces);
|
||||
treeToBufferWithUserData(buffer, (TreeElement)SourceTreeToPsiMap.psiElementToTree(child), indent + 2, skipWhiteSpaces);
|
||||
}
|
||||
|
||||
if (children.length == 0){
|
||||
for(int i = 0; i < indent + 2; i++){
|
||||
if (children.length == 0) {
|
||||
for (int i = 0; i < indent + 2; i++) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
buffer.append("<empty list>\n");
|
||||
@@ -116,13 +118,13 @@ public class DebugUtil {
|
||||
private static void treeToBufferWithUserData(StringBuffer buffer, PsiElement root, int indent, boolean skipWhiteSpaces) {
|
||||
if (skipWhiteSpaces && root instanceof PsiWhiteSpace) return;
|
||||
|
||||
for(int i = 0; i < indent; i++){
|
||||
for (int i = 0; i < indent; i++) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (root instanceof CompositeElement){
|
||||
if (root instanceof CompositeElement) {
|
||||
buffer.append(root);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
String text = root.getText();
|
||||
text = StringUtil.replace(text, "\n", "\\n");
|
||||
text = StringUtil.replace(text, "\r", "\\r");
|
||||
@@ -134,13 +136,13 @@ public class DebugUtil {
|
||||
|
||||
PsiElement[] children = root.getChildren();
|
||||
|
||||
for(int i = 0; i < children.length; i++){
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
PsiElement child = children[i];
|
||||
treeToBufferWithUserData(buffer, child, indent + 2, skipWhiteSpaces);
|
||||
}
|
||||
|
||||
if (children.length == 0){
|
||||
for(int i = 0; i < indent + 2; i++){
|
||||
if (children.length == 0) {
|
||||
for (int i = 0; i < indent + 2; i++) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
buffer.append("<empty list>\n");
|
||||
@@ -150,45 +152,45 @@ public class DebugUtil {
|
||||
|
||||
public static void checkTreeStructure(ASTNode anyElement) {
|
||||
ASTNode root = anyElement;
|
||||
while(root.getTreeParent() != null){
|
||||
while (root.getTreeParent() != null) {
|
||||
root = root.getTreeParent();
|
||||
}
|
||||
if (root instanceof CompositeElement) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
checkSubtree(root);
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
checkSubtree(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkSubtree(ASTNode root) {
|
||||
if (root.getFirstChildNode() == null){
|
||||
if (root.getLastChildNode() != null){
|
||||
if (root.getFirstChildNode() == null) {
|
||||
if (root.getLastChildNode() != null) {
|
||||
throw new IncorrectTreeStructureException(root, "firstChild == null, but lastChild != null");
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(ASTNode child = root.getFirstChildNode(); child != null; child = child.getTreeNext()){
|
||||
if (child instanceof CompositeElement){
|
||||
else {
|
||||
for (ASTNode child = root.getFirstChildNode(); child != null; child = child.getTreeNext()) {
|
||||
if (child instanceof CompositeElement) {
|
||||
checkSubtree(child);
|
||||
}
|
||||
if (child.getTreeParent() != root){
|
||||
if (child.getTreeParent() != root) {
|
||||
throw new IncorrectTreeStructureException(child, "child has wrong parent value");
|
||||
}
|
||||
if (child == root.getFirstChildNode()){
|
||||
if (child.getTreePrev() != null){
|
||||
if (child == root.getFirstChildNode()) {
|
||||
if (child.getTreePrev() != null) {
|
||||
throw new IncorrectTreeStructureException(root, "firstChild.prev != null");
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (child.getTreePrev() == null){
|
||||
else {
|
||||
if (child.getTreePrev() == null) {
|
||||
throw new IncorrectTreeStructureException(child, "not first child has prev == null");
|
||||
}
|
||||
if (child.getTreePrev().getTreeNext() != child){
|
||||
if (child.getTreePrev().getTreeNext() != child) {
|
||||
throw new IncorrectTreeStructureException(child, "element.prev.next != element");
|
||||
}
|
||||
}
|
||||
if (child.getTreeNext() == null){
|
||||
if (root.getLastChildNode() != child){
|
||||
if (child.getTreeNext() == null) {
|
||||
if (root.getLastChildNode() != child) {
|
||||
throw new IncorrectTreeStructureException(child, "not last child has next == null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,8 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
if (myManager.getEffectiveLanguageLevel().compareTo(LanguageLevel.JDK_1_5) < 0) {
|
||||
ARRAY_CLASS = createClassFromText(
|
||||
"public class __Array__{\n public final int length; \n public Object clone(){}\n}", null);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ARRAY_CLASS = createClassFromText(
|
||||
"public class __Array__<T>{\n public final int length; \n public T[] clone(){}\n}", null);
|
||||
}
|
||||
@@ -159,7 +160,7 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
PsiClass aClass = aFile.getClasses()[0];
|
||||
PsiField field = aClass.getFields()[0];
|
||||
SourceTreeToPsiMap.psiElementToTree(field).replaceChild(SourceTreeToPsiMap.psiElementToTree(field.getTypeElement()), typeCopy);
|
||||
ChangeUtil.decodeInformation(SourceTreeToPsiMap.psiElementToTree(field));
|
||||
ChangeUtil.decodeInformation((TreeElement)SourceTreeToPsiMap.psiElementToTree(field));
|
||||
return (PsiField)CodeStyleManager.getInstance(myManager.getProject()).reformat(field);
|
||||
}
|
||||
|
||||
@@ -204,7 +205,8 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
throw new IncorrectOperationException("Cannot create field with type \"<null_type>\".");
|
||||
}
|
||||
final FileElement treeHolder = new DummyHolder(myManager, null).getTreeElement();
|
||||
final CompositeElement treeElement = DeclarationParsing.parseParameterText(myManager, ("int " + name).toCharArray(), treeHolder.getCharTable());
|
||||
final CompositeElement treeElement =
|
||||
DeclarationParsing.parseParameterText(myManager, ("int " + name).toCharArray(), treeHolder.getCharTable());
|
||||
TreeUtil.addChildren(treeHolder, treeElement);
|
||||
|
||||
TreeElement typeElement = ChangeUtil.copyToElement(createTypeElement(type));
|
||||
@@ -213,7 +215,8 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
|
||||
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
|
||||
PsiParameter parameter = (PsiParameter)SourceTreeToPsiMap.treeElementToPsi(treeElement);
|
||||
parameter.getModifierList().setModifierProperty(PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_PARAMETERS);
|
||||
parameter.getModifierList()
|
||||
.setModifierProperty(PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_PARAMETERS);
|
||||
return (PsiParameter)codeStyleManager.reformat(parameter);
|
||||
}
|
||||
|
||||
@@ -246,7 +249,9 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
|
||||
public PsiType visitWildcardType(PsiWildcardType wildcardType) {
|
||||
final PsiType bound = wildcardType.getBound();
|
||||
if (bound == null) return wildcardType;
|
||||
if (bound == null) {
|
||||
return wildcardType;
|
||||
}
|
||||
else {
|
||||
return PsiWildcardType.changeBound(wildcardType, bound.accept(this));
|
||||
}
|
||||
@@ -344,12 +349,13 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
|
||||
public XmlTag getAntImplicitDeclarationTag() throws IncorrectOperationException {
|
||||
return createTagFromText(
|
||||
"<implicit-properties-ant-declaration-tag-for-intellij-idea xmlns=\"" + XmlUtil.ANT_URI + "\"/>");
|
||||
"<implicit-properties-ant-declaration-tag-for-intellij-idea xmlns=\"" + XmlUtil.ANT_URI + "\"/>");
|
||||
}
|
||||
|
||||
public PsiAnnotation createAnnotationFromText(String annotationText, PsiElement context) throws IncorrectOperationException {
|
||||
final FileElement holderElement = new DummyHolder(myManager, context).getTreeElement();
|
||||
CompositeElement annotationElement = DeclarationParsing.parseAnnotationFromText(myManager, annotationText, holderElement.getCharTable());
|
||||
CompositeElement annotationElement =
|
||||
DeclarationParsing.parseAnnotationFromText(myManager, annotationText, holderElement.getCharTable());
|
||||
if (annotationElement == null || annotationElement.getElementType() != ElementType.ANNOTATION) {
|
||||
throw new IncorrectOperationException("Incorrect annotation \"" + annotationText + "\".");
|
||||
}
|
||||
@@ -380,7 +386,7 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
sep = ",";
|
||||
}
|
||||
text += "){}";
|
||||
PsiMethod method = createMethodFromText(text,null);
|
||||
PsiMethod method = createMethodFromText(text, null);
|
||||
return method.getParameterList();
|
||||
}
|
||||
|
||||
@@ -398,7 +404,9 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
return method.getThrowsList();
|
||||
}
|
||||
|
||||
public PsiCatchSection createCatchSection(PsiClassType exceptionType, String exceptionName, PsiElement context) throws IncorrectOperationException {
|
||||
public PsiCatchSection createCatchSection(PsiClassType exceptionType,
|
||||
String exceptionName,
|
||||
PsiElement context) throws IncorrectOperationException {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("catch (");
|
||||
buffer.append(exceptionType.getCanonicalText());
|
||||
@@ -406,7 +414,7 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
String catchSectionText = buffer.toString();
|
||||
final FileElement holderElement = new DummyHolder(myManager, context).getTreeElement();
|
||||
TreeElement catchSection = StatementParsing.parseCatchSectionText(myManager, catchSectionText.toCharArray(),
|
||||
holderElement.getCharTable());
|
||||
holderElement.getCharTable());
|
||||
LOG.assertTrue(catchSection != null && catchSection.getElementType() == ElementType.CATCH_SECTION);
|
||||
TreeUtil.addChildren(holderElement, catchSection);
|
||||
PsiCatchSection psiCatchSection = (PsiCatchSection)SourceTreeToPsiMap.treeElementToPsi(catchSection);
|
||||
@@ -436,14 +444,14 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
psiCatchSection.getCatchBlock().replace(codeBlockFromText);
|
||||
}
|
||||
|
||||
public XmlText createDisplayText(String s) throws IncorrectOperationException{
|
||||
public XmlText createDisplayText(String s) throws IncorrectOperationException {
|
||||
final XmlTag tagFromText = createTagFromText("<a>" + XmlTagTextUtil.getCDATAQuote(s) + "</a>");
|
||||
final XmlText[] textElements = tagFromText.getValue().getTextElements();
|
||||
if(textElements.length == 0) return (XmlText)Factory.createCompositeElement(XmlElementType.XML_TEXT);
|
||||
if (textElements.length == 0) return (XmlText)Factory.createCompositeElement(XmlElementType.XML_TEXT);
|
||||
return textElements[0];
|
||||
}
|
||||
|
||||
public XmlTag createXHTMLTagFromText(String text) throws IncorrectOperationException{
|
||||
public XmlTag createXHTMLTagFromText(String text) throws IncorrectOperationException {
|
||||
return ((XmlFile)createFileFromText("dummy.xhtml", text)).getDocument().getRootTag();
|
||||
}
|
||||
|
||||
@@ -533,12 +541,13 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
PsiDeclarationStatement statement = (PsiDeclarationStatement)createStatementFromText(buffer.toString(), null);
|
||||
PsiVariable variable = (PsiVariable)statement.getDeclaredElements()[0];
|
||||
variable.getTypeElement().replace(createTypeElement(type));
|
||||
variable.getModifierList().setModifierProperty(PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_LOCALS);
|
||||
variable.getModifierList()
|
||||
.setModifierProperty(PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_LOCALS);
|
||||
if (initializer != null) {
|
||||
variable.getInitializer().replace(initializer);
|
||||
}
|
||||
|
||||
statement = (PsiDeclarationStatement)CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
|
||||
statement = (PsiDeclarationStatement)CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
|
||||
return statement;
|
||||
}
|
||||
|
||||
@@ -633,7 +642,7 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
return createMethodFromTextInner(text, context, myManager.getEffectiveLanguageLevel());
|
||||
}
|
||||
|
||||
private PsiMethod createMethodFromTextInner (String text, PsiElement context, LanguageLevel level) throws IncorrectOperationException {
|
||||
private PsiMethod createMethodFromTextInner(String text, PsiElement context, LanguageLevel level) throws IncorrectOperationException {
|
||||
final FileElement holderElement = new DummyHolder(myManager, context).getTreeElement();
|
||||
TreeElement decl = DeclarationParsing.parseDeclarationText(myManager, level, text.toCharArray(),
|
||||
DeclarationParsing.CLASS_CONTEXT, holderElement.getCharTable());
|
||||
@@ -707,7 +716,7 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
throw new IncorrectOperationException("Incorrect comment \"" + text + "\".");
|
||||
}
|
||||
PsiComment comment = (PsiComment)children[i];
|
||||
new DummyHolder(myManager, SourceTreeToPsiMap.psiElementToTree(comment), context);
|
||||
new DummyHolder(myManager, (TreeElement)SourceTreeToPsiMap.psiElementToTree(comment), context);
|
||||
return comment;
|
||||
}
|
||||
}
|
||||
@@ -766,23 +775,24 @@ public class PsiElementFactoryImpl implements PsiElementFactory {
|
||||
|
||||
|
||||
public PsiTypeCodeFragment createTypeCodeFragment(String text,
|
||||
PsiElement context,
|
||||
boolean isVoidValid,
|
||||
boolean isPhysical) {
|
||||
PsiElement context,
|
||||
boolean isVoidValid,
|
||||
boolean isPhysical) {
|
||||
return createTypeCodeFragment(text, context, true, isPhysical, false);
|
||||
}
|
||||
|
||||
public PsiTypeCodeFragment createTypeCodeFragment(String text,
|
||||
PsiElement context,
|
||||
boolean isVoidValid,
|
||||
boolean isPhysical, boolean allowEllipsis) {
|
||||
PsiElement context,
|
||||
boolean isVoidValid,
|
||||
boolean isPhysical,
|
||||
boolean allowEllipsis) {
|
||||
final PsiTypeCodeFragmentImpl result = new PsiTypeCodeFragmentImpl(myManager,
|
||||
isPhysical,
|
||||
allowEllipsis,
|
||||
"fragment.java",
|
||||
text.toCharArray(),
|
||||
0,
|
||||
text.length());
|
||||
isPhysical,
|
||||
allowEllipsis,
|
||||
"fragment.java",
|
||||
text.toCharArray(),
|
||||
0,
|
||||
text.length());
|
||||
result.setContext(context);
|
||||
if (isVoidValid) {
|
||||
result.putUserData(PsiUtil.VALID_VOID_TYPE_IN_CODE_FRAGMENT, Boolean.TRUE);
|
||||
|
||||
@@ -52,12 +52,12 @@ public class ClsAnnotationImpl extends ClsElementImpl implements PsiAnnotation {
|
||||
myMirror = element;
|
||||
|
||||
PsiAnnotation mirror = (PsiAnnotation)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
((ClsElementImpl)getParameterList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList()));
|
||||
((ClsElementImpl)getNameReferenceElement()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getNameReferenceElement()));
|
||||
((ClsElementImpl)getParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList()));
|
||||
((ClsElementImpl)getNameReferenceElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameReferenceElement()));
|
||||
}
|
||||
|
||||
public PsiElement[] getChildren() {
|
||||
return new PsiElement[] {myReferenceElement, myParameterList};
|
||||
return new PsiElement[]{myReferenceElement, myParameterList};
|
||||
}
|
||||
|
||||
public PsiElement getParent() {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ClsAnnotationParameterListImpl extends ClsElementImpl implements Ps
|
||||
PsiNameValuePair[] attrs = mirror.getAttributes();
|
||||
LOG.assertTrue(myAttributes.length == attrs.length);
|
||||
for (int i = 0; i < myAttributes.length; i++) {
|
||||
myAttributes[i].setMirror(SourceTreeToPsiMap.psiElementToTree(attrs[i]));
|
||||
myAttributes[i].setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(attrs[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ClsArrayInitializerMemberValueImpl extends ClsElementImpl implement
|
||||
LOG.assertTrue(myInitializers.length == initializers.length);
|
||||
for (int i = 0; i < myInitializers.length; i++) {
|
||||
ClsElementImpl value = (ClsElementImpl)myInitializers[i];
|
||||
value.setMirror(SourceTreeToPsiMap.psiElementToTree(initializers[i]));
|
||||
value.setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(initializers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,13 +85,13 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public void setRepositoryId(long repositoryId) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
super.setRepositoryId(repositoryId);
|
||||
if (repositoryId >= 0) {
|
||||
myClassFileData = null;
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
super.setRepositoryId(repositoryId);
|
||||
if (repositoryId >= 0) {
|
||||
myClassFileData = null;
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public PsiDirectory getContainingPackage() {
|
||||
@@ -163,18 +163,18 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiIdentifier getNameIdentifier() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myNameIdentifier == null) {
|
||||
String qName = getQualifiedName();
|
||||
String name = PsiNameHelper.getShortClassName(qName);
|
||||
if (name.length() == 0) {
|
||||
name = "_";
|
||||
}
|
||||
myNameIdentifier = new ClsIdentifierImpl(this, name);
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myNameIdentifier == null) {
|
||||
String qName = getQualifiedName();
|
||||
String name = PsiNameHelper.getShortClassName(qName);
|
||||
if (name.length() == 0) {
|
||||
name = "_";
|
||||
}
|
||||
;
|
||||
myNameIdentifier = new ClsIdentifierImpl(this, name);
|
||||
}
|
||||
return myNameIdentifier;
|
||||
;
|
||||
}
|
||||
return myNameIdentifier;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -186,40 +186,40 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiTypeParameterList getTypeParameterList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myTypeParameters == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myTypeParameters == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
int count = classView.getParametersListSize(repositoryId);
|
||||
if (count == 0) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
}
|
||||
else {
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
int count = classView.getParametersListSize(repositoryId);
|
||||
if (count == 0) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
StringBuffer compiledParams = new StringBuffer();
|
||||
compiledParams.append('<');
|
||||
for (int i = 0; i < count; i++) {
|
||||
compiledParams.append(classView.getParameterText(repositoryId, i));
|
||||
}
|
||||
else {
|
||||
StringBuffer compiledParams = new StringBuffer();
|
||||
compiledParams.append('<');
|
||||
for (int i = 0; i < count; i++) {
|
||||
compiledParams.append(classView.getParameterText(repositoryId, i));
|
||||
}
|
||||
compiledParams.append('>');
|
||||
try {
|
||||
final String signature = compiledParams.toString();
|
||||
myTypeParameters =
|
||||
GenericSignatureParsing.parseTypeParametersDeclaration(new StringCharacterIterator(signature, 0), this, signature);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
LOG.error(e); // dsl: this should not happen
|
||||
}
|
||||
compiledParams.append('>');
|
||||
try {
|
||||
final String signature = compiledParams.toString();
|
||||
myTypeParameters =
|
||||
GenericSignatureParsing.parseTypeParametersDeclaration(new StringCharacterIterator(signature, 0), this, signature);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
LOG.error(e); // dsl: this should not happen
|
||||
}
|
||||
}
|
||||
}
|
||||
return myTypeParameters;
|
||||
}
|
||||
return myTypeParameters;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasTypeParameters() {
|
||||
@@ -232,46 +232,46 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public String getQualifiedName() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myQualifiedName == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
BytePointer ptr = new BytePointer(classFileData.getData(), classFileData.getConstantPoolEnd() + 2);
|
||||
ptr.offset = classFileData.getOffsetInConstantPool(ClsUtil.readU2(ptr));
|
||||
int tag = ClsUtil.readU1(ptr);
|
||||
if (tag != ClsUtil.CONSTANT_Class) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
ptr.offset = classFileData.getOffsetInConstantPool(ClsUtil.readU2(ptr));
|
||||
String className = ClsUtil.readUtf8Info(ptr, '/', '.');
|
||||
myQualifiedName = ClsUtil.convertClassName(className, false);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myQualifiedName = "";
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myQualifiedName == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
BytePointer ptr = new BytePointer(classFileData.getData(), classFileData.getConstantPoolEnd() + 2);
|
||||
ptr.offset = classFileData.getOffsetInConstantPool(ClsUtil.readU2(ptr));
|
||||
int tag = ClsUtil.readU1(ptr);
|
||||
if (tag != ClsUtil.CONSTANT_Class) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
ptr.offset = classFileData.getOffsetInConstantPool(ClsUtil.readU2(ptr));
|
||||
String className = ClsUtil.readUtf8Info(ptr, '/', '.');
|
||||
myQualifiedName = ClsUtil.convertClassName(className, false);
|
||||
}
|
||||
else {
|
||||
myQualifiedName = getRepositoryManager().getClassView().getQualifiedName(repositoryId);
|
||||
if (myQualifiedName == null) {
|
||||
myQualifiedName = "";
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myQualifiedName = "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
myQualifiedName = getRepositoryManager().getClassView().getQualifiedName(repositoryId);
|
||||
if (myQualifiedName == null) {
|
||||
myQualifiedName = "";
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
return myQualifiedName;
|
||||
;
|
||||
}
|
||||
return myQualifiedName;
|
||||
}
|
||||
|
||||
public PsiModifierList getModifierList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
int flags = getAccessFlags();
|
||||
myModifierList = new ClsModifierListImpl(this, flags);
|
||||
}
|
||||
return myModifierList;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
int flags = getAccessFlags();
|
||||
myModifierList = new ClsModifierListImpl(this, flags);
|
||||
}
|
||||
return myModifierList;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasModifierProperty(String name) {
|
||||
@@ -279,40 +279,40 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiReferenceList getExtendsList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myExtendsList == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
if (parseViaGenericSignature()) return myExtendsList;
|
||||
if (!isInterface()) {
|
||||
myExtendsList = buildSuperList(PsiKeyword.EXTENDS);
|
||||
}
|
||||
else {
|
||||
myExtendsList = buildInterfaceList(PsiKeyword.EXTENDS);
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myExtendsList == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
if (parseViaGenericSignature()) return myExtendsList;
|
||||
if (!isInterface()) {
|
||||
myExtendsList = buildSuperList(PsiKeyword.EXTENDS);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myExtendsList = new ClsReferenceListImpl(this, PsiJavaCodeReferenceElement.EMPTY_ARRAY, PsiKeyword.EXTENDS);
|
||||
else {
|
||||
myExtendsList = buildInterfaceList(PsiKeyword.EXTENDS);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
String[] refTexts = classView.getExtendsList(repositoryId);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[refTexts.length];
|
||||
for (int i = 0; i < refTexts.length; i++) {
|
||||
refs[i] = new ClsJavaCodeReferenceElementImpl(null, refTexts[i]);
|
||||
}
|
||||
myExtendsList = new ClsReferenceListImpl(this, refs, PsiKeyword.EXTENDS);
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
ClsJavaCodeReferenceElementImpl ref = refs[i];
|
||||
ref.setParent(myExtendsList);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myExtendsList = new ClsReferenceListImpl(this, PsiJavaCodeReferenceElement.EMPTY_ARRAY, PsiKeyword.EXTENDS);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
String[] refTexts = classView.getExtendsList(repositoryId);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[refTexts.length];
|
||||
for (int i = 0; i < refTexts.length; i++) {
|
||||
refs[i] = new ClsJavaCodeReferenceElementImpl(null, refTexts[i]);
|
||||
}
|
||||
myExtendsList = new ClsReferenceListImpl(this, refs, PsiKeyword.EXTENDS);
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
ClsJavaCodeReferenceElementImpl ref = refs[i];
|
||||
ref.setParent(myExtendsList);
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
return myExtendsList;
|
||||
;
|
||||
}
|
||||
return myExtendsList;
|
||||
}
|
||||
|
||||
private boolean parseViaGenericSignature() {
|
||||
@@ -366,40 +366,40 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiReferenceList getImplementsList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myImplementsList == null) {
|
||||
if (!isInterface()) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
if (parseViaGenericSignature()) return myImplementsList;
|
||||
myImplementsList = buildInterfaceList(PsiKeyword.IMPLEMENTS);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myImplementsList = new ClsReferenceListImpl(this, PsiJavaCodeReferenceElement.EMPTY_ARRAY, PsiKeyword.IMPLEMENTS);
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myImplementsList == null) {
|
||||
if (!isInterface()) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
if (parseViaGenericSignature()) return myImplementsList;
|
||||
myImplementsList = buildInterfaceList(PsiKeyword.IMPLEMENTS);
|
||||
}
|
||||
else {
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
String[] refTexts = classView.getImplementsList(repositoryId);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[refTexts.length];
|
||||
for (int i = 0; i < refTexts.length; i++) {
|
||||
refs[i] = new ClsJavaCodeReferenceElementImpl(null, refTexts[i]);
|
||||
}
|
||||
myImplementsList = new ClsReferenceListImpl(this, refs, PsiKeyword.IMPLEMENTS);
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
ClsJavaCodeReferenceElementImpl ref = refs[i];
|
||||
ref.setParent(myImplementsList);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myImplementsList = new ClsReferenceListImpl(this, PsiJavaCodeReferenceElement.EMPTY_ARRAY, PsiKeyword.IMPLEMENTS);
|
||||
}
|
||||
}
|
||||
else {
|
||||
myImplementsList = new ClsReferenceListImpl(this, PsiJavaCodeReferenceElement.EMPTY_ARRAY, PsiKeyword.IMPLEMENTS);
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
String[] refTexts = classView.getImplementsList(repositoryId);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[refTexts.length];
|
||||
for (int i = 0; i < refTexts.length; i++) {
|
||||
refs[i] = new ClsJavaCodeReferenceElementImpl(null, refTexts[i]);
|
||||
}
|
||||
myImplementsList = new ClsReferenceListImpl(this, refs, PsiKeyword.IMPLEMENTS);
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
ClsJavaCodeReferenceElementImpl ref = refs[i];
|
||||
ref.setParent(myImplementsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
else {
|
||||
myImplementsList = new ClsReferenceListImpl(this, PsiJavaCodeReferenceElement.EMPTY_ARRAY, PsiKeyword.IMPLEMENTS);
|
||||
}
|
||||
}
|
||||
return myImplementsList;
|
||||
;
|
||||
}
|
||||
return myImplementsList;
|
||||
}
|
||||
|
||||
public PsiClassType[] getExtendsListTypes() {
|
||||
@@ -445,9 +445,9 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
ref = null;
|
||||
}
|
||||
PsiReferenceList list = new ClsReferenceListImpl(this,
|
||||
ref != null
|
||||
? new PsiJavaCodeReferenceElement[]{ref}
|
||||
: PsiJavaCodeReferenceElement.EMPTY_ARRAY,
|
||||
ref != null
|
||||
? new PsiJavaCodeReferenceElement[]{ref}
|
||||
: PsiJavaCodeReferenceElement.EMPTY_ARRAY,
|
||||
type);
|
||||
if (ref != null) {
|
||||
ref.setParent(list);
|
||||
@@ -483,53 +483,53 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiField[] getFields() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myFields == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
BytePointer ptr = new BytePointer(classFileData.getData(), classFileData.getConstantPoolEnd() + 6);
|
||||
int count = ClsUtil.readU2(ptr);
|
||||
ptr.offset += count * 2; // skip interfaces
|
||||
count = ClsUtil.readU2(ptr);
|
||||
ArrayList<PsiField> array = new ArrayList<PsiField>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
PsiField field;
|
||||
if (isEnumField(ptr.offset)) {
|
||||
field = new ClsEnumConstantImpl(this, ptr.offset);
|
||||
}
|
||||
else {
|
||||
field = new ClsFieldImpl(this, ptr.offset);
|
||||
}
|
||||
String name = field.getName();
|
||||
//if (name.indexOf('$') < 0 && name.indexOf('<') < 0){ // skip synthetic fields
|
||||
if (myManager.getNameHelper().isIdentifier(name) && name.indexOf('$') < 0) { // skip synthetic&obfuscated fields
|
||||
array.add(field);
|
||||
}
|
||||
ptr.offset += 6;
|
||||
ClsUtil.skipAttributes(ptr);
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myFields == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
BytePointer ptr = new BytePointer(classFileData.getData(), classFileData.getConstantPoolEnd() + 6);
|
||||
int count = ClsUtil.readU2(ptr);
|
||||
ptr.offset += count * 2; // skip interfaces
|
||||
count = ClsUtil.readU2(ptr);
|
||||
ArrayList<PsiField> array = new ArrayList<PsiField>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
PsiField field;
|
||||
if (isEnumField(ptr.offset)) {
|
||||
field = new ClsEnumConstantImpl(this, ptr.offset);
|
||||
}
|
||||
myFields = array.toArray(new PsiField[array.size()]);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myFields = PsiField.EMPTY_ARRAY;
|
||||
else {
|
||||
field = new ClsFieldImpl(this, ptr.offset);
|
||||
}
|
||||
String name = field.getName();
|
||||
//if (name.indexOf('$') < 0 && name.indexOf('<') < 0){ // skip synthetic fields
|
||||
if (myManager.getNameHelper().isIdentifier(name) && name.indexOf('$') < 0) { // skip synthetic&obfuscated fields
|
||||
array.add(field);
|
||||
}
|
||||
ptr.offset += 6;
|
||||
ClsUtil.skipAttributes(ptr);
|
||||
}
|
||||
myFields = array.toArray(new PsiField[array.size()]);
|
||||
}
|
||||
else {
|
||||
long[] fieldIds = getRepositoryManager().getClassView().getFields(repositoryId);
|
||||
PsiField[] fields = new PsiField[fieldIds.length];
|
||||
RepositoryElementsManager repositoryElementsManager = getRepositoryElementsManager();
|
||||
for (int i = 0; i < fieldIds.length; i++) {
|
||||
long id = fieldIds[i];
|
||||
fields[i] = (PsiField)repositoryElementsManager.findOrCreatePsiElementById(id);
|
||||
}
|
||||
myFields = fields;
|
||||
catch (ClsFormatException e) {
|
||||
myFields = PsiField.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
;
|
||||
else {
|
||||
long[] fieldIds = getRepositoryManager().getClassView().getFields(repositoryId);
|
||||
PsiField[] fields = new PsiField[fieldIds.length];
|
||||
RepositoryElementsManager repositoryElementsManager = getRepositoryElementsManager();
|
||||
for (int i = 0; i < fieldIds.length; i++) {
|
||||
long id = fieldIds[i];
|
||||
fields[i] = (PsiField)repositoryElementsManager.findOrCreatePsiElementById(id);
|
||||
}
|
||||
myFields = fields;
|
||||
}
|
||||
}
|
||||
return myFields;
|
||||
;
|
||||
}
|
||||
return myFields;
|
||||
}
|
||||
|
||||
private boolean isEnumField(int ptrOffset) {
|
||||
@@ -544,109 +544,110 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
int b2 = data[offset] & 0xFF;
|
||||
flags = (b1 << 8) + b2;
|
||||
}
|
||||
catch (ClsFormatException e) {}
|
||||
catch (ClsFormatException e) {
|
||||
}
|
||||
|
||||
return (flags & ClsUtil.ACC_ENUM) != 0;
|
||||
}
|
||||
|
||||
public PsiMethod[] getMethods() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myMethods == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myMethods == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
BytePointer ptr = new BytePointer(classFileData.getData(), classFileData.getConstantPoolEnd() + 6);
|
||||
int count = ClsUtil.readU2(ptr);
|
||||
ptr.offset += count * 2; // skip interfaces
|
||||
count = ClsUtil.readU2(ptr);
|
||||
for (int i = 0; i < count; i++) { // skip fields
|
||||
ptr.offset += 6;
|
||||
ClsUtil.skipAttributes(ptr);
|
||||
}
|
||||
count = ClsUtil.readU2(ptr);
|
||||
ArrayList<PsiMethod> array = new ArrayList<PsiMethod>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
ClsMethodImpl method = new ClsMethodImpl(this, ptr.offset);
|
||||
String name = method.getName();
|
||||
//if (name.indexOf('$') < 0 && name.indexOf('<') < 0){ // skip synthetic methods
|
||||
if (!method.isBridge()) { //skip bridge methods
|
||||
if (myManager.getNameHelper().isIdentifier(name) && name.indexOf('$') < 0) { // skip synthetic&obfuscated methods
|
||||
array.add(method);
|
||||
}
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
BytePointer ptr = new BytePointer(classFileData.getData(), classFileData.getConstantPoolEnd() + 6);
|
||||
int count = ClsUtil.readU2(ptr);
|
||||
ptr.offset += count * 2; // skip interfaces
|
||||
count = ClsUtil.readU2(ptr);
|
||||
for (int i = 0; i < count; i++) { // skip fields
|
||||
ptr.offset += 6;
|
||||
ClsUtil.skipAttributes(ptr);
|
||||
}
|
||||
count = ClsUtil.readU2(ptr);
|
||||
ArrayList<PsiMethod> array = new ArrayList<PsiMethod>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
ClsMethodImpl method = new ClsMethodImpl(this, ptr.offset);
|
||||
String name = method.getName();
|
||||
//if (name.indexOf('$') < 0 && name.indexOf('<') < 0){ // skip synthetic methods
|
||||
if (!method.isBridge()) { //skip bridge methods
|
||||
if (myManager.getNameHelper().isIdentifier(name) && name.indexOf('$') < 0) { // skip synthetic&obfuscated methods
|
||||
array.add(method);
|
||||
}
|
||||
ptr.offset += 6;
|
||||
ClsUtil.skipAttributes(ptr);
|
||||
}
|
||||
myMethods = array.toArray(new PsiMethod[array.size()]);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myMethods = PsiMethod.EMPTY_ARRAY;
|
||||
ptr.offset += 6;
|
||||
ClsUtil.skipAttributes(ptr);
|
||||
}
|
||||
myMethods = array.toArray(new PsiMethod[array.size()]);
|
||||
}
|
||||
else {
|
||||
long[] methodIds = getRepositoryManager().getClassView().getMethods(repositoryId);
|
||||
PsiMethod[] methods = new PsiMethod[methodIds.length];
|
||||
RepositoryElementsManager repositoryElementsManager = getRepositoryElementsManager();
|
||||
for (int i = 0; i < methodIds.length; i++) {
|
||||
long id = methodIds[i];
|
||||
methods[i] = (PsiMethod)repositoryElementsManager.findOrCreatePsiElementById(id);
|
||||
}
|
||||
myMethods = methods;
|
||||
catch (ClsFormatException e) {
|
||||
myMethods = PsiMethod.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
;
|
||||
else {
|
||||
long[] methodIds = getRepositoryManager().getClassView().getMethods(repositoryId);
|
||||
PsiMethod[] methods = new PsiMethod[methodIds.length];
|
||||
RepositoryElementsManager repositoryElementsManager = getRepositoryElementsManager();
|
||||
for (int i = 0; i < methodIds.length; i++) {
|
||||
long id = methodIds[i];
|
||||
methods[i] = (PsiMethod)repositoryElementsManager.findOrCreatePsiElementById(id);
|
||||
}
|
||||
myMethods = methods;
|
||||
}
|
||||
}
|
||||
return myMethods;
|
||||
;
|
||||
}
|
||||
return myMethods;
|
||||
}
|
||||
|
||||
public PsiMethod[] getConstructors() {
|
||||
if (myConstructors == null){
|
||||
if (myConstructors == null) {
|
||||
myConstructors = PsiImplUtil.getConstructors(this);
|
||||
}
|
||||
return myConstructors;
|
||||
}
|
||||
|
||||
public PsiClass[] getInnerClasses() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myInnerClasses == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
VirtualFile vFile = myClassFileData.vFile;
|
||||
VirtualFile parentFile = vFile.getParent();
|
||||
if (parentFile == null) return null;
|
||||
String name = vFile.getNameWithoutExtension();
|
||||
String prefix = name + "$";
|
||||
ArrayList<PsiClass> array = new ArrayList<PsiClass>();
|
||||
VirtualFile[] children = parentFile.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
VirtualFile child = children[i];
|
||||
String childName = child.getNameWithoutExtension();
|
||||
if (childName.startsWith(prefix)) {
|
||||
String innerName = childName.substring(prefix.length());
|
||||
if (innerName.indexOf('$') >= 0) continue;
|
||||
if (!myManager.getNameHelper().isIdentifier(innerName)) continue;
|
||||
PsiClass aClass = new ClsClassImpl(myManager, this, child);
|
||||
array.add(aClass);
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myInnerClasses == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
VirtualFile vFile = myClassFileData.vFile;
|
||||
VirtualFile parentFile = vFile.getParent();
|
||||
if (parentFile == null) return null;
|
||||
String name = vFile.getNameWithoutExtension();
|
||||
String prefix = name + "$";
|
||||
ArrayList<PsiClass> array = new ArrayList<PsiClass>();
|
||||
VirtualFile[] children = parentFile.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
VirtualFile child = children[i];
|
||||
String childName = child.getNameWithoutExtension();
|
||||
if (childName.startsWith(prefix)) {
|
||||
String innerName = childName.substring(prefix.length());
|
||||
if (innerName.indexOf('$') >= 0) continue;
|
||||
if (!myManager.getNameHelper().isIdentifier(innerName)) continue;
|
||||
PsiClass aClass = new ClsClassImpl(myManager, this, child);
|
||||
array.add(aClass);
|
||||
}
|
||||
myInnerClasses = array.toArray(new PsiClass[array.size()]);
|
||||
}
|
||||
else {
|
||||
long[] classIds = getRepositoryManager().getClassView().getInnerClasses(repositoryId);
|
||||
PsiClass[] classes = new PsiClass[classIds.length];
|
||||
RepositoryElementsManager repositoryElementsManager = getRepositoryElementsManager();
|
||||
for (int i = 0; i < classIds.length; i++) {
|
||||
long id = classIds[i];
|
||||
classes[i] = (PsiClass)repositoryElementsManager.findOrCreatePsiElementById(id);
|
||||
}
|
||||
myInnerClasses = classes;
|
||||
}
|
||||
myInnerClasses = array.toArray(new PsiClass[array.size()]);
|
||||
}
|
||||
else {
|
||||
long[] classIds = getRepositoryManager().getClassView().getInnerClasses(repositoryId);
|
||||
PsiClass[] classes = new PsiClass[classIds.length];
|
||||
RepositoryElementsManager repositoryElementsManager = getRepositoryElementsManager();
|
||||
for (int i = 0; i < classIds.length; i++) {
|
||||
long id = classIds[i];
|
||||
classes[i] = (PsiClass)repositoryElementsManager.findOrCreatePsiElementById(id);
|
||||
}
|
||||
myInnerClasses = classes;
|
||||
}
|
||||
;
|
||||
}
|
||||
return myInnerClasses;
|
||||
;
|
||||
}
|
||||
return myInnerClasses;
|
||||
}
|
||||
|
||||
public PsiClassInitializer[] getInitializers() {
|
||||
@@ -671,9 +672,9 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiField findFieldByName(String name, boolean checkBases) {
|
||||
if(!checkBases){
|
||||
if(myCachedFieldsMap == null){
|
||||
myCachedFieldsMap = new HashMap<String,PsiField>();
|
||||
if (!checkBases) {
|
||||
if (myCachedFieldsMap == null) {
|
||||
myCachedFieldsMap = new HashMap<String, PsiField>();
|
||||
final PsiField[] fields = getFields();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
final PsiField field = fields[i];
|
||||
@@ -694,15 +695,15 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiMethod[] findMethodsByName(String name, boolean checkBases) {
|
||||
if(!checkBases){
|
||||
if(myCachedMethodsMap == null){
|
||||
myCachedMethodsMap = new HashMap<String,PsiMethod[]>();
|
||||
Map<String, List<PsiMethod>> cachedMethodsMap = new HashMap<String,List<PsiMethod>>();
|
||||
if (!checkBases) {
|
||||
if (myCachedMethodsMap == null) {
|
||||
myCachedMethodsMap = new HashMap<String, PsiMethod[]>();
|
||||
Map<String, List<PsiMethod>> cachedMethodsMap = new HashMap<String, List<PsiMethod>>();
|
||||
final PsiMethod[] methods = getMethods();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
final PsiMethod method = methods[i];
|
||||
List<PsiMethod> list = cachedMethodsMap.get(method.getName());
|
||||
if(list == null){
|
||||
if (list == null) {
|
||||
list = new ArrayList<PsiMethod>(1);
|
||||
cachedMethodsMap.put(method.getName(), list);
|
||||
}
|
||||
@@ -730,9 +731,9 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiClass findInnerClassByName(String name, boolean checkBases) {
|
||||
if(!checkBases){
|
||||
if(myCachedInnersMap == null){
|
||||
myCachedInnersMap = new HashMap<String,PsiClass>();
|
||||
if (!checkBases) {
|
||||
if (myCachedInnersMap == null) {
|
||||
myCachedInnersMap = new HashMap<String, PsiClass>();
|
||||
final PsiClass[] classes = getInnerClasses();
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
final PsiClass psiClass = classes[i];
|
||||
@@ -745,57 +746,57 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myIsDeprecated == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
boolean isDeprecated = readClassAttribute("Deprecated") != null;
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myIsDeprecated = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean isDeprecated = getRepositoryManager().getClassView().isDeprecated(repositoryId);
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
return myIsDeprecated.booleanValue();
|
||||
}
|
||||
|
||||
public String getSourceFileName() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myIsDeprecated == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
String sourceFileName = getClassFileData().readUtf8Attribute(readClassAttribute("SourceFile"));
|
||||
if (sourceFileName == null) {
|
||||
sourceFileName = obtainSourceFileNameFromClassFileName();
|
||||
return sourceFileName;
|
||||
}
|
||||
int slashIndex = sourceFileName.lastIndexOf('/'); // We need short name while some compilers do generate fulls
|
||||
if (slashIndex >= 0) {
|
||||
sourceFileName = sourceFileName.substring(slashIndex + 1, sourceFileName.length());
|
||||
}
|
||||
return sourceFileName;
|
||||
boolean isDeprecated = readClassAttribute("Deprecated") != null;
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
return null;
|
||||
myIsDeprecated = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ClsFileImpl file = (ClsFileImpl)getContainingFile();
|
||||
String sourceFileName = getRepositoryManager().getFileView().getSourceFileName(file.getRepositoryId());
|
||||
if (sourceFileName == null || sourceFileName.length() == 0) {
|
||||
boolean isDeprecated = getRepositoryManager().getClassView().isDeprecated(repositoryId);
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
return myIsDeprecated.booleanValue();
|
||||
}
|
||||
|
||||
public String getSourceFileName() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
String sourceFileName = getClassFileData().readUtf8Attribute(readClassAttribute("SourceFile"));
|
||||
if (sourceFileName == null) {
|
||||
sourceFileName = obtainSourceFileNameFromClassFileName();
|
||||
return sourceFileName;
|
||||
}
|
||||
int slashIndex = sourceFileName.lastIndexOf('/'); // We need short name while some compilers do generate fulls
|
||||
if (slashIndex >= 0) {
|
||||
sourceFileName = sourceFileName.substring(slashIndex + 1, sourceFileName.length());
|
||||
}
|
||||
return sourceFileName;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ClsFileImpl file = (ClsFileImpl)getContainingFile();
|
||||
String sourceFileName = getRepositoryManager().getFileView().getSourceFileName(file.getRepositoryId());
|
||||
if (sourceFileName == null || sourceFileName.length() == 0) {
|
||||
sourceFileName = obtainSourceFileNameFromClassFileName();
|
||||
}
|
||||
return sourceFileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String obtainSourceFileNameFromClassFileName() {
|
||||
@@ -835,15 +836,15 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
public PsiDocComment getDocComment() {
|
||||
if (!isDeprecated()) return null;
|
||||
if (!isDeprecated()) return null;
|
||||
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myDocComment == null) {
|
||||
myDocComment = new ClsDocCommentImpl(this);
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myDocComment == null) {
|
||||
myDocComment = new ClsDocCommentImpl(this);
|
||||
}
|
||||
return myDocComment;
|
||||
;
|
||||
}
|
||||
return myDocComment;
|
||||
}
|
||||
|
||||
public PsiJavaToken getLBrace() {
|
||||
@@ -881,63 +882,63 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
}
|
||||
|
||||
private int getAccessFlags() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
int offset = classFileData.getConstantPoolEnd();
|
||||
byte[] data = classFileData.getData();
|
||||
if (offset + 2 > data.length) {
|
||||
throw new ClsFormatException();
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = getClassFileData();
|
||||
int offset = classFileData.getConstantPoolEnd();
|
||||
byte[] data = classFileData.getData();
|
||||
if (offset + 2 > data.length) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset/*++*/] & 0xFF;
|
||||
int flags = ((b1 << 8) + b2) & ClsUtil.ACC_CLASS_MASK;
|
||||
|
||||
PsiElement parent = getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)parent;
|
||||
if (aClass.isInterface()) {
|
||||
flags |= ClsUtil.ACC_STATIC;
|
||||
}
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset/*++*/] & 0xFF;
|
||||
int flags = ((b1 << 8) + b2) & ClsUtil.ACC_CLASS_MASK;
|
||||
else {
|
||||
flags &= ~ClsUtil.ACC_STATIC;
|
||||
|
||||
PsiElement parent = getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)parent;
|
||||
if (aClass.isInterface()) {
|
||||
flags |= ClsUtil.ACC_STATIC;
|
||||
}
|
||||
else {
|
||||
flags &= ~ClsUtil.ACC_STATIC;
|
||||
|
||||
BytePointer ptr = readClassAttribute("InnerClasses");
|
||||
if (ptr != null) {
|
||||
//Skip attribute_length
|
||||
ptr.offset += 4;
|
||||
int numClasses = ClsUtil.readU2(ptr);
|
||||
int startOffset = ptr.offset + 4;
|
||||
for (int i = 0; i < numClasses; i++) {
|
||||
BytePointer ptr1 = new BytePointer(classFileData.getData(), startOffset + i * 8);
|
||||
int innerNameIdx = ClsUtil.readU2(ptr1);
|
||||
if (innerNameIdx == 0) {
|
||||
continue;
|
||||
}
|
||||
int innerNameOffset = classFileData.getOffsetInConstantPool(innerNameIdx);
|
||||
String innerName = ClsUtil.convertClassName(ClsUtil.readUtf8Info(classFileData.getData(), innerNameOffset), true);
|
||||
if (getName().equals(innerName)) {
|
||||
int accessFlags = ClsUtil.readU2(ptr1);
|
||||
flags = accessFlags;
|
||||
break;
|
||||
}
|
||||
BytePointer ptr = readClassAttribute("InnerClasses");
|
||||
if (ptr != null) {
|
||||
//Skip attribute_length
|
||||
ptr.offset += 4;
|
||||
int numClasses = ClsUtil.readU2(ptr);
|
||||
int startOffset = ptr.offset + 4;
|
||||
for (int i = 0; i < numClasses; i++) {
|
||||
BytePointer ptr1 = new BytePointer(classFileData.getData(), startOffset + i * 8);
|
||||
int innerNameIdx = ClsUtil.readU2(ptr1);
|
||||
if (innerNameIdx == 0) {
|
||||
continue;
|
||||
}
|
||||
int innerNameOffset = classFileData.getOffsetInConstantPool(innerNameIdx);
|
||||
String innerName = ClsUtil.convertClassName(ClsUtil.readUtf8Info(classFileData.getData(), innerNameOffset), true);
|
||||
if (getName().equals(innerName)) {
|
||||
int accessFlags = ClsUtil.readU2(ptr1);
|
||||
flags = accessFlags;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
else {
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
return classView.getModifiers(repositoryId);
|
||||
catch (ClsFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ClassView classView = getRepositoryManager().getClassView();
|
||||
return classView.getModifiers(repositoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getMirrorText() {
|
||||
@@ -967,7 +968,8 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
if (field instanceof ClsEnumConstantImpl) {
|
||||
if (i < fields.length - 1 && fields[i + 1] instanceof ClsEnumConstantImpl) {
|
||||
buffer.append(", ");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
buffer.append(";");
|
||||
}
|
||||
}
|
||||
@@ -991,21 +993,21 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
PsiClass mirror = (PsiClass)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
|
||||
if (getDocComment() != null) {
|
||||
((ClsElementImpl)getDocComment()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
((ClsElementImpl)getDocComment()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
}
|
||||
((ClsElementImpl)getModifierList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
if (!isAnnotationType() &&!isEnum()) {
|
||||
((ClsElementImpl)getExtendsList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList()));
|
||||
((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
if (!isAnnotationType() && !isEnum()) {
|
||||
((ClsElementImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList()));
|
||||
}
|
||||
((ClsElementImpl)getImplementsList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getImplementsList()));
|
||||
((ClsElementImpl)getTypeParameterList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList()));
|
||||
((ClsElementImpl)getImplementsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getImplementsList()));
|
||||
((ClsElementImpl)getTypeParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList()));
|
||||
|
||||
PsiField[] fields = getFields();
|
||||
PsiField[] mirrorFields = mirror.getFields();
|
||||
if (LOG.assertTrue(fields.length == mirrorFields.length)) {
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
((ClsElementImpl)fields[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(mirrorFields[i]));
|
||||
((ClsElementImpl)fields[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorFields[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1013,7 +1015,7 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
PsiMethod[] mirrorMethods = mirror.getMethods();
|
||||
if (LOG.assertTrue(methods.length == mirrorMethods.length)) {
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
((ClsElementImpl)methods[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(mirrorMethods[i]));
|
||||
((ClsElementImpl)methods[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorMethods[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1021,7 +1023,7 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
PsiClass[] mirrorClasses = mirror.getInnerClasses();
|
||||
if (LOG.assertTrue(classes.length == mirrorClasses.length)) {
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
((ClsElementImpl)classes[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(mirrorClasses[i]));
|
||||
((ClsElementImpl)classes[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorClasses[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1073,7 +1075,7 @@ public class ClsClassImpl extends ClsRepositoryPsiElement implements PsiClass, C
|
||||
if (psiSource == null) continue;
|
||||
if (!(psiSource instanceof PsiJavaFile)) {
|
||||
LOG.error("Not PsiJavaFile:" + psiSource);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
PsiJavaFile psiJavaFile = (PsiJavaFile)psiSource;
|
||||
PsiClass[] classes = psiJavaFile.getClasses();
|
||||
|
||||
@@ -14,7 +14,7 @@ public class ClsClassObjectAccessExpressionImpl extends ClsElementImpl implement
|
||||
private ClsTypeElementImpl myTypeElement;
|
||||
private ClsElementImpl myParent;
|
||||
|
||||
public ClsClassObjectAccessExpressionImpl (String canonicalClassText, ClsElementImpl parent) {
|
||||
public ClsClassObjectAccessExpressionImpl(String canonicalClassText, ClsElementImpl parent) {
|
||||
myParent = parent;
|
||||
myTypeElement = new ClsTypeElementImpl(this, canonicalClassText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
@@ -29,11 +29,11 @@ public class ClsClassObjectAccessExpressionImpl extends ClsElementImpl implement
|
||||
myMirror = element;
|
||||
|
||||
PsiClassObjectAccessExpression mirror = (PsiClassObjectAccessExpression)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
((ClsElementImpl)getOperand()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getOperand()));
|
||||
((ClsElementImpl)getOperand()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getOperand()));
|
||||
}
|
||||
|
||||
public PsiElement[] getChildren() {
|
||||
return new PsiElement[] {myTypeElement};
|
||||
return new PsiElement[]{myTypeElement};
|
||||
}
|
||||
|
||||
public PsiElement getParent() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
*/
|
||||
public class ClsEnumConstantImpl extends ClsFieldImpl implements PsiEnumConstant {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsEnumConstantImpl");
|
||||
|
||||
public ClsEnumConstantImpl(ClsClassImpl parent, int startOffset) {
|
||||
super(parent, startOffset);
|
||||
}
|
||||
@@ -38,11 +39,11 @@ public class ClsEnumConstantImpl extends ClsFieldImpl implements PsiEnumConstant
|
||||
myMirror = element;
|
||||
|
||||
PsiField mirror = (PsiField)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
if (getDocComment() != null){
|
||||
((ClsElementImpl)getDocComment()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
if (getDocComment() != null) {
|
||||
((ClsElementImpl)getDocComment()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
}
|
||||
((ClsElementImpl)getModifierList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
}
|
||||
|
||||
public PsiExpressionList getArgumentList() {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
|
||||
public void setRepositoryId(long repositoryId) {
|
||||
super.setRepositoryId(repositoryId);
|
||||
if (repositoryId >= 0){
|
||||
if (repositoryId >= 0) {
|
||||
myStartOffset = -1;
|
||||
}
|
||||
}
|
||||
@@ -73,16 +73,16 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
PsiElement[] children = new PsiElement[count];
|
||||
|
||||
int offset = 0;
|
||||
if (docComment != null){
|
||||
if (docComment != null) {
|
||||
children[offset++] = docComment;
|
||||
}
|
||||
if (modifierList != null){
|
||||
if (modifierList != null) {
|
||||
children[offset++] = modifierList;
|
||||
}
|
||||
if (type != null){
|
||||
if (type != null) {
|
||||
children[offset++] = type;
|
||||
}
|
||||
if (name != null){
|
||||
if (name != null) {
|
||||
children[offset++] = name;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
|
||||
public PsiElement getParent() {
|
||||
final long parentId = getParentId();
|
||||
if(parentId < 0) return myParent;
|
||||
if (parentId < 0) return myParent;
|
||||
return getRepositoryElementsManager().findOrCreatePsiElementById(parentId);
|
||||
}
|
||||
|
||||
@@ -100,39 +100,37 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
}
|
||||
|
||||
public PsiIdentifier getNameIdentifier() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myNameIdentifier == null) {
|
||||
myNameIdentifier = new ClsIdentifierImpl(this, getName());
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myNameIdentifier == null) {
|
||||
myNameIdentifier = new ClsIdentifierImpl(this, getName());
|
||||
}
|
||||
return myNameIdentifier;
|
||||
}
|
||||
return myNameIdentifier;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (myName == null) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 2;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
myName = ClsUtil.readUtf8Info(data, offset);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myName = "";
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 2;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
myName = ClsUtil.readUtf8Info(data, offset);
|
||||
}
|
||||
else {
|
||||
myName = getRepositoryManager().getFieldView().getName(repositoryId);
|
||||
catch (ClsFormatException e) {
|
||||
myName = "";
|
||||
}
|
||||
;
|
||||
}
|
||||
else {
|
||||
myName = getRepositoryManager().getFieldView().getName(repositoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return myName;
|
||||
}
|
||||
@@ -148,33 +146,32 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
|
||||
public PsiTypeElement getTypeElement() {
|
||||
if (myType == null) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 4;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
offset += 3; // skip tag and length
|
||||
String typeText = ClsUtil.getTypeText(data, offset);
|
||||
myType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myType = null;
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 4;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
offset += 3; // skip tag and length
|
||||
String typeText = ClsUtil.getTypeText(data, offset);
|
||||
myType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myType = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
String typeText = getRepositoryManager().getFieldView().getTypeText(repositoryId);
|
||||
myType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
;
|
||||
}
|
||||
else {
|
||||
String typeText = getRepositoryManager().getFieldView().getTypeText(repositoryId);
|
||||
myType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return myType;
|
||||
}
|
||||
@@ -183,7 +180,8 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
try {
|
||||
ClassFileData data = myParent.getClassFileData();
|
||||
return data.readUtf8Attribute(data.findAttribute(myStartOffset + 6, "Signature"));
|
||||
} catch (ClsFormatException e) {
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -194,7 +192,8 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
String signature = getSignatureAttribute();
|
||||
if (signature == null) return false;
|
||||
|
||||
myType = new ClsTypeElementImpl(this, GenericSignatureParsing.parseTypeString(new StringCharacterIterator(signature, 0)), ClsTypeElementImpl.VARIANCE_NONE);
|
||||
myType = new ClsTypeElementImpl(this, GenericSignatureParsing.parseTypeString(new StringCharacterIterator(signature, 0)),
|
||||
ClsTypeElementImpl.VARIANCE_NONE);
|
||||
return true;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
@@ -203,14 +202,13 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
}
|
||||
|
||||
public PsiModifierList getModifierList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
int flags = getAccessFlags();
|
||||
myModifierList = new ClsModifierListImpl(this, flags & ClsUtil.ACC_FIELD_MASK);
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
int flags = getAccessFlags();
|
||||
myModifierList = new ClsModifierListImpl(this, flags & ClsUtil.ACC_FIELD_MASK);
|
||||
}
|
||||
return myModifierList;
|
||||
}
|
||||
return myModifierList;
|
||||
}
|
||||
|
||||
public boolean hasModifierProperty(String name) {
|
||||
@@ -218,49 +216,48 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
}
|
||||
|
||||
private int getAccessFlags() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
int offset = myStartOffset;
|
||||
byte[] data = myParent.getClassFileData().getData();
|
||||
if (offset + 2 > data.length) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
return (b1 << 8) + b2;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
return 0;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
int offset = myStartOffset;
|
||||
byte[] data = myParent.getClassFileData().getData();
|
||||
if (offset + 2 > data.length) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
return (b1 << 8) + b2;
|
||||
}
|
||||
else {
|
||||
FieldView fieldView = getRepositoryManager().getFieldView();
|
||||
return fieldView.getModifiers(repositoryId);
|
||||
catch (ClsFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FieldView fieldView = getRepositoryManager().getFieldView();
|
||||
return fieldView.getModifiers(repositoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PsiExpression getInitializer() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (!myInitializerInitialized) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
myInitializer = createInitializerFromClassFile();
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (!myInitializerInitialized) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
myInitializer = createInitializerFromClassFile();
|
||||
}
|
||||
else {
|
||||
myInitializer = createInitializerFromRepository();
|
||||
catch (ClsFormatException e) {
|
||||
}
|
||||
myInitializerInitialized = true;
|
||||
}
|
||||
;
|
||||
else {
|
||||
myInitializer = createInitializerFromRepository();
|
||||
}
|
||||
myInitializerInitialized = true;
|
||||
}
|
||||
return myInitializer;
|
||||
}
|
||||
return myInitializer;
|
||||
}
|
||||
|
||||
private PsiExpression createInitializerFromClassFile() throws ClsFormatException {
|
||||
@@ -275,15 +272,15 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
int kind = ClsUtil.readU1(ptr);
|
||||
|
||||
PsiType type = getType();
|
||||
if (PsiType.INT == type){
|
||||
if (kind != ClsUtil.CONSTANT_Integer){
|
||||
if (PsiType.INT == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Integer) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int v = ClsUtil.readU4(ptr);
|
||||
return createNumberExpr(v);
|
||||
}
|
||||
else if (PsiType.LONG == type){
|
||||
if (kind != ClsUtil.CONSTANT_Long){
|
||||
else if (PsiType.LONG == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Long) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int valueH = ClsUtil.readU4(ptr);
|
||||
@@ -291,22 +288,22 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
long v = ((long)valueH << 32) | (valueL & 0xFFFFFFFFL);
|
||||
return createNumberExpr(v);
|
||||
}
|
||||
else if (PsiType.SHORT == type){
|
||||
if (kind != ClsUtil.CONSTANT_Integer){
|
||||
else if (PsiType.SHORT == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Integer) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int v = ClsUtil.readU4(ptr);
|
||||
return createNumberExpr(v);
|
||||
}
|
||||
else if (PsiType.BYTE == type){
|
||||
if (kind != ClsUtil.CONSTANT_Integer){
|
||||
else if (PsiType.BYTE == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Integer) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int v = ClsUtil.readU4(ptr);
|
||||
return createNumberExpr(v);
|
||||
}
|
||||
else if (PsiType.CHAR == type){
|
||||
if (kind != ClsUtil.CONSTANT_Integer){
|
||||
else if (PsiType.CHAR == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Integer) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
char v = (char)ClsUtil.readU4(ptr);
|
||||
@@ -314,8 +311,8 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
String text = literalToString(value.toString(), '\'');
|
||||
return new ClsLiteralExpressionImpl(this, text, type, value);
|
||||
}
|
||||
else if (PsiType.BOOLEAN == type){
|
||||
if (kind != ClsUtil.CONSTANT_Integer){
|
||||
else if (PsiType.BOOLEAN == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Integer) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int v = ClsUtil.readU4(ptr);
|
||||
@@ -323,42 +320,42 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
String text = value.toString();
|
||||
return new ClsLiteralExpressionImpl(this, text, type, value);
|
||||
}
|
||||
else if (PsiType.FLOAT == type){
|
||||
if (kind != ClsUtil.CONSTANT_Float){
|
||||
else if (PsiType.FLOAT == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Float) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
float v = ClsUtil.readFloat(ptr);
|
||||
String text;
|
||||
if (Float.isInfinite(v)){
|
||||
if (Float.isInfinite(v)) {
|
||||
text = v > 0 ? "Float.POSITIVE_INFINITY" : "Float.NEGATIVE_INFINITY";
|
||||
}
|
||||
else if (Float.isNaN(v)){
|
||||
else if (Float.isNaN(v)) {
|
||||
text = "Float.NaN";
|
||||
}
|
||||
else{
|
||||
else {
|
||||
text = Float.toString(v) + "f";
|
||||
}
|
||||
return ClsParsingUtil.createExpressionFromText(text, getManager(), this);
|
||||
}
|
||||
else if (PsiType.DOUBLE == type){
|
||||
if (kind != ClsUtil.CONSTANT_Double){
|
||||
else if (PsiType.DOUBLE == type) {
|
||||
if (kind != ClsUtil.CONSTANT_Double) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
double v = ClsUtil.readDouble(ptr);
|
||||
String text;
|
||||
if (Double.isInfinite(v)){
|
||||
if (Double.isInfinite(v)) {
|
||||
text = v > 0 ? "Double.POSITIVE_INFINITY" : "Double.NEGATIVE_INFINITY";
|
||||
}
|
||||
else if (Double.isNaN(v)){
|
||||
else if (Double.isNaN(v)) {
|
||||
text = "Double.NaN";
|
||||
}
|
||||
else{
|
||||
else {
|
||||
text = Double.toString(v);
|
||||
}
|
||||
return ClsParsingUtil.createExpressionFromText(text, getManager(), this);
|
||||
}
|
||||
else if (getTypeElement() != null && "java.lang.String".equals(((ClsTypeElementImpl) getTypeElement()).getCanonicalText())){
|
||||
if (kind != ClsUtil.CONSTANT_String){
|
||||
else if (getTypeElement() != null && "java.lang.String".equals(((ClsTypeElementImpl)getTypeElement()).getCanonicalText())) {
|
||||
if (kind != ClsUtil.CONSTANT_String) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int stringIndex = ClsUtil.readU2(ptr);
|
||||
@@ -367,13 +364,13 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
String text = literalToString(value, '"');
|
||||
return new ClsLiteralExpressionImpl(this, text, type, value);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
}
|
||||
|
||||
private PsiExpression createNumberExpr(long v) {
|
||||
if (v < 0){
|
||||
if (v < 0) {
|
||||
ClsLiteralExpressionImpl literalExpression = (ClsLiteralExpressionImpl)_createNumberExpr(-v, true);
|
||||
ClsPrefixExpressionImpl prefixExpression = new ClsPrefixExpressionImpl(this, literalExpression);
|
||||
literalExpression.setParent(prefixExpression);
|
||||
@@ -385,18 +382,18 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
|
||||
private PsiExpression _createNumberExpr(long v, boolean negated) {
|
||||
String text = Long.toString(v);
|
||||
if (negated && StringUtil.startsWithChar(text, '-')){
|
||||
if (negated && StringUtil.startsWithChar(text, '-')) {
|
||||
LOG.assertTrue(v == -1L << 63);
|
||||
text = text.substring(1);
|
||||
}
|
||||
|
||||
Object value;
|
||||
PsiType type;
|
||||
if (0 <= v && v <= Integer.MAX_VALUE || negated && v == (long)Integer.MAX_VALUE + 1){
|
||||
if (0 <= v && v <= Integer.MAX_VALUE || negated && v == (long)Integer.MAX_VALUE + 1) {
|
||||
type = PsiType.INT;
|
||||
value = new Integer((int)v);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
type = PsiType.LONG;
|
||||
text += "L";
|
||||
value = new Long(v);
|
||||
@@ -406,10 +403,10 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
|
||||
private PsiExpression createInitializerFromRepository() {
|
||||
String initializerText;
|
||||
try{
|
||||
try {
|
||||
initializerText = getRepositoryManager().getFieldView().getInitializerText(getRepositoryId());
|
||||
}
|
||||
catch(InitializerTooLongException e){
|
||||
catch (InitializerTooLongException e) {
|
||||
return null; //??
|
||||
}
|
||||
|
||||
@@ -423,48 +420,48 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
StringBuffer buffer = new StringBuffer(length + 3);
|
||||
buffer.append(quote);
|
||||
|
||||
for(int i = 0; i < length; i++){
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = value.charAt(i);
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
|
||||
buffer.append(c);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case '\b':
|
||||
buffer.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
buffer.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
buffer.append("\\n");
|
||||
break;
|
||||
case '\f':
|
||||
buffer.append("\\f");
|
||||
break;
|
||||
case '\r':
|
||||
buffer.append("\\r");
|
||||
break;
|
||||
case '\\':
|
||||
buffer.append("\\\\");
|
||||
break;
|
||||
default:
|
||||
if (c == quote) {
|
||||
buffer.append("\\" + quote);
|
||||
}
|
||||
else if (Character.isISOControl(c)) {
|
||||
String hexCode = Integer.toHexString(c).toUpperCase();
|
||||
buffer.append("\\x");
|
||||
int paddingCount = 4 - hexCode.length();
|
||||
while (paddingCount-- > 0) {
|
||||
buffer.append(0);
|
||||
}
|
||||
buffer.append(hexCode);
|
||||
}
|
||||
else {
|
||||
buffer.append(c);
|
||||
}
|
||||
case '\b':
|
||||
buffer.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
buffer.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
buffer.append("\\n");
|
||||
break;
|
||||
case '\f':
|
||||
buffer.append("\\f");
|
||||
break;
|
||||
case '\r':
|
||||
buffer.append("\\r");
|
||||
break;
|
||||
case '\\':
|
||||
buffer.append("\\\\");
|
||||
break;
|
||||
default:
|
||||
if (c == quote) {
|
||||
buffer.append("\\" + quote);
|
||||
}
|
||||
else if (Character.isISOControl(c)) {
|
||||
String hexCode = Integer.toHexString(c).toUpperCase();
|
||||
buffer.append("\\x");
|
||||
int paddingCount = 4 - hexCode.length();
|
||||
while (paddingCount-- > 0) {
|
||||
buffer.append(0);
|
||||
}
|
||||
buffer.append(hexCode);
|
||||
}
|
||||
else {
|
||||
buffer.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,7 +487,8 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
if ("POSITIVE_INFINITY".equals(getName())) return new Float(Float.POSITIVE_INFINITY);
|
||||
if ("NEGATIVE_INFINITY".equals(getName())) return new Float(Float.NEGATIVE_INFINITY);
|
||||
if ("NaN".equals(getName())) return new Float(Float.NaN);
|
||||
} else if ("java.lang.Double".equals(qName)) {
|
||||
}
|
||||
else if ("java.lang.Double".equals(qName)) {
|
||||
if ("POSITIVE_INFINITY".equals(getName())) return new Double(Double.POSITIVE_INFINITY);
|
||||
if ("NEGATIVE_INFINITY".equals(getName())) return new Double(Double.NEGATIVE_INFINITY);
|
||||
if ("NaN".equals(getName())) return new Double(Double.NaN);
|
||||
@@ -500,38 +498,36 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myIsDeprecated == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
boolean isDeprecated = myParent.getClassFileData().findAttribute(myStartOffset + 6, "Deprecated") != null;
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myIsDeprecated = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean isDeprecated = getRepositoryManager().getFieldView().isDeprecated(repositoryId);
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myIsDeprecated == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
boolean isDeprecated = myParent.getClassFileData().findAttribute(myStartOffset + 6, "Deprecated") != null;
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myIsDeprecated = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean isDeprecated = getRepositoryManager().getFieldView().isDeprecated(repositoryId);
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
;
|
||||
}
|
||||
return myIsDeprecated.booleanValue();
|
||||
}
|
||||
return myIsDeprecated.booleanValue();
|
||||
}
|
||||
|
||||
public PsiDocComment getDocComment() {
|
||||
if (!isDeprecated()) return null;
|
||||
if (!isDeprecated()) return null;
|
||||
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myDocComment == null) {
|
||||
myDocComment = new ClsDocCommentImpl(this);
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myDocComment == null) {
|
||||
myDocComment = new ClsDocCommentImpl(this);
|
||||
}
|
||||
return myDocComment;
|
||||
}
|
||||
return myDocComment;
|
||||
}
|
||||
|
||||
public void normalizeDeclaration() throws IncorrectOperationException {
|
||||
@@ -540,7 +536,7 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
public String getMirrorText() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment();
|
||||
if (docComment != null){
|
||||
if (docComment != null) {
|
||||
buffer.append(docComment.getMirrorText());
|
||||
}
|
||||
buffer.append(((ClsElementImpl)getModifierList()).getMirrorText());
|
||||
@@ -548,7 +544,7 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
buffer.append(((ClsElementImpl)getTypeElement()).getMirrorText());
|
||||
buffer.append(' ');
|
||||
buffer.append(((ClsElementImpl)getNameIdentifier()).getMirrorText());
|
||||
if (getInitializer() != null){
|
||||
if (getInitializer() != null) {
|
||||
buffer.append("=");
|
||||
buffer.append(getInitializer().getText());
|
||||
}
|
||||
@@ -563,12 +559,12 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
myMirror = element;
|
||||
|
||||
PsiField mirror = (PsiField)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
if (getDocComment() != null){
|
||||
((ClsElementImpl)getDocComment()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
if (getDocComment() != null) {
|
||||
((ClsElementImpl)getDocComment()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
}
|
||||
((ClsElementImpl)getModifierList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getTypeElement()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getTypeElement()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getTypeElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeElement()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
}
|
||||
|
||||
public void accept(PsiElementVisitor visitor) {
|
||||
@@ -604,7 +600,8 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, P
|
||||
myAnnotations = ClsAnnotationsUtil.getAnnotationsImpl(this, reader, myModifierList);
|
||||
}
|
||||
|
||||
return myAnnotations; }
|
||||
return myAnnotations;
|
||||
}
|
||||
|
||||
public PomField getPom() {
|
||||
//TODO:
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.lang.ASTNode;
|
||||
|
||||
public class ClsFileImpl extends ClsRepositoryPsiElement implements PsiJavaFile, PsiFileEx {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsFileImpl");
|
||||
@@ -188,14 +189,14 @@ public class ClsFileImpl extends ClsRepositoryPsiElement implements PsiJavaFile,
|
||||
|
||||
PsiPackageStatement packageStatement = ((PsiJavaFile)SourceTreeToPsiMap.treeElementToPsi(myMirror)).getPackageStatement();
|
||||
if (packageStatement != null) {
|
||||
((ClsElementImpl)getPackageStatement()).setMirror(SourceTreeToPsiMap.psiElementToTree(packageStatement));
|
||||
((ClsElementImpl)getPackageStatement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(packageStatement));
|
||||
}
|
||||
PsiClass[] classes = getClasses();
|
||||
PsiClass[] mirrorClasses = ((PsiJavaFile)SourceTreeToPsiMap.treeElementToPsi(myMirror)).getClasses();
|
||||
LOG.assertTrue(classes.length == mirrorClasses.length);
|
||||
if (classes.length == mirrorClasses.length) {
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
((ClsElementImpl)classes[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(mirrorClasses[i]));
|
||||
((ClsElementImpl)classes[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorClasses[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,17 +222,16 @@ public class ClsFileImpl extends ClsRepositoryPsiElement implements PsiJavaFile,
|
||||
String fileName = aClass.getName() + "." + ext;
|
||||
PsiManager manager = getManager();
|
||||
PsiFile mirror = manager.getElementFactory().createFileFromText(fileName, text);
|
||||
TreeElement mirrorTreeElement = SourceTreeToPsiMap.psiElementToTree(mirror);
|
||||
ASTNode mirrorTreeElement = SourceTreeToPsiMap.psiElementToTree(mirror);
|
||||
|
||||
//IMPORTANT: do not take lock too early - FileDocumentManager.getInstance().saveToString() can run write action...
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myMirror == null) {
|
||||
setMirror(mirrorTreeElement);
|
||||
myMirror.putUserData(DOCUMENT_IN_MIRROR_KEY, document);
|
||||
}
|
||||
;
|
||||
if (myMirror == null) {
|
||||
setMirror((TreeElement)mirrorTreeElement);
|
||||
myMirror.putUserData(DOCUMENT_IN_MIRROR_KEY, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
+ (returnType != null ? 1 : 0)
|
||||
+ (name != null ? 1 : 0)
|
||||
+ (throwsList != null ? 1 : 0)
|
||||
+ (defaultValue != null ? 1 : 0);;
|
||||
+ (defaultValue != null ? 1 : 0);
|
||||
;
|
||||
PsiElement[] children = new PsiElement[count];
|
||||
|
||||
int offset = 0;
|
||||
@@ -111,7 +112,7 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
|
||||
public PsiElement getParent() {
|
||||
final long parentId = getParentId();
|
||||
if(parentId < 0) return myParent;
|
||||
if (parentId < 0) return myParent;
|
||||
return getRepositoryElementsManager().findOrCreatePsiElementById(parentId);
|
||||
}
|
||||
|
||||
@@ -120,13 +121,13 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
}
|
||||
|
||||
public PsiIdentifier getNameIdentifier() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myNameIdentifier == null) {
|
||||
myNameIdentifier = new ClsIdentifierImpl(this, getName());
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myNameIdentifier == null) {
|
||||
myNameIdentifier = new ClsIdentifierImpl(this, getName());
|
||||
}
|
||||
return myNameIdentifier;
|
||||
;
|
||||
}
|
||||
return myNameIdentifier;
|
||||
}
|
||||
|
||||
public PsiMethod[] findSuperMethods() {
|
||||
@@ -160,38 +161,38 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
|
||||
public String getName() {
|
||||
if (myName == null) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 2;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
String name = ClsUtil.readUtf8Info(data, offset);
|
||||
if (name.equals("<init>")) {
|
||||
name = myParent.getName();
|
||||
myConstructorFlag = true;
|
||||
}
|
||||
else {
|
||||
myConstructorFlag = false;
|
||||
}
|
||||
myName = name;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 2;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
String name = ClsUtil.readUtf8Info(data, offset);
|
||||
if (name.equals("<init>")) {
|
||||
name = myParent.getName();
|
||||
myConstructorFlag = true;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myName = "";
|
||||
else {
|
||||
myConstructorFlag = false;
|
||||
}
|
||||
myName = name;
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
myName = methodView.getName(repositoryId);
|
||||
myConstructorFlag = methodView.getReturnTypeText(repositoryId) == null;
|
||||
catch (ClsFormatException e) {
|
||||
myName = "";
|
||||
}
|
||||
;
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
myName = methodView.getName(repositoryId);
|
||||
myConstructorFlag = methodView.getReturnTypeText(repositoryId) == null;
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
return myName;
|
||||
}
|
||||
@@ -202,44 +203,44 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
}
|
||||
|
||||
public PsiTypeElement getReturnTypeElement() {
|
||||
if (isConstructor()) return null;
|
||||
if (isConstructor()) return null;
|
||||
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myReturnType == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 4;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
offset += 3; // skip tag and length
|
||||
while (true) {
|
||||
if (offset >= data.length) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
if (data[offset++] == ')') break;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myReturnType == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
byte[] data = classFileData.getData();
|
||||
int offset = myStartOffset + 4;
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
int index = (b1 << 8) + b2;
|
||||
offset = classFileData.getOffsetInConstantPool(index);
|
||||
offset += 3; // skip tag and length
|
||||
while (true) {
|
||||
if (offset >= data.length) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
String typeText = ClsUtil.getTypeText(data, offset);
|
||||
myReturnType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myReturnType = null;
|
||||
if (data[offset++] == ')') break;
|
||||
}
|
||||
String typeText = ClsUtil.getTypeText(data, offset);
|
||||
myReturnType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myReturnType = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
String typeText = getRepositoryManager().getMethodView().getReturnTypeText(repositoryId);
|
||||
myReturnType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
}
|
||||
;
|
||||
else {
|
||||
String typeText = getRepositoryManager().getMethodView().getReturnTypeText(repositoryId);
|
||||
myReturnType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
|
||||
}
|
||||
}
|
||||
return myReturnType;
|
||||
;
|
||||
}
|
||||
return myReturnType;
|
||||
}
|
||||
|
||||
public PsiType getReturnType() {
|
||||
@@ -248,14 +249,14 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
}
|
||||
|
||||
public PsiModifierList getModifierList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
int flags = getAccessFlags();
|
||||
myModifierList = new ClsModifierListImpl(this, flags & ClsUtil.ACC_METHOD_MASK);
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
int flags = getAccessFlags();
|
||||
myModifierList = new ClsModifierListImpl(this, flags & ClsUtil.ACC_METHOD_MASK);
|
||||
}
|
||||
return myModifierList;
|
||||
;
|
||||
}
|
||||
return myModifierList;
|
||||
}
|
||||
|
||||
public boolean hasModifierProperty(String name) {
|
||||
@@ -263,44 +264,44 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
}
|
||||
|
||||
private int getAccessFlags() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
int offset = myStartOffset;
|
||||
byte[] data = myParent.getClassFileData().getData();
|
||||
if (offset + 2 > data.length) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
return (b1 << 8) + b2;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
return 0;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
int offset = myStartOffset;
|
||||
byte[] data = myParent.getClassFileData().getData();
|
||||
if (offset + 2 > data.length) {
|
||||
throw new ClsFormatException();
|
||||
}
|
||||
int b1 = data[offset++] & 0xFF;
|
||||
int b2 = data[offset++] & 0xFF;
|
||||
return (b1 << 8) + b2;
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
return methodView.getModifiers(repositoryId);
|
||||
catch (ClsFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
return methodView.getModifiers(repositoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean isBridge () throws ClsFormatException {
|
||||
return ClsUtil.isBridge(getAccessFlags()) ||
|
||||
//This is 2.2 spec rudiment; TODO remove it
|
||||
myParent.getClassFileData().findAttribute(myStartOffset + 6, "Bridge") != null;
|
||||
boolean isBridge() throws ClsFormatException {
|
||||
return ClsUtil.isBridge(getAccessFlags()) ||
|
||||
//This is 2.2 spec rudiment; TODO remove it
|
||||
myParent.getClassFileData().findAttribute(myStartOffset + 6, "Bridge") != null;
|
||||
}
|
||||
|
||||
public PsiParameterList getParameterList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myParameterList == null && !parseViaGenericSignature()) {
|
||||
myParameterList = createParameters(calcParameterTypes());
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myParameterList == null && !parseViaGenericSignature()) {
|
||||
myParameterList = createParameters(calcParameterTypes());
|
||||
}
|
||||
}
|
||||
|
||||
return myParameterList;
|
||||
return myParameterList;
|
||||
}
|
||||
|
||||
private PsiParameterList createParameters(ArrayList<String> types) {
|
||||
@@ -316,16 +317,16 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
return parameterList;
|
||||
}
|
||||
|
||||
private ClsAnnotationImpl[][] calcParameterAnnotations () {
|
||||
private ClsAnnotationImpl[][] calcParameterAnnotations() {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
try {
|
||||
BytePointer pointer1 = classFileData.findAttribute(myStartOffset + 6, "RuntimeVisibleParameterAnnotations");
|
||||
BytePointer pointer1 = classFileData.findAttribute(myStartOffset + 6, "RuntimeVisibleParameterAnnotations");
|
||||
ClsParameterImpl[] parameters = (ClsParameterImpl[])myParameterList.getParameters();
|
||||
if (pointer1 != null) {
|
||||
ClsAnnotationImpl[][] ann1 = readParameterAnnotations(pointer1, parameters);
|
||||
BytePointer pointer2 = classFileData.findAttribute(myStartOffset + 6, "RuntimeInvisibleParameterAnnotations");
|
||||
BytePointer pointer2 = classFileData.findAttribute(myStartOffset + 6, "RuntimeInvisibleParameterAnnotations");
|
||||
if (pointer2 != null) {
|
||||
ClsAnnotationImpl[][] ann2 = readParameterAnnotations(pointer2, parameters);
|
||||
ClsAnnotationImpl[][] result = ArrayUtil.mergeArrays(ann1, ann2, ClsAnnotationImpl[].class);
|
||||
@@ -336,7 +337,7 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
}
|
||||
}
|
||||
else {
|
||||
BytePointer pointer2 = classFileData.findAttribute(myStartOffset + 6, "RuntimeInvisibleParameterAnnotations");
|
||||
BytePointer pointer2 = classFileData.findAttribute(myStartOffset + 6, "RuntimeInvisibleParameterAnnotations");
|
||||
if (pointer2 != null) {
|
||||
return readParameterAnnotations(pointer2, parameters);
|
||||
}
|
||||
@@ -348,7 +349,8 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
catch (ClsFormatException e) {
|
||||
return new ClsAnnotationImpl[0][];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
|
||||
String[][] parameterAnnotations = methodView.getParameterAnnotations(repositoryId);
|
||||
@@ -358,7 +360,8 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
ClsParameterImpl parameter = (ClsParameterImpl)myParameterList.getParameters()[i];
|
||||
result[i] = new ClsAnnotationImpl[annotations.length];
|
||||
for (int j = 0; j < annotations.length; j++) {
|
||||
result[i][j] = (ClsAnnotationImpl)ClsAnnotationsUtil.createMemberValueFromText(annotations[j], myManager, (ClsElementImpl)parameter.getModifierList());
|
||||
result[i][j] = (ClsAnnotationImpl)ClsAnnotationsUtil.createMemberValueFromText(annotations[j], myManager,
|
||||
(ClsElementImpl)parameter.getModifierList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,68 +452,68 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
if (isVarArgs()) {
|
||||
String lastParamTypeText = types.get(types.size() - 1);
|
||||
LOG.assertTrue(lastParamTypeText.endsWith("[]"));
|
||||
lastParamTypeText = lastParamTypeText.substring(0 ,lastParamTypeText.length() - 2) + "...";
|
||||
lastParamTypeText = lastParamTypeText.substring(0, lastParamTypeText.length() - 2) + "...";
|
||||
types.set(types.size() - 1, lastParamTypeText);
|
||||
}
|
||||
}
|
||||
|
||||
public PsiReferenceList getThrowsList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myThrowsList == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
parseViaGenericSignature();
|
||||
if (myThrowsList == null) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
BytePointer ptr = classFileData.findAttribute(myStartOffset + 6, "Exceptions");
|
||||
if (ptr != null) {
|
||||
ptr.offset += 4; // skip length
|
||||
int exceptionCount = ClsUtil.readU2(ptr);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[exceptionCount];
|
||||
int jj = 0;
|
||||
for (int j = 0; j < exceptionCount; j++) {
|
||||
int index = ClsUtil.readU2(ptr);
|
||||
if (index != 0) {
|
||||
refs[jj++] = classFileData.buildReference(index);
|
||||
}
|
||||
}
|
||||
if (jj < exceptionCount) {
|
||||
ClsJavaCodeReferenceElementImpl[] refs1 = new ClsJavaCodeReferenceElementImpl[jj];
|
||||
System.arraycopy(refs, 0, refs1, 0, jj);
|
||||
refs = refs1;
|
||||
}
|
||||
|
||||
myThrowsList = new ClsReferenceListImpl(this, refs, PsiKeyword.THROWS);
|
||||
for (int j = 0; j < refs.length; j++) {
|
||||
refs[j].setParent(myThrowsList);
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myThrowsList == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
parseViaGenericSignature();
|
||||
if (myThrowsList == null) {
|
||||
try {
|
||||
ClassFileData classFileData = myParent.getClassFileData();
|
||||
BytePointer ptr = classFileData.findAttribute(myStartOffset + 6, "Exceptions");
|
||||
if (ptr != null) {
|
||||
ptr.offset += 4; // skip length
|
||||
int exceptionCount = ClsUtil.readU2(ptr);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[exceptionCount];
|
||||
int jj = 0;
|
||||
for (int j = 0; j < exceptionCount; j++) {
|
||||
int index = ClsUtil.readU2(ptr);
|
||||
if (index != 0) {
|
||||
refs[jj++] = classFileData.buildReference(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
}
|
||||
if (myThrowsList == null) {
|
||||
myThrowsList = new ClsReferenceListImpl(this, new ClsJavaCodeReferenceElementImpl[0], PsiKeyword.THROWS);
|
||||
if (jj < exceptionCount) {
|
||||
ClsJavaCodeReferenceElementImpl[] refs1 = new ClsJavaCodeReferenceElementImpl[jj];
|
||||
System.arraycopy(refs, 0, refs1, 0, jj);
|
||||
refs = refs1;
|
||||
}
|
||||
|
||||
myThrowsList = new ClsReferenceListImpl(this, refs, PsiKeyword.THROWS);
|
||||
for (int j = 0; j < refs.length; j++) {
|
||||
refs[j].setParent(myThrowsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
String[] refTexts = methodView.getThrowsList(repositoryId);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[refTexts.length];
|
||||
for (int i = 0; i < refTexts.length; i++) {
|
||||
refs[i] = new ClsJavaCodeReferenceElementImpl(null, refTexts[i]);
|
||||
catch (ClsFormatException e) {
|
||||
}
|
||||
myThrowsList = new ClsReferenceListImpl(this, refs, PsiKeyword.THROWS);
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
ClsJavaCodeReferenceElementImpl ref = refs[i];
|
||||
ref.setParent(myThrowsList);
|
||||
if (myThrowsList == null) {
|
||||
myThrowsList = new ClsReferenceListImpl(this, new ClsJavaCodeReferenceElementImpl[0], PsiKeyword.THROWS);
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
String[] refTexts = methodView.getThrowsList(repositoryId);
|
||||
ClsJavaCodeReferenceElementImpl[] refs = new ClsJavaCodeReferenceElementImpl[refTexts.length];
|
||||
for (int i = 0; i < refTexts.length; i++) {
|
||||
refs[i] = new ClsJavaCodeReferenceElementImpl(null, refTexts[i]);
|
||||
}
|
||||
myThrowsList = new ClsReferenceListImpl(this, refs, PsiKeyword.THROWS);
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
ClsJavaCodeReferenceElementImpl ref = refs[i];
|
||||
ref.setParent(myThrowsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
return myThrowsList;
|
||||
;
|
||||
}
|
||||
return myThrowsList;
|
||||
}
|
||||
|
||||
public PsiCodeBlock getBody() {
|
||||
@@ -518,33 +521,33 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myIsDeprecated == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
boolean isDeprecated = myParent.getClassFileData().findAttribute(myStartOffset + 6, "Deprecated") != null;
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myIsDeprecated = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean isDeprecated = getRepositoryManager().getMethodView().isDeprecated(repositoryId);
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myIsDeprecated == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
try {
|
||||
boolean isDeprecated = myParent.getClassFileData().findAttribute(myStartOffset + 6, "Deprecated") != null;
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
myIsDeprecated = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean isDeprecated = getRepositoryManager().getMethodView().isDeprecated(repositoryId);
|
||||
myIsDeprecated = isDeprecated ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
;
|
||||
}
|
||||
return myIsDeprecated.booleanValue();
|
||||
;
|
||||
}
|
||||
return myIsDeprecated.booleanValue();
|
||||
}
|
||||
|
||||
ClassFileData getClassFileData () {
|
||||
ClassFileData getClassFileData() {
|
||||
return myParent.getClassFileData();
|
||||
}
|
||||
|
||||
public PsiAnnotationMemberValue getDefaultValue () {
|
||||
public PsiAnnotationMemberValue getDefaultValue() {
|
||||
if (myDefaultValue == null) {
|
||||
myDefaultValue = new PsiAnnotationMemberValue[1];
|
||||
|
||||
@@ -600,7 +603,7 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
iterator.next();
|
||||
myThrowsList = new ClsReferenceListImpl(this, "throws");
|
||||
PsiJavaCodeReferenceElement[] refs = GenericSignatureParsing.parseToplevelClassRefSignatures(iterator, myThrowsList);
|
||||
((ClsReferenceListImpl)myThrowsList).setReferences(refs);
|
||||
((ClsReferenceListImpl)myThrowsList).setReferences(refs);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -621,15 +624,15 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
}
|
||||
|
||||
public PsiDocComment getDocComment() {
|
||||
if (!isDeprecated()) return null;
|
||||
if (!isDeprecated()) return null;
|
||||
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myDocComment == null) {
|
||||
myDocComment = new ClsDocCommentImpl(this);
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myDocComment == null) {
|
||||
myDocComment = new ClsDocCommentImpl(this);
|
||||
}
|
||||
return myDocComment;
|
||||
;
|
||||
}
|
||||
return myDocComment;
|
||||
}
|
||||
|
||||
|
||||
@@ -643,7 +646,8 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
boolean isVarArgs;
|
||||
if (getRepositoryId() < 0) {
|
||||
isVarArgs = (getAccessFlags() & ClsUtil.ACC_VARARGS) != 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
RepositoryManager repositoryManager = getRepositoryManager();
|
||||
isVarArgs = repositoryManager.getMethodView().isVarArgs(getRepositoryId());
|
||||
}
|
||||
@@ -702,21 +706,21 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
|
||||
PsiMethod mirror = (PsiMethod)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
if (getDocComment() != null) {
|
||||
((ClsElementImpl)getDocComment()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
((ClsElementImpl)getDocComment()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
}
|
||||
((ClsElementImpl)getModifierList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
if (!isConstructor() && mirror.getReturnTypeElement() != null) {
|
||||
((ClsElementImpl)getReturnTypeElement()).setMirror(
|
||||
SourceTreeToPsiMap.psiElementToTree(mirror.getReturnTypeElement()));
|
||||
((ClsElementImpl)getReturnTypeElement()).setMirror(
|
||||
(TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getReturnTypeElement()));
|
||||
}
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
((ClsElementImpl)getParameterList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList()));
|
||||
((ClsElementImpl)getThrowsList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getThrowsList()));
|
||||
((ClsElementImpl)getTypeParameterList()).setMirror(
|
||||
SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
((ClsElementImpl)getParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList()));
|
||||
((ClsElementImpl)getThrowsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getThrowsList()));
|
||||
((ClsElementImpl)getTypeParameterList()).setMirror(
|
||||
(TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList()));
|
||||
if (getDefaultValue() != null) {
|
||||
LOG.assertTrue(mirror instanceof PsiAnnotationMethod);
|
||||
((ClsElementImpl)getDefaultValue()).setMirror(SourceTreeToPsiMap.psiElementToTree(((PsiAnnotationMethod)mirror).getDefaultValue()));
|
||||
((ClsElementImpl)getDefaultValue()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(((PsiAnnotationMethod)mirror).getDefaultValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -748,46 +752,46 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotat
|
||||
public PsiElement getNavigationElement() {
|
||||
PsiClass sourceClassMirror = ((ClsClassImpl)getParent()).getSourceMirrorClass();
|
||||
PsiMethod sourceMethodMirror = sourceClassMirror != null
|
||||
? sourceClassMirror.findMethodBySignature(this, false)
|
||||
: null;
|
||||
? sourceClassMirror.findMethodBySignature(this, false)
|
||||
: null;
|
||||
return sourceMethodMirror != null ? sourceMethodMirror : this;
|
||||
}
|
||||
|
||||
public PsiTypeParameterList getTypeParameterList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myTypeParameters == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myTypeParameters == null) {
|
||||
long repositoryId = getRepositoryId();
|
||||
if (repositoryId < 0) {
|
||||
if (!parseViaGenericSignature()) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
int count = methodView.getTypeParametersCount(repositoryId);
|
||||
if (count == 0) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
}
|
||||
else {
|
||||
MethodView methodView = getRepositoryManager().getMethodView();
|
||||
int count = methodView.getTypeParametersCount(repositoryId);
|
||||
if (count == 0) {
|
||||
myTypeParameters = new ClsTypeParametersListImpl(this, new ClsTypeParameterImpl[0]);
|
||||
StringBuffer compiledParams = new StringBuffer();
|
||||
compiledParams.append('<');
|
||||
for (int i = 0; i < count; i++) {
|
||||
compiledParams.append(methodView.getTypeParameterText(repositoryId, i));
|
||||
}
|
||||
else {
|
||||
StringBuffer compiledParams = new StringBuffer();
|
||||
compiledParams.append('<');
|
||||
for (int i = 0; i < count; i++) {
|
||||
compiledParams.append(methodView.getTypeParameterText(repositoryId, i));
|
||||
}
|
||||
compiledParams.append('>');
|
||||
try {
|
||||
final String signature = compiledParams.toString();
|
||||
myTypeParameters =
|
||||
GenericSignatureParsing.parseTypeParametersDeclaration(new StringCharacterIterator(signature, 0), this, signature);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
LOG.error(e); // dsl: should not happen when stuff is parsed from repository
|
||||
}
|
||||
compiledParams.append('>');
|
||||
try {
|
||||
final String signature = compiledParams.toString();
|
||||
myTypeParameters =
|
||||
GenericSignatureParsing.parseTypeParametersDeclaration(new StringCharacterIterator(signature, 0), this, signature);
|
||||
}
|
||||
catch (ClsFormatException e) {
|
||||
LOG.error(e); // dsl: should not happen when stuff is parsed from repository
|
||||
}
|
||||
}
|
||||
}
|
||||
return myTypeParameters;
|
||||
}
|
||||
return myTypeParameters;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasTypeParameters() {
|
||||
|
||||
@@ -13,8 +13,9 @@ import com.intellij.util.containers.HashMap;
|
||||
public class ClsModifierListImpl extends ClsElementImpl implements PsiModifierList {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsModifierListImpl");
|
||||
|
||||
private static final HashMap<String,Integer> ourModifierNameToFlagMap = new HashMap<String, Integer>();
|
||||
static{
|
||||
private static final HashMap<String, Integer> ourModifierNameToFlagMap = new HashMap<String, Integer>();
|
||||
|
||||
static {
|
||||
ourModifierNameToFlagMap.put(PsiModifier.PUBLIC, new Integer(ClsUtil.ACC_PUBLIC));
|
||||
ourModifierNameToFlagMap.put(PsiModifier.PROTECTED, new Integer(ClsUtil.ACC_PROTECTED));
|
||||
ourModifierNameToFlagMap.put(PsiModifier.PRIVATE, new Integer(ClsUtil.ACC_PRIVATE));
|
||||
@@ -31,23 +32,23 @@ public class ClsModifierListImpl extends ClsElementImpl implements PsiModifierLi
|
||||
private ClsAnnotationImpl[] myAnnotations = null;
|
||||
private final int myFlags;
|
||||
|
||||
public ClsModifierListImpl(ClsModifierListOwner parent, int flags){
|
||||
public ClsModifierListImpl(ClsModifierListOwner parent, int flags) {
|
||||
myParent = parent;
|
||||
myFlags = flags;
|
||||
}
|
||||
|
||||
public PsiElement[] getChildren(){
|
||||
public PsiElement[] getChildren() {
|
||||
return getAnnotations();
|
||||
}
|
||||
|
||||
public PsiElement getParent(){
|
||||
public PsiElement getParent() {
|
||||
return myParent;
|
||||
}
|
||||
|
||||
public boolean hasModifierProperty(String name){
|
||||
public boolean hasModifierProperty(String name) {
|
||||
Integer flag = ourModifierNameToFlagMap.get(name);
|
||||
if (flag == null){
|
||||
if (PsiModifier.PACKAGE_LOCAL.equals(name)){
|
||||
if (flag == null) {
|
||||
if (PsiModifier.PACKAGE_LOCAL.equals(name)) {
|
||||
return (myFlags & (ClsUtil.ACC_PUBLIC | ClsUtil.ACC_PROTECTED | ClsUtil.ACC_PRIVATE)) == 0;
|
||||
}
|
||||
return false;
|
||||
@@ -55,11 +56,11 @@ public class ClsModifierListImpl extends ClsElementImpl implements PsiModifierLi
|
||||
return (myFlags & flag.intValue()) != 0;
|
||||
}
|
||||
|
||||
public void setModifierProperty(String name, boolean value) throws IncorrectOperationException{
|
||||
public void setModifierProperty(String name, boolean value) throws IncorrectOperationException {
|
||||
throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE);
|
||||
}
|
||||
|
||||
public void checkSetModifierProperty(String name, boolean value) throws IncorrectOperationException{
|
||||
|
||||
public void checkSetModifierProperty(String name, boolean value) throws IncorrectOperationException {
|
||||
throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ public class ClsModifierListImpl extends ClsElementImpl implements PsiModifierLi
|
||||
return PsiImplUtil.findAnnotation(this, qualifiedName);
|
||||
}
|
||||
|
||||
public String getMirrorText(){
|
||||
public String getMirrorText() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
PsiAnnotation[] annotations = getAnnotations();
|
||||
for (int i = 0; i < annotations.length; i++) {
|
||||
@@ -87,59 +88,60 @@ public class ClsModifierListImpl extends ClsElementImpl implements PsiModifierLi
|
||||
boolean isInterface = myParent instanceof PsiClass && ((PsiClass)myParent).isInterface();
|
||||
boolean isInterfaceMethod = myParent instanceof PsiMethod && ((PsiClass)myParent.getParent()).isInterface();
|
||||
boolean isInterfaceField = myParent instanceof PsiField && ((PsiClass)myParent.getParent()).isInterface();
|
||||
boolean isInterfaceClass = myParent instanceof PsiClass && myParent.getParent() instanceof PsiClass && ((PsiClass)myParent.getParent()).isInterface();
|
||||
if (hasModifierProperty(PsiModifier.PUBLIC)){
|
||||
if (!isInterfaceMethod && !isInterfaceField && !isInterfaceClass){
|
||||
boolean isInterfaceClass =
|
||||
myParent instanceof PsiClass && myParent.getParent() instanceof PsiClass && ((PsiClass)myParent.getParent()).isInterface();
|
||||
if (hasModifierProperty(PsiModifier.PUBLIC)) {
|
||||
if (!isInterfaceMethod && !isInterfaceField && !isInterfaceClass) {
|
||||
buffer.append(PsiModifier.PUBLIC);
|
||||
buffer.append(' ');
|
||||
}
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.PROTECTED)){
|
||||
if (hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||
buffer.append(PsiModifier.PROTECTED);
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.PRIVATE)){
|
||||
if (hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
buffer.append(PsiModifier.PRIVATE);
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.STATIC)){
|
||||
if (!isInterfaceField){
|
||||
if (hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (!isInterfaceField) {
|
||||
buffer.append(PsiModifier.STATIC);
|
||||
buffer.append(' ');
|
||||
}
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.ABSTRACT)){
|
||||
if (!isInterface && !isInterfaceMethod){
|
||||
if (hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
if (!isInterface && !isInterfaceMethod) {
|
||||
buffer.append(PsiModifier.ABSTRACT);
|
||||
buffer.append(' ');
|
||||
}
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.FINAL)){
|
||||
if (!isInterfaceField){
|
||||
if (hasModifierProperty(PsiModifier.FINAL)) {
|
||||
if (!isInterfaceField) {
|
||||
buffer.append(PsiModifier.FINAL);
|
||||
buffer.append(' ');
|
||||
}
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.NATIVE)){
|
||||
if (hasModifierProperty(PsiModifier.NATIVE)) {
|
||||
buffer.append(PsiModifier.NATIVE);
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.SYNCHRONIZED)){
|
||||
if (hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
|
||||
buffer.append(PsiModifier.SYNCHRONIZED);
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.TRANSIENT)){
|
||||
if (hasModifierProperty(PsiModifier.TRANSIENT)) {
|
||||
buffer.append(PsiModifier.TRANSIENT);
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (hasModifierProperty(PsiModifier.VOLATILE)){
|
||||
if (hasModifierProperty(PsiModifier.VOLATILE)) {
|
||||
buffer.append(PsiModifier.VOLATILE);
|
||||
buffer.append(' ');
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public void setMirror(TreeElement element){
|
||||
public void setMirror(TreeElement element) {
|
||||
LOG.assertTrue(myMirror == null);
|
||||
LOG.assertTrue(element.getElementType() == ElementType.MODIFIER_LIST);
|
||||
myMirror = element;
|
||||
@@ -147,11 +149,11 @@ public class ClsModifierListImpl extends ClsElementImpl implements PsiModifierLi
|
||||
PsiAnnotation[] annotations = getAnnotations();
|
||||
LOG.assertTrue(annotations.length == mirrorAnnotations.length);
|
||||
for (int i = 0; i < annotations.length; i++) {
|
||||
((ClsElementImpl)annotations[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(mirrorAnnotations[i]));
|
||||
((ClsElementImpl)annotations[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorAnnotations[i]));
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(PsiElementVisitor visitor){
|
||||
public void accept(PsiElementVisitor visitor) {
|
||||
visitor.visitModifierList(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ public class ClsNameValuePairImpl extends ClsElementImpl implements PsiNameValue
|
||||
myMirror = element;
|
||||
|
||||
PsiNameValuePair mirror = (PsiNameValuePair)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
((ClsElementImpl)getValue()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getValue()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
((ClsElementImpl)getValue()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getValue()));
|
||||
}
|
||||
|
||||
public PsiElement[] getChildren() {
|
||||
return new PsiElement[] {myNameIdentifier, myMemberValue};
|
||||
return new PsiElement[]{myNameIdentifier, myMemberValue};
|
||||
}
|
||||
|
||||
public PsiElement getParent() {
|
||||
|
||||
@@ -62,13 +62,13 @@ public class ClsParameterImpl extends ClsElementImpl implements PsiParameter, Cl
|
||||
}
|
||||
|
||||
public PsiModifierList getModifierList() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
myModifierList = new ClsModifierListImpl(this, 0);
|
||||
}
|
||||
;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myModifierList == null) {
|
||||
myModifierList = new ClsModifierListImpl(this, 0);
|
||||
}
|
||||
return myModifierList;
|
||||
;
|
||||
}
|
||||
return myModifierList;
|
||||
}
|
||||
|
||||
public boolean hasModifierProperty(String name) {
|
||||
@@ -104,36 +104,36 @@ public class ClsParameterImpl extends ClsElementImpl implements PsiParameter, Cl
|
||||
}
|
||||
|
||||
private String getMirrorName() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myMirrorName == null) {
|
||||
String name = getName();
|
||||
if (name != null) return name;
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myMirrorName == null) {
|
||||
String name = getName();
|
||||
if (name != null) return name;
|
||||
|
||||
String[] nameSuggestions = getManager().getCodeStyleManager().suggestVariableName(VariableKind.PARAMETER, null,
|
||||
null, getType())
|
||||
.names;
|
||||
name = "p";
|
||||
if (nameSuggestions.length > 0) {
|
||||
name = nameSuggestions[0];
|
||||
}
|
||||
String[] nameSuggestions = getManager().getCodeStyleManager().suggestVariableName(VariableKind.PARAMETER, null,
|
||||
null, getType())
|
||||
.names;
|
||||
name = "p";
|
||||
if (nameSuggestions.length > 0) {
|
||||
name = nameSuggestions[0];
|
||||
}
|
||||
|
||||
PsiParameter[] parms = ((PsiParameterList)getParent()).getParameters();
|
||||
AttemptsLoop:
|
||||
while (true) {
|
||||
for (int i = 0; i < parms.length; i++) {
|
||||
if (parms[i] == this) break AttemptsLoop;
|
||||
String name1 = ((ClsParameterImpl)parms[i]).getMirrorName();
|
||||
if (name.equals(name1)) {
|
||||
name = nextName(name);
|
||||
continue AttemptsLoop;
|
||||
}
|
||||
PsiParameter[] parms = ((PsiParameterList)getParent()).getParameters();
|
||||
AttemptsLoop:
|
||||
while (true) {
|
||||
for (int i = 0; i < parms.length; i++) {
|
||||
if (parms[i] == this) break AttemptsLoop;
|
||||
String name1 = ((ClsParameterImpl)parms[i]).getMirrorName();
|
||||
if (name.equals(name1)) {
|
||||
name = nextName(name);
|
||||
continue AttemptsLoop;
|
||||
}
|
||||
}
|
||||
myMirrorName = name;
|
||||
}
|
||||
;
|
||||
myMirrorName = name;
|
||||
}
|
||||
return myMirrorName;
|
||||
;
|
||||
}
|
||||
return myMirrorName;
|
||||
}
|
||||
|
||||
private static String nextName(String name) {
|
||||
@@ -165,8 +165,8 @@ public class ClsParameterImpl extends ClsElementImpl implements PsiParameter, Cl
|
||||
myMirror = element;
|
||||
|
||||
PsiParameter mirror = (PsiParameter)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
((ClsElementImpl)getModifierList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getTypeElement()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getTypeElement()));
|
||||
((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getTypeElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeElement()));
|
||||
}
|
||||
|
||||
public void accept(PsiElementVisitor visitor) {
|
||||
|
||||
@@ -20,15 +20,15 @@ public class ClsParameterListImpl extends ClsElementImpl implements PsiParameter
|
||||
myParameters = parameters;
|
||||
}
|
||||
|
||||
public PsiElement[] getChildren(){
|
||||
public PsiElement[] getChildren() {
|
||||
return myParameters;
|
||||
}
|
||||
|
||||
public PsiElement getParent(){
|
||||
public PsiElement getParent() {
|
||||
return myParent;
|
||||
}
|
||||
|
||||
public PsiParameter[] getParameters(){
|
||||
public PsiParameter[] getParameters() {
|
||||
return myParameters;
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ public class ClsParameterListImpl extends ClsElementImpl implements PsiParameter
|
||||
return PsiImplUtil.getParameterIndex(parameter, this);
|
||||
}
|
||||
|
||||
public String getMirrorText(){
|
||||
public String getMirrorText() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append('(');
|
||||
for(int i = 0; i < myParameters.length; i++) {
|
||||
for (int i = 0; i < myParameters.length; i++) {
|
||||
PsiParameter parm = myParameters[i];
|
||||
if (i > 0) buffer.append(",");
|
||||
buffer.append(((ClsElementImpl)parm).getMirrorText());
|
||||
@@ -49,21 +49,21 @@ public class ClsParameterListImpl extends ClsElementImpl implements PsiParameter
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public void setMirror(TreeElement element){
|
||||
public void setMirror(TreeElement element) {
|
||||
LOG.assertTrue(myMirror == null);
|
||||
myMirror = element;
|
||||
|
||||
PsiParameter[] parms = getParameters();
|
||||
PsiParameter[] parmMirrors = ((PsiParameterList)SourceTreeToPsiMap.treeElementToPsi(myMirror)).getParameters();
|
||||
LOG.assertTrue(parms.length == parmMirrors.length);
|
||||
if (parms.length == parmMirrors.length){
|
||||
for(int i = 0; i < parms.length; i++) {
|
||||
((ClsElementImpl)parms[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(parmMirrors[i]));
|
||||
if (parms.length == parmMirrors.length) {
|
||||
for (int i = 0; i < parms.length; i++) {
|
||||
((ClsElementImpl)parms[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(parmMirrors[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(PsiElementVisitor visitor){
|
||||
public void accept(PsiElementVisitor visitor) {
|
||||
visitor.visitParameterList(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,39 +30,39 @@ public class ClsReferenceListImpl extends ClsElementImpl implements PsiReference
|
||||
myReferences = references;
|
||||
}
|
||||
|
||||
public PsiElement[] getChildren(){
|
||||
public PsiElement[] getChildren() {
|
||||
return myReferences;
|
||||
}
|
||||
|
||||
public PsiElement getParent(){
|
||||
public PsiElement getParent() {
|
||||
return myParent;
|
||||
}
|
||||
|
||||
public PsiJavaCodeReferenceElement[] getReferenceElements(){
|
||||
public PsiJavaCodeReferenceElement[] getReferenceElements() {
|
||||
return myReferences;
|
||||
}
|
||||
|
||||
public PsiClassType[] getReferencedTypes() {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myTypes == null) {
|
||||
final PsiElementFactory factory = getManager().getElementFactory();
|
||||
myTypes = new PsiClassType[myReferences.length];
|
||||
for (int i = 0; i < myReferences.length; i++) {
|
||||
PsiJavaCodeReferenceElement reference = myReferences[i];
|
||||
myTypes[i] = factory.createType(reference);
|
||||
}
|
||||
synchronized (PsiLock.LOCK) {
|
||||
if (myTypes == null) {
|
||||
final PsiElementFactory factory = getManager().getElementFactory();
|
||||
myTypes = new PsiClassType[myReferences.length];
|
||||
for (int i = 0; i < myReferences.length; i++) {
|
||||
PsiJavaCodeReferenceElement reference = myReferences[i];
|
||||
myTypes[i] = factory.createType(reference);
|
||||
}
|
||||
;
|
||||
}
|
||||
return myTypes;
|
||||
;
|
||||
}
|
||||
return myTypes;
|
||||
}
|
||||
|
||||
public String getMirrorText(){
|
||||
public String getMirrorText() {
|
||||
if (myReferences.length == 0) return "";
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(myType);
|
||||
buffer.append(" ");
|
||||
for(int i = 0; i < myReferences.length; i++) {
|
||||
for (int i = 0; i < myReferences.length; i++) {
|
||||
PsiJavaCodeReferenceElement ref = myReferences[i];
|
||||
if (i > 0) buffer.append(",");
|
||||
buffer.append(((ClsElementImpl)ref).getMirrorText());
|
||||
@@ -70,21 +70,21 @@ public class ClsReferenceListImpl extends ClsElementImpl implements PsiReference
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public void setMirror(TreeElement element){
|
||||
public void setMirror(TreeElement element) {
|
||||
LOG.assertTrue(myMirror == null);
|
||||
myMirror = element;
|
||||
|
||||
PsiJavaCodeReferenceElement[] refs = getReferenceElements();
|
||||
PsiJavaCodeReferenceElement[] refMirrors = ((PsiReferenceList)SourceTreeToPsiMap.treeElementToPsi(myMirror)).getReferenceElements();
|
||||
LOG.assertTrue(refs.length == refMirrors.length);
|
||||
if (refs.length == refMirrors.length){
|
||||
for(int i = 0; i < refs.length; i++) {
|
||||
((ClsElementImpl)refs[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(refMirrors[i]));
|
||||
if (refs.length == refMirrors.length) {
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
((ClsElementImpl)refs[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(refMirrors[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(PsiElementVisitor visitor){
|
||||
public void accept(PsiElementVisitor visitor) {
|
||||
visitor.visitReferenceList(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ClsReferenceParametersListImpl extends ClsElementImpl implements Ps
|
||||
buf.append('<');
|
||||
for (int i = 0; i < myTypeElements.length; i++) {
|
||||
if (i > 0) buf.append(',');
|
||||
ClsTypeElementImpl typeElement = (ClsTypeElementImpl) myTypeElements[i];
|
||||
ClsTypeElementImpl typeElement = (ClsTypeElementImpl)myTypeElements[i];
|
||||
buf.append(typeElement.getMirrorText());
|
||||
}
|
||||
buf.append('>');
|
||||
@@ -40,9 +40,9 @@ public class ClsReferenceParametersListImpl extends ClsElementImpl implements Ps
|
||||
PsiTypeElement[] typeElements = getTypeParameterElements();
|
||||
PsiTypeElement[] typeMirrors = ((PsiReferenceParameterList)SourceTreeToPsiMap.treeElementToPsi(myMirror)).getTypeParameterElements();
|
||||
LOG.assertTrue(typeElements.length == typeMirrors.length);
|
||||
if (typeElements.length == typeMirrors.length){
|
||||
for(int i = 0; i < typeElements.length; i++) {
|
||||
((ClsElementImpl)typeElements[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(typeMirrors[i]));
|
||||
if (typeElements.length == typeMirrors.length) {
|
||||
for (int i = 0; i < typeElements.length; i++) {
|
||||
((ClsElementImpl)typeElements[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(typeMirrors[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,10 @@ public class ClsTypeParameterImpl extends ClsElementImpl implements PsiTypeParam
|
||||
private LightEmptyImplementsList myLightEmptyImplementsList;
|
||||
private final String mySignature;
|
||||
|
||||
public ClsTypeParameterImpl(PsiElement parent, CharacterIterator signature, int index, String parentSignatureAttribute) throws ClsFormatException {
|
||||
public ClsTypeParameterImpl(PsiElement parent,
|
||||
CharacterIterator signature,
|
||||
int index,
|
||||
String parentSignatureAttribute) throws ClsFormatException {
|
||||
myParent = parent;
|
||||
myIndex = index;
|
||||
StringBuffer name = new StringBuffer();
|
||||
@@ -58,7 +61,7 @@ public class ClsTypeParameterImpl extends ClsElementImpl implements PsiTypeParam
|
||||
}
|
||||
|
||||
myBoundsList = new ClsReferenceListImpl(this, bounds.toArray(
|
||||
new PsiJavaCodeReferenceElement[bounds.size()]), PsiKeyword.EXTENDS);
|
||||
new PsiJavaCodeReferenceElement[bounds.size()]), PsiKeyword.EXTENDS);
|
||||
final int endIndex = signature.getIndex();
|
||||
mySignature = parentSignatureAttribute.substring(signatureBeginIndex, endIndex);
|
||||
}
|
||||
@@ -141,7 +144,7 @@ public class ClsTypeParameterImpl extends ClsElementImpl implements PsiTypeParam
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean processDeclarations(PsiScopeProcessor processor, PsiSubstitutor substitutor, PsiElement lastParent, PsiElement place){
|
||||
public boolean processDeclarations(PsiScopeProcessor processor, PsiSubstitutor substitutor, PsiElement lastParent, PsiElement place) {
|
||||
return PsiClassImplUtil.processDeclarationsInClass(this, processor, substitutor, new HashSet(), lastParent, place);
|
||||
}
|
||||
|
||||
@@ -272,8 +275,8 @@ public class ClsTypeParameterImpl extends ClsElementImpl implements PsiTypeParam
|
||||
LOG.assertTrue(myMirror == null);
|
||||
myMirror = element;
|
||||
|
||||
PsiTypeParameter mirror = (PsiTypeParameter) SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
((ClsReferenceListImpl) getExtendsList()).setMirror(SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList()));
|
||||
PsiTypeParameter mirror = (PsiTypeParameter)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
((ClsReferenceListImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList()));
|
||||
}
|
||||
|
||||
public PsiElement[] getChildren() {
|
||||
@@ -287,7 +290,7 @@ public class ClsTypeParameterImpl extends ClsElementImpl implements PsiTypeParam
|
||||
public PsiTypeParameterListOwner getOwner() {
|
||||
if (myParent instanceof ClsTypeParametersListImpl) {
|
||||
final PsiElement parent = myParent.getParent();
|
||||
if (parent instanceof PsiTypeParameterListOwner) return (PsiTypeParameterListOwner) parent;
|
||||
if (parent instanceof PsiTypeParameterListOwner) return (PsiTypeParameterListOwner)parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -44,16 +44,16 @@ public class ClsTypeParametersListImpl extends ClsElementImpl implements PsiType
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public void setMirror(TreeElement element){
|
||||
public void setMirror(TreeElement element) {
|
||||
LOG.assertTrue(myMirror == null);
|
||||
myMirror = element;
|
||||
|
||||
PsiTypeParameter[] parms = getTypeParameters();
|
||||
PsiTypeParameter[] parmMirrors = ((PsiTypeParameterList)SourceTreeToPsiMap.treeElementToPsi(myMirror)).getTypeParameters();
|
||||
LOG.assertTrue(parms.length == parmMirrors.length);
|
||||
if (parms.length == parmMirrors.length){
|
||||
for(int i = 0; i < parms.length; i++) {
|
||||
((ClsElementImpl)parms[i]).setMirror(SourceTreeToPsiMap.psiElementToTree(parmMirrors[i]));
|
||||
if (parms.length == parmMirrors.length) {
|
||||
for (int i = 0; i < parms.length; i++) {
|
||||
((ClsElementImpl)parms[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(parmMirrors[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.psi.impl.PsiElementBase;
|
||||
import com.intellij.psi.impl.PsiManagerImpl;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.tree.ChangeUtil;
|
||||
import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
@@ -315,7 +316,8 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
text = template.getText(properties);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e);
|
||||
throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName),
|
||||
e);
|
||||
}
|
||||
|
||||
PsiElementFactory factory = myManager.getElementFactory();
|
||||
@@ -334,7 +336,9 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
}
|
||||
|
||||
private String getIncorrectTemplateMessage(String templateName) {
|
||||
String incorrectTemplateMessage = "Cannot create " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName) + " - incorrect " + templateName + " template.";
|
||||
String incorrectTemplateMessage =
|
||||
"Cannot create " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName) + " - incorrect " + templateName +
|
||||
" template.";
|
||||
return incorrectTemplateMessage;
|
||||
}
|
||||
|
||||
@@ -375,7 +379,7 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
VirtualFile existingFile = getVirtualFile().findChild(name);
|
||||
if (existingFile != null) {
|
||||
throw new IncorrectOperationException(
|
||||
"Cannot create package - file \"" + existingFile.getPresentableUrl() + "\" already exists.");
|
||||
"Cannot create package - file \"" + existingFile.getPresentableUrl() + "\" already exists.");
|
||||
}
|
||||
CheckUtil.checkWritable(this);
|
||||
}
|
||||
@@ -396,14 +400,14 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
public void checkCreateFile(String name) throws IncorrectOperationException {
|
||||
FileTypeManager fileTypeManager = FileTypeManager.getInstance();
|
||||
FileType type = fileTypeManager.getFileTypeByFileName(name);
|
||||
/* [dsl] now it is possible to create a Java file outside source path.
|
||||
if (type == FileType.JAVA) {
|
||||
if (getPackage() == null){
|
||||
throw new IncorrectOperationException("Cannot create java-files outside sourcepath");
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
/* [dsl] now it is possible to create a Java file outside source path.
|
||||
if (type == FileType.JAVA) {
|
||||
if (getPackage() == null){
|
||||
throw new IncorrectOperationException("Cannot create java-files outside sourcepath");
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
if (type == StdFileTypes.CLASS) {
|
||||
throw new IncorrectOperationException("Cannot create class-file");
|
||||
}
|
||||
@@ -411,7 +415,7 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
VirtualFile existingFile = getVirtualFile().findChild(name);
|
||||
if (existingFile != null) {
|
||||
throw new IncorrectOperationException(
|
||||
"Cannot create file - file \"" + existingFile.getPresentableUrl() + "\" already exists.");
|
||||
"Cannot create file - file \"" + existingFile.getPresentableUrl() + "\" already exists.");
|
||||
}
|
||||
CheckUtil.checkWritable(this);
|
||||
}
|
||||
@@ -460,9 +464,9 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
|
||||
PsiFile newFile = myManager.findFile(newVFile);
|
||||
if (newFile instanceof com.intellij.psi.impl.source.PsiFileImpl) {
|
||||
ChangeUtil.encodeInformation(SourceTreeToPsiMap.psiElementToTree(newFile));
|
||||
ChangeUtil.encodeInformation((TreeElement)SourceTreeToPsiMap.psiElementToTree(newFile));
|
||||
PsiUtil.updatePackageStatement(newFile);
|
||||
ChangeUtil.decodeInformation(SourceTreeToPsiMap.psiElementToTree(newFile));
|
||||
ChangeUtil.decodeInformation((TreeElement)SourceTreeToPsiMap.psiElementToTree(newFile));
|
||||
}
|
||||
|
||||
return newFile;
|
||||
@@ -503,7 +507,7 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
PsiDirectory dir = subpackages[i];
|
||||
if (dir.getName().equals(name)) {
|
||||
throw new IncorrectOperationException(
|
||||
"File " + dir.getVirtualFile().getPresentableUrl() + " already exists.");
|
||||
"File " + dir.getVirtualFile().getPresentableUrl() + " already exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,7 +518,7 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory {
|
||||
PsiFile file = files[i];
|
||||
if (file.getName().equals(name)) {
|
||||
throw new IncorrectOperationException(
|
||||
"File " + file.getVirtualFile().getPresentableUrl() + " already exists.");
|
||||
"File " + file.getVirtualFile().getPresentableUrl() + " already exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class LowLevelSearchUtil {
|
||||
|
||||
|
||||
private static boolean processElementsContainingWordInElement(PsiElementProcessorEx processor,
|
||||
TreeElement scope,
|
||||
ASTNode scope,
|
||||
StringSearcher searcher,
|
||||
TokenSet elementTypes,
|
||||
ProgressIndicator progress) {
|
||||
@@ -55,7 +55,7 @@ public class LowLevelSearchUtil {
|
||||
endOffset = startOffset + leaf.getTextLength();
|
||||
}
|
||||
else {
|
||||
char[] buffer = scope.textToCharArray();
|
||||
char[] buffer = ((CompositeElement)scope).textToCharArray();
|
||||
|
||||
// This is hack. Need to be fixed and optimized. current code's extremely slow
|
||||
// LeafElement leaf = SourceUtil.findLeafToFetchCharArrayRange(scope);
|
||||
@@ -97,38 +97,42 @@ public class LowLevelSearchUtil {
|
||||
private static boolean processChildren(ASTNode scope,
|
||||
StringSearcher searcher,
|
||||
PsiElementProcessorEx processor,
|
||||
TokenSet elementTypes, ProgressIndicator progress) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
ASTNode child = scope.getFirstChildNode();
|
||||
while (child != null) {
|
||||
if (child instanceof ChameleonElement) {
|
||||
LeafElement leaf = (LeafElement)child;
|
||||
if (leaf.searchWord(0, searcher) >= 0) {
|
||||
ASTNode next = child.getTreeNext();
|
||||
child = ChameleonTransforming.transform((ChameleonElement)child);
|
||||
if (child == null) {
|
||||
child = next;
|
||||
}
|
||||
continue;
|
||||
TokenSet elementTypes,
|
||||
ProgressIndicator progress) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
ASTNode child = scope.getFirstChildNode();
|
||||
while (child != null) {
|
||||
if (child instanceof ChameleonElement) {
|
||||
LeafElement leaf = (LeafElement)child;
|
||||
if (leaf.searchWord(0, searcher) >= 0) {
|
||||
ASTNode next = child.getTreeNext();
|
||||
child = ChameleonTransforming.transform((ChameleonElement)child);
|
||||
if (child == null) {
|
||||
child = next;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
child = child.getTreeNext();
|
||||
}
|
||||
child = child.getTreeNext();
|
||||
}
|
||||
}
|
||||
|
||||
ASTNode child = null;
|
||||
while (true) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
child = child != null ? child.getTreeNext() : scope.getFirstChildNode();
|
||||
while (child instanceof ChameleonElement) {
|
||||
child = child.getTreeNext();
|
||||
}
|
||||
if (child == null) break;
|
||||
}
|
||||
ASTNode child = null;
|
||||
while (true) {
|
||||
synchronized (PsiLock.LOCK) {
|
||||
child = child != null ? child.getTreeNext() : scope.getFirstChildNode();
|
||||
while (child instanceof ChameleonElement) {
|
||||
child = child.getTreeNext();
|
||||
}
|
||||
if (child == null) break;
|
||||
}
|
||||
|
||||
if (!processElementsContainingWordInElement(processor, (TreeElement)child, searcher, elementTypes, progress)) return false;
|
||||
}
|
||||
return true;
|
||||
if (!processElementsContainingWordInElement(processor, (TreeElement)child, searcher, elementTypes,
|
||||
progress)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int searchWord(char[] text, int startOffset, int endOffset, StringSearcher searcher) {
|
||||
@@ -139,7 +143,7 @@ public class LowLevelSearchUtil {
|
||||
if (index > startOffset) {
|
||||
char c = text[index - 1];
|
||||
if (Character.isJavaIdentifierPart(c) && c != '$') {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +151,7 @@ public class LowLevelSearchUtil {
|
||||
if (index + pattern.length() < endOffset) {
|
||||
char c = text[index + pattern.length()];
|
||||
if (Character.isJavaIdentifierPart(c) && c != '$') {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
|
||||
@@ -59,50 +59,50 @@ public class DummyHolder extends PsiFileImpl implements PsiImportHolder {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean importClass(PsiClass aClass){
|
||||
public boolean importClass(PsiClass aClass) {
|
||||
LOG.assertTrue(myContext == null);
|
||||
String className = aClass.getName();
|
||||
if (!myPseudoImports.containsKey(className)){
|
||||
if (!myPseudoImports.containsKey(className)) {
|
||||
myPseudoImports.put(className, aClass);
|
||||
myManager.nonPhysicalChange(); // to clear resolve caches!
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasImports(){
|
||||
public boolean hasImports() {
|
||||
return !myPseudoImports.isEmpty();
|
||||
}
|
||||
|
||||
public boolean processDeclarations(PsiScopeProcessor processor, PsiSubstitutor substitutor, PsiElement lastParent, PsiElement place) {
|
||||
if (myContext == null){ // process classes in lang&default package + "pseudo-imports"
|
||||
ElementClassHint classHint = (ElementClassHint)processor.getHint(ElementClassHint.class);
|
||||
if (classHint == null || classHint.shouldProcess(PsiClass.class)){
|
||||
final NameHint nameHint = (NameHint)processor.getHint(NameHint.class);
|
||||
if (myContext == null) { // process classes in lang&default package + "pseudo-imports"
|
||||
ElementClassHint classHint = processor.getHint(ElementClassHint.class);
|
||||
if (classHint == null || classHint.shouldProcess(PsiClass.class)) {
|
||||
final NameHint nameHint = processor.getHint(NameHint.class);
|
||||
final String name = nameHint != null ? nameHint.getName() : null;
|
||||
if (name != null){
|
||||
if (name != null) {
|
||||
PsiClass imported = myPseudoImports.get(name);
|
||||
if (imported != null){
|
||||
if (imported != null) {
|
||||
if (!processor.execute(imported, substitutor)) return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
Iterator<PsiClass> iter = myPseudoImports.values().iterator();
|
||||
while(iter.hasNext()){
|
||||
while (iter.hasNext()) {
|
||||
PsiClass aClass = iter.next();
|
||||
if (!processor.execute(aClass, substitutor)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
PsiPackage langPackage = getManager().findPackage("java.lang");
|
||||
if (langPackage != null){
|
||||
if (langPackage != null) {
|
||||
if (!langPackage.processDeclarations(processor, substitutor, null, place)) return false;
|
||||
}
|
||||
|
||||
PsiPackage defaultPackage = getManager().findPackage("");
|
||||
if (defaultPackage != null){
|
||||
if (defaultPackage != null) {
|
||||
if (!defaultPackage.processDeclarations(processor, substitutor, null, place)) return false;
|
||||
}
|
||||
}
|
||||
@@ -120,21 +120,21 @@ public class DummyHolder extends PsiFileImpl implements PsiImportHolder {
|
||||
|
||||
public boolean isSamePackage(PsiElement other) {
|
||||
if (other instanceof DummyHolder) {
|
||||
final PsiElement otherContext = ((DummyHolder) other).myContext;
|
||||
final PsiElement otherContext = ((DummyHolder)other).myContext;
|
||||
return (myContext == null && otherContext == null) || myContext.getManager().arePackagesTheSame(myContext, otherContext);
|
||||
}
|
||||
if (other instanceof PsiJavaFile) {
|
||||
if (myContext != null) return myContext.getManager().arePackagesTheSame(myContext, other);
|
||||
final String packageName = ((PsiJavaFile) other).getPackageName();
|
||||
final String packageName = ((PsiJavaFile)other).getPackageName();
|
||||
return "".equals(packageName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public FileType getFileType() {
|
||||
if (myContext!=null) {
|
||||
if (myContext != null) {
|
||||
PsiFile containingFile = myContext.getContainingFile();
|
||||
if (containingFile!=null) return containingFile.getFileType();
|
||||
if (containingFile != null) return containingFile.getFileType();
|
||||
}
|
||||
return StdFileTypes.JAVA;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class DummyHolder extends PsiFileImpl implements PsiImportHolder {
|
||||
|
||||
public FileElement getTreeElement() {
|
||||
final FileElement holderElement = super.getTreeElement();
|
||||
if(myTable != null) holderElement.setCharTable(myTable);
|
||||
if (myTable != null) holderElement.setCharTable(myTable);
|
||||
return holderElement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,15 +49,17 @@ public class PsiEnumConstantImpl extends NonSlaveRepositoryPsiElement implements
|
||||
public PsiEnumConstantInitializer getInitializingClass() {
|
||||
if (myCachedInitializingClass == null) {
|
||||
if (getTreeElement() != null) {
|
||||
myCachedInitializingClass = Ref.create((PsiEnumConstantInitializer)getTreeElement().findChildByRoleAsPsiElement(ChildRole.ANONYMOUS_CLASS));
|
||||
myCachedInitializingClass = Ref.create((PsiEnumConstantInitializer)getTreeElement()
|
||||
.findChildByRoleAsPsiElement(ChildRole.ANONYMOUS_CLASS));
|
||||
}
|
||||
else {
|
||||
long initializingClass = getRepositoryManager().getFieldView().getEnumConstantInitializer(getRepositoryId());
|
||||
if (initializingClass < 0) {
|
||||
myCachedInitializingClass = Ref.create((PsiEnumConstantInitializer)null);
|
||||
myCachedInitializingClass = Ref.create(null);
|
||||
}
|
||||
else {
|
||||
PsiEnumConstantInitializer repoElement = (PsiEnumConstantInitializer)getRepositoryElementsManager().findOrCreatePsiElementById(initializingClass);
|
||||
PsiEnumConstantInitializer repoElement = (PsiEnumConstantInitializer)getRepositoryElementsManager()
|
||||
.findOrCreatePsiElementById(initializingClass);
|
||||
myCachedInitializingClass = Ref.create(repoElement);
|
||||
}
|
||||
}
|
||||
@@ -124,7 +126,7 @@ public class PsiEnumConstantImpl extends NonSlaveRepositoryPsiElement implements
|
||||
return true;
|
||||
}
|
||||
|
||||
public void normalizeDeclaration() throws IncorrectOperationException {}
|
||||
public void normalizeDeclaration() throws IncorrectOperationException { }
|
||||
|
||||
public Object computeConstantValue() {
|
||||
return null;
|
||||
@@ -133,14 +135,16 @@ public class PsiEnumConstantImpl extends NonSlaveRepositoryPsiElement implements
|
||||
public PsiMethod resolveMethod() {
|
||||
PsiClass containingClass = getContainingClass();
|
||||
LOG.assertTrue(containingClass != null);
|
||||
ResolveResult resolveResult = getManager().getResolveHelper().resolveConstructor(getManager().getElementFactory().createType(containingClass), getArgumentList(), this);
|
||||
ResolveResult resolveResult = getManager().getResolveHelper()
|
||||
.resolveConstructor(getManager().getElementFactory().createType(containingClass), getArgumentList(), this);
|
||||
return (PsiMethod)resolveResult.getElement();
|
||||
}
|
||||
|
||||
public ResolveResult resolveMethodGenerics() {
|
||||
PsiClass containingClass = getContainingClass();
|
||||
LOG.assertTrue(containingClass != null);
|
||||
return getManager().getResolveHelper().resolveConstructor(getManager().getElementFactory().createType(containingClass), getArgumentList(), this);
|
||||
return getManager().getResolveHelper()
|
||||
.resolveConstructor(getManager().getElementFactory().createType(containingClass), getArgumentList(), this);
|
||||
}
|
||||
|
||||
public PsiIdentifier getNameIdentifier() {
|
||||
@@ -264,9 +268,9 @@ public class PsiEnumConstantImpl extends NonSlaveRepositoryPsiElement implements
|
||||
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
return element instanceof PsiMethod
|
||||
&& ((PsiMethod)element).isConstructor()
|
||||
&& ((PsiMethod)element).getContainingClass() == getContainingClass()
|
||||
&& getManager().areElementsEquivalent(resolve(), element);
|
||||
&& ((PsiMethod)element).isConstructor()
|
||||
&& ((PsiMethod)element).getContainingClass() == getContainingClass()
|
||||
&& getManager().areElementsEquivalent(resolve(), element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public abstract class PsiFileImpl extends NonSlaveRepositoryPsiElement implement
|
||||
}
|
||||
|
||||
public void prepareToRepositoryIdInvalidation() {
|
||||
if (isRepositoryIdInitialized()){
|
||||
if (isRepositoryIdInitialized()) {
|
||||
super.prepareToRepositoryIdInvalidation();
|
||||
}
|
||||
}
|
||||
@@ -132,33 +132,34 @@ public abstract class PsiFileImpl extends NonSlaveRepositoryPsiElement implement
|
||||
}
|
||||
|
||||
public FileElement loadTreeElement() {
|
||||
// load document outside lock for better performance
|
||||
if (!isPhysical()) {
|
||||
return getTreeElement();
|
||||
// load document outside lock for better performance
|
||||
if (!isPhysical()) {
|
||||
return getTreeElement();
|
||||
}
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(myFile);
|
||||
|
||||
synchronized (PsiLock.LOCK) {
|
||||
FileElement treeElement = getTreeElement();
|
||||
if (treeElement != null) return treeElement;
|
||||
if (myFile != null && myManager.isAssertOnFileLoading(myFile)) {
|
||||
LOG.error("File text loaded " + myFile.getPresentableUrl());
|
||||
}
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(myFile);
|
||||
treeElement = (FileElement)Factory.createCompositeElement(myElementType);
|
||||
treeElement.setDocument(document);
|
||||
final CharSequence docText = document.getCharsSequence();
|
||||
char[] chars = CharArrayUtil.fromSequence(docText);
|
||||
|
||||
synchronized (PsiLock.LOCK) {
|
||||
FileElement treeElement = getTreeElement();
|
||||
if (treeElement != null) return treeElement;
|
||||
if (myFile != null && myManager.isAssertOnFileLoading(myFile)) {
|
||||
LOG.error("File text loaded " + myFile.getPresentableUrl());
|
||||
}
|
||||
treeElement = (FileElement)Factory.createCompositeElement(myElementType);
|
||||
treeElement.setDocument(document);
|
||||
final CharSequence docText = ((DocumentEx)document).getCharsSequence();
|
||||
char[] chars = CharArrayUtil.fromSequence(docText);
|
||||
|
||||
TreeElement contentElement = Factory.createLeafElement(myContentElementType, chars, 0, docText.length(), -1, treeElement.getCharTable());
|
||||
TreeUtil.addChildren(treeElement, contentElement);
|
||||
setTreeElement(treeElement);
|
||||
treeElement.setPsiElement(this);
|
||||
TreeElement contentElement =
|
||||
Factory.createLeafElement(myContentElementType, chars, 0, docText.length(), -1, treeElement.getCharTable());
|
||||
TreeUtil.addChildren(treeElement, contentElement);
|
||||
setTreeElement(treeElement);
|
||||
treeElement.setPsiElement(this);
|
||||
((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(myManager.getProject())).contentsLoaded(this);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Loaded text for file " + myFile.getPresentableUrl());
|
||||
}
|
||||
return treeElement;
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Loaded text for file " + myFile.getPresentableUrl());
|
||||
}
|
||||
return treeElement;
|
||||
}
|
||||
}
|
||||
|
||||
public PsiJavaCodeReferenceElement findImportReferenceTo(PsiClass aClass) {
|
||||
|
||||
@@ -49,9 +49,9 @@ public class PsiImportListImpl extends SlaveRepositoryPsiElement implements PsiI
|
||||
public void setOwner(SrcRepositoryPsiElement owner) {
|
||||
super.setOwner(owner);
|
||||
|
||||
if (myOwner == null){
|
||||
if (myRepositoryImports != null){
|
||||
for(int i = 0; i < myRepositoryImports.length; i++){
|
||||
if (myOwner == null) {
|
||||
if (myRepositoryImports != null) {
|
||||
for (int i = 0; i < myRepositoryImports.length; i++) {
|
||||
PsiImportStatementBaseImpl anImport = myRepositoryImports[i];
|
||||
anImport.setOwnerAndIndex(this, i);
|
||||
}
|
||||
@@ -60,8 +60,9 @@ public class PsiImportListImpl extends SlaveRepositoryPsiElement implements PsiI
|
||||
myRepositoryClassImports = null;
|
||||
myRepositoryStaticImports = null;
|
||||
}
|
||||
else{
|
||||
myRepositoryImports = (PsiImportStatementBaseImpl[])bindIndexedSlaves(IMPORT_STATEMENT_BASE_BIT_SET, IMPORT_STATEMENT_BASE_IMPL_ARRAY_CONSTRUCTOR);
|
||||
else {
|
||||
myRepositoryImports = (PsiImportStatementBaseImpl[])bindIndexedSlaves(IMPORT_STATEMENT_BASE_BIT_SET,
|
||||
IMPORT_STATEMENT_BASE_IMPL_ARRAY_CONSTRUCTOR);
|
||||
myRepositoryClassImports = null;
|
||||
myRepositoryStaticImports = null;
|
||||
}
|
||||
@@ -74,43 +75,45 @@ public class PsiImportListImpl extends SlaveRepositoryPsiElement implements PsiI
|
||||
super.subtreeChanged();
|
||||
}
|
||||
|
||||
public PsiImportStatement[] getImportStatements(){
|
||||
if (myOwner != null){
|
||||
if (myRepositoryClassImports == null){
|
||||
public PsiImportStatement[] getImportStatements() {
|
||||
if (myOwner != null) {
|
||||
if (myRepositoryClassImports == null) {
|
||||
calcRepositoryImports();
|
||||
final ArrayList<PsiImportStatementImpl> importStatements = new ArrayList<PsiImportStatementImpl>();
|
||||
for (int i = 0; i < myRepositoryImports.length; i++) {
|
||||
PsiImportStatementBaseImpl repositoryImport = myRepositoryImports[i];
|
||||
if (repositoryImport instanceof PsiImportStatementImpl) {
|
||||
importStatements.add((PsiImportStatementImpl) repositoryImport);
|
||||
importStatements.add((PsiImportStatementImpl)repositoryImport);
|
||||
}
|
||||
}
|
||||
myRepositoryClassImports = (PsiImportStatementImpl[])importStatements.toArray(new PsiImportStatementImpl[importStatements.size()]);
|
||||
myRepositoryClassImports = importStatements.toArray(new PsiImportStatementImpl[importStatements.size()]);
|
||||
}
|
||||
return myRepositoryClassImports;
|
||||
}
|
||||
else{
|
||||
return (PsiImportStatement[])calcTreeElement().getChildrenAsPsiElements(IMPORT_STATEMENT_BIT_SET, PSI_IMPORT_STATEMENT_ARRAY_CONSTRUCTOR);
|
||||
else {
|
||||
return (PsiImportStatement[])calcTreeElement()
|
||||
.getChildrenAsPsiElements(IMPORT_STATEMENT_BIT_SET, PSI_IMPORT_STATEMENT_ARRAY_CONSTRUCTOR);
|
||||
}
|
||||
}
|
||||
|
||||
public PsiImportStaticStatement[] getImportStaticStatements() {
|
||||
if (myOwner != null){
|
||||
if (myRepositoryStaticImports == null){
|
||||
if (myOwner != null) {
|
||||
if (myRepositoryStaticImports == null) {
|
||||
calcRepositoryImports();
|
||||
final ArrayList<PsiImportStaticStatementImpl> importStatements = new ArrayList<PsiImportStaticStatementImpl>();
|
||||
for (int i = 0; i < myRepositoryImports.length; i++) {
|
||||
PsiImportStatementBaseImpl repositoryImport = myRepositoryImports[i];
|
||||
if (repositoryImport instanceof PsiImportStaticStatementImpl) {
|
||||
importStatements.add((PsiImportStaticStatementImpl) repositoryImport);
|
||||
importStatements.add((PsiImportStaticStatementImpl)repositoryImport);
|
||||
}
|
||||
}
|
||||
myRepositoryStaticImports = (PsiImportStaticStatementImpl[])importStatements.toArray(new PsiImportStaticStatementImpl[importStatements.size()]);
|
||||
myRepositoryStaticImports = importStatements.toArray(new PsiImportStaticStatementImpl[importStatements.size()]);
|
||||
}
|
||||
return myRepositoryStaticImports;
|
||||
}
|
||||
else{
|
||||
return (PsiImportStaticStatement[])calcTreeElement().getChildrenAsPsiElements(IMPORT_STATIC_STATEMENT_BIT_SET, PSI_IMPORT_STATIC_STATEMENT_ARRAY_CONSTRUCTOR);
|
||||
else {
|
||||
return (PsiImportStaticStatement[])calcTreeElement()
|
||||
.getChildrenAsPsiElements(IMPORT_STATIC_STATEMENT_BIT_SET, PSI_IMPORT_STATIC_STATEMENT_ARRAY_CONSTRUCTOR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -121,23 +124,24 @@ public class PsiImportListImpl extends SlaveRepositoryPsiElement implements PsiI
|
||||
return myRepositoryImports;
|
||||
}
|
||||
else {
|
||||
return (PsiImportStatementBase[])calcTreeElement().getChildrenAsPsiElements(IMPORT_STATEMENT_BASE_BIT_SET, PSI_IMPORT_STATEMENT_BASE_ARRAY_CONSTRUCTOR);
|
||||
return (PsiImportStatementBase[])calcTreeElement()
|
||||
.getChildrenAsPsiElements(IMPORT_STATEMENT_BASE_BIT_SET, PSI_IMPORT_STATEMENT_BASE_ARRAY_CONSTRUCTOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void calcRepositoryImports() {
|
||||
if (myRepositoryImports == null){
|
||||
if (myRepositoryImports == null) {
|
||||
ASTNode treeElement = getTreeElement();
|
||||
if (treeElement != null){
|
||||
if (treeElement != null) {
|
||||
final ASTNode[] imports = treeElement.getChildren(IMPORT_STATEMENT_BASE_BIT_SET);
|
||||
int count = imports.length;
|
||||
myRepositoryImports = new PsiImportStatementBaseImpl[count];
|
||||
for(int i = 0; i < myRepositoryImports.length; i++){
|
||||
for (int i = 0; i < myRepositoryImports.length; i++) {
|
||||
final IElementType type = imports[i].getElementType();
|
||||
if (type == IMPORT_STATEMENT) {
|
||||
myRepositoryImports[i] = new PsiImportStatementImpl(myManager, this, i);
|
||||
}
|
||||
else if (imports[i].getElementType() == IMPORT_STATIC_STATEMENT){
|
||||
else if (imports[i].getElementType() == IMPORT_STATIC_STATEMENT) {
|
||||
myRepositoryImports[i] = new PsiImportStaticStatementImpl(myManager, this, i);
|
||||
}
|
||||
else {
|
||||
@@ -145,12 +149,12 @@ public class PsiImportListImpl extends SlaveRepositoryPsiElement implements PsiI
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
final FileView fileView = getRepositoryManager().getFileView();
|
||||
final long repositoryId = getRepositoryId();
|
||||
int count = fileView.getImportStatementsCount(repositoryId);
|
||||
myRepositoryImports = new PsiImportStatementBaseImpl[count];
|
||||
for(int i = 0; i < myRepositoryImports.length; i++){
|
||||
for (int i = 0; i < myRepositoryImports.length; i++) {
|
||||
if (fileView.isImportStatic(repositoryId, i)) {
|
||||
myRepositoryImports[i] = new PsiImportStaticStatementImpl(myManager, this, i);
|
||||
}
|
||||
@@ -179,19 +183,19 @@ public class PsiImportListImpl extends SlaveRepositoryPsiElement implements PsiI
|
||||
}
|
||||
|
||||
private void initializeMaps() {
|
||||
if (myClassNameToImportMap == null){
|
||||
if (myClassNameToImportMap == null) {
|
||||
myClassNameToImportMap = new HashMap();
|
||||
myPackageNameToImportMap = new HashMap();
|
||||
myNameToSingleImportMap = new HashMap();
|
||||
PsiImportStatement[] imports = getImportStatements();
|
||||
for(int i = 0; i < imports.length; i++){
|
||||
for (int i = 0; i < imports.length; i++) {
|
||||
PsiImportStatement anImport = imports[i];
|
||||
String qName = anImport.getQualifiedName();
|
||||
if (qName == null) continue;
|
||||
if (anImport.isOnDemand()){
|
||||
if (anImport.isOnDemand()) {
|
||||
myPackageNameToImportMap.put(qName, anImport);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
myClassNameToImportMap.put(qName, anImport);
|
||||
myNameToSingleImportMap.put(anImport.getImportReference().getReferenceName(), anImport);
|
||||
}
|
||||
@@ -210,11 +214,11 @@ public class PsiImportListImpl extends SlaveRepositoryPsiElement implements PsiI
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(PsiElementVisitor visitor){
|
||||
public void accept(PsiElementVisitor visitor) {
|
||||
visitor.visitImportList(this);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "PsiImportList";
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,24 +11,24 @@ import com.intellij.lang.ASTNode;
|
||||
public class SourceTreeToPsiMap {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.SourceTreeToPsiMap");
|
||||
|
||||
public static PsiElement treeElementToPsi(ASTNode element){
|
||||
public static PsiElement treeElementToPsi(ASTNode element) {
|
||||
ProgressManager.getInstance().checkCanceled();
|
||||
|
||||
if (element == null) return null;
|
||||
|
||||
if (element instanceof PsiElement){
|
||||
if (element instanceof PsiElement) {
|
||||
return (PsiElement)element;
|
||||
}
|
||||
else if (element instanceof RepositoryTreeElement){
|
||||
else if (element instanceof RepositoryTreeElement) {
|
||||
return RepositoryElementsManager.getOrFindPsiElement((RepositoryTreeElement)element);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
LOG.error("Not PsiElement:" + element);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeElement psiElementToTree(PsiElement psiElement){
|
||||
public static ASTNode psiElementToTree(PsiElement psiElement) {
|
||||
ProgressManager.getInstance().checkCanceled();
|
||||
|
||||
if (psiElement == null) return null;
|
||||
@@ -36,16 +36,16 @@ public class SourceTreeToPsiMap {
|
||||
if (psiElement instanceof TreeElement) {
|
||||
return (TreeElement)psiElement;
|
||||
}
|
||||
else if (psiElement instanceof SrcRepositoryPsiElement){
|
||||
else if (psiElement instanceof SrcRepositoryPsiElement) {
|
||||
return RepositoryElementsManager.getOrFindTreeElement((SrcRepositoryPsiElement)psiElement);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
LOG.error("Not TreeElement:" + psiElement);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasTreeElement(PsiElement psiElement){
|
||||
public static boolean hasTreeElement(PsiElement psiElement) {
|
||||
return psiElement instanceof TreeElement || psiElement instanceof SrcRepositoryPsiElement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,11 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
|
||||
public void initComponent() { }
|
||||
|
||||
public void disposeComponent() {}
|
||||
public void disposeComponent() { }
|
||||
|
||||
public void projectOpened() {}
|
||||
public void projectOpened() { }
|
||||
|
||||
public void projectClosed() {}
|
||||
public void projectClosed() { }
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
@@ -73,7 +73,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
}
|
||||
Helper helper = new Helper(fileType, myProject);
|
||||
final PsiElement formatted = SourceTreeToPsiMap.treeElementToPsi(
|
||||
new CodeFormatterFacade(getSettings(), helper).process(treeElement,-1));
|
||||
new CodeFormatterFacade(getSettings(), helper).process(treeElement, -1));
|
||||
return new BraceEnforcer(getSettings()).process(formatted);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
boolean addImports = (flags & DO_NOT_ADD_IMPORTS) == 0;
|
||||
boolean uncompleteCode = (flags & UNCOMPLETE_CODE) != 0;
|
||||
return SourceTreeToPsiMap.treeElementToPsi(
|
||||
new ReferenceAdjuster(getSettings()).process(SourceTreeToPsiMap.psiElementToTree(element), addImports,
|
||||
new ReferenceAdjuster(getSettings()).process((TreeElement)SourceTreeToPsiMap.psiElementToTree(element), addImports,
|
||||
uncompleteCode));
|
||||
}
|
||||
|
||||
@@ -115,13 +115,13 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
throws IncorrectOperationException {
|
||||
CheckUtil.checkWritable(element);
|
||||
if (!SourceTreeToPsiMap.hasTreeElement(element)) return;
|
||||
new ReferenceAdjuster(getSettings()).processRange(SourceTreeToPsiMap.psiElementToTree(element), startOffset,
|
||||
new ReferenceAdjuster(getSettings()).processRange((TreeElement)SourceTreeToPsiMap.psiElementToTree(element), startOffset,
|
||||
endOffset);
|
||||
}
|
||||
|
||||
public PsiElement qualifyClassReferences(PsiElement element) {
|
||||
return SourceTreeToPsiMap.treeElementToPsi(
|
||||
new ReferenceAdjuster(getSettings(), true, true).process(SourceTreeToPsiMap.psiElementToTree(element), false,
|
||||
new ReferenceAdjuster(getSettings(), true, true).process((TreeElement)SourceTreeToPsiMap.psiElementToTree(element), false,
|
||||
false));
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
if (file instanceof PsiJavaFile) {
|
||||
PsiImportList newList = prepareOptimizeImportsResult(file);
|
||||
if (newList != null) {
|
||||
((PsiJavaFile)file).getImportList().replace(newList);
|
||||
((PsiJavaFile)file).getImportList().replace(newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
return new ImportHelper(getSettings()).addImport(file, refClass);
|
||||
}
|
||||
|
||||
public int findEntryIndex(PsiImportStatementBase statement){
|
||||
public int findEntryIndex(PsiImportStatementBase statement) {
|
||||
return new ImportHelper(getSettings()).findEntryIndex(statement);
|
||||
}
|
||||
|
||||
@@ -157,11 +157,11 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
if (!SourceTreeToPsiMap.hasTreeElement(file)) return offset;
|
||||
|
||||
final CharTable charTable = ((FileElement)SourceTreeToPsiMap.psiElementToTree(file)).getCharTable();
|
||||
TreeElement element = SourceTreeToPsiMap.psiElementToTree(file.findElementAt(offset));
|
||||
ASTNode element = SourceTreeToPsiMap.psiElementToTree(file.findElementAt(offset));
|
||||
if (element == null) return offset;
|
||||
if (element.getElementType() == ElementType.WHITE_SPACE) {
|
||||
int spaceStart = element.getTextRange().getStartOffset();
|
||||
offset = spaceStart + CharArrayUtil.shiftForward(element.textToCharArray(), offset - spaceStart, " \t");
|
||||
offset = spaceStart + CharArrayUtil.shiftForward(((TreeElement)element).textToCharArray(), offset - spaceStart, " \t");
|
||||
element = SourceTreeToPsiMap.psiElementToTree(file.findElementAt(offset));
|
||||
}
|
||||
|
||||
@@ -169,48 +169,48 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
Helper helper = new Helper(fileType, myProject);
|
||||
|
||||
CheckUncompleteCode:
|
||||
if (element != null && canTryXXX) {
|
||||
ASTNode space;
|
||||
if (element.getElementType() == ElementType.WHITE_SPACE) {
|
||||
space = element;
|
||||
}
|
||||
else {
|
||||
space = SourceTreeToPsiMap.psiElementToTree(file.findElementAt(offset - 1));
|
||||
}
|
||||
if (element != null && canTryXXX) {
|
||||
ASTNode space;
|
||||
if (element.getElementType() == ElementType.WHITE_SPACE) {
|
||||
space = element;
|
||||
}
|
||||
else {
|
||||
space = SourceTreeToPsiMap.psiElementToTree(file.findElementAt(offset - 1));
|
||||
}
|
||||
|
||||
int spaceStart;
|
||||
if (space != null && space.getElementType() == ElementType.WHITE_SPACE) {
|
||||
spaceStart = space.getStartOffset();
|
||||
}
|
||||
else {
|
||||
spaceStart = element.getTextRange().getStartOffset();
|
||||
}
|
||||
int spaceStart;
|
||||
if (space != null && space.getElementType() == ElementType.WHITE_SPACE) {
|
||||
spaceStart = space.getStartOffset();
|
||||
}
|
||||
else {
|
||||
spaceStart = element.getTextRange().getStartOffset();
|
||||
}
|
||||
|
||||
if (spaceStart > 0) {
|
||||
ASTNode leafBeforeSpace = SourceTreeToPsiMap.psiElementToTree(file.findElementAt(spaceStart - 1));
|
||||
if (leafBeforeSpace.getTreeNext() != null && leafBeforeSpace.getTreeNext().getElementType() == ElementType.ERROR_ELEMENT) {
|
||||
PsiErrorElement errorElement = (PsiErrorElement)SourceTreeToPsiMap.treeElementToPsi(leafBeforeSpace.getTreeNext());
|
||||
Project project = file.getProject();
|
||||
BlockSupport blockSupport = project.getComponent(BlockSupport.class);
|
||||
String dummyString = "xxx";
|
||||
if ("';' expected".equals(errorElement.getErrorDescription())) { //TODO: change!!!
|
||||
break CheckUncompleteCode;
|
||||
}
|
||||
|
||||
blockSupport.reparseRange(file, offset, offset, dummyString);
|
||||
int newOffset = adjustLineIndent(file, offset, false);
|
||||
blockSupport.reparseRange(file, newOffset, newOffset + dummyString.length(), "");
|
||||
return newOffset;
|
||||
if (spaceStart > 0) {
|
||||
ASTNode leafBeforeSpace = SourceTreeToPsiMap.psiElementToTree(file.findElementAt(spaceStart - 1));
|
||||
if (leafBeforeSpace.getTreeNext() != null && leafBeforeSpace.getTreeNext().getElementType() == ElementType.ERROR_ELEMENT) {
|
||||
PsiErrorElement errorElement = (PsiErrorElement)SourceTreeToPsiMap.treeElementToPsi(leafBeforeSpace.getTreeNext());
|
||||
Project project = file.getProject();
|
||||
BlockSupport blockSupport = project.getComponent(BlockSupport.class);
|
||||
String dummyString = "xxx";
|
||||
if ("';' expected".equals(errorElement.getErrorDescription())) { //TODO: change!!!
|
||||
break CheckUncompleteCode;
|
||||
}
|
||||
|
||||
blockSupport.reparseRange(file, offset, offset, dummyString);
|
||||
int newOffset = adjustLineIndent(file, offset, false);
|
||||
blockSupport.reparseRange(file, newOffset, newOffset + dummyString.length(), "");
|
||||
return newOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int start = -1; // start of the line
|
||||
int end = -1; // end of whitespace at the beginning of the line
|
||||
if (element != null && element.getElementType() == ElementType.WHITE_SPACE) { // optimization to not fetch file.textToCharArray()
|
||||
TextRange range = element.getTextRange();
|
||||
int localOffset = offset - range.getStartOffset();
|
||||
char[] chars = element.textToCharArray();
|
||||
char[] chars = ((TreeElement)element).textToCharArray();
|
||||
start = CharArrayUtil.shiftBackward(chars, localOffset - 1, " \t");
|
||||
if (start > 0 && chars[start] != '\n' && chars[start] != '\r') return offset;
|
||||
start++;
|
||||
@@ -243,13 +243,13 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
ASTNode parent;
|
||||
ASTNode newSpace;
|
||||
try {
|
||||
((PsiFileImpl)file).setIsPhysicalExplicitly(false);
|
||||
((PsiFileImpl)file).setIsPhysicalExplicitly(false);
|
||||
|
||||
int spaceStart = element.getTextRange().getStartOffset();
|
||||
parent = element.getTreeParent();
|
||||
ASTNode prev = element.getTreePrev();
|
||||
ASTNode next = element.getTreeNext();
|
||||
ASTNode space1 = Helper.splitSpaceElement(element, end - spaceStart, charTable);
|
||||
ASTNode space1 = Helper.splitSpaceElement((TreeElement)element, end - spaceStart, charTable);
|
||||
ASTNode tempElement = Factory.createSingleLeafElement(
|
||||
ElementType.NEW_LINE_INDENT, "###".toCharArray(), 0,
|
||||
"###".length(), charTable, null);
|
||||
@@ -264,7 +264,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
parent.replaceChild(newSpace, element);
|
||||
}
|
||||
finally {
|
||||
((PsiFileImpl)file).setIsPhysicalExplicitly(physical);
|
||||
((PsiFileImpl)file).setIsPhysicalExplicitly(physical);
|
||||
}
|
||||
|
||||
parent.replaceChild(element, newSpace);
|
||||
@@ -283,7 +283,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
if (element.getTreeParent() == null) break;
|
||||
element = element.getTreeParent();
|
||||
}
|
||||
element = (TreeElement)new IndentAdjusterFacade(getSettings(), helper).adjustFirstLineIndent(element);
|
||||
element = new IndentAdjusterFacade(getSettings(), helper).adjustFirstLineIndent(element);
|
||||
return element.getTextRange().getStartOffset();
|
||||
}
|
||||
else {
|
||||
@@ -305,7 +305,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
String newElementText = elementText.substring(0, start - elementStart) + indentSpace +
|
||||
elementText.substring(end - elementStart);
|
||||
LeafElement newElement = Factory.createSingleLeafElement(element.getElementType(), newElementText.toCharArray(), 0,
|
||||
newElementText.length(), null, element.getManager());
|
||||
newElementText.length(), null, ((TreeElement)element).getManager());
|
||||
element.getTreeParent().replaceChild(element, newElement);
|
||||
return start + indentSpace.length();
|
||||
}
|
||||
@@ -338,7 +338,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
final CharTable charTable = ((FileElement)SourceTreeToPsiMap.psiElementToTree(file)).getCharTable();
|
||||
PsiElement elementAt = file.findElementAt(offset);
|
||||
if (elementAt == null) return null;
|
||||
TreeElement element = SourceTreeToPsiMap.psiElementToTree(elementAt);
|
||||
ASTNode element = SourceTreeToPsiMap.psiElementToTree(elementAt);
|
||||
ASTNode parent = element.getTreeParent();
|
||||
int elementStart = element.getTextRange().getStartOffset();
|
||||
if (element.getElementType() != ElementType.WHITE_SPACE) {
|
||||
@@ -351,7 +351,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
return null;
|
||||
}
|
||||
|
||||
ASTNode space1 = Helper.splitSpaceElement(element, offset - elementStart, charTable);
|
||||
ASTNode space1 = Helper.splitSpaceElement((TreeElement)element, offset - elementStart, charTable);
|
||||
ASTNode marker = Factory.createSingleLeafElement(ElementType.NEW_LINE_INDENT, "###".toCharArray(), 0, "###".length(), charTable, null);
|
||||
parent.addChild(marker, space1.getTreeNext());
|
||||
return SourceTreeToPsiMap.treeElementToPsi(marker);
|
||||
@@ -553,7 +553,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
final PsiSubstitutor substitutor;
|
||||
if (!manager.areElementsEquivalent(resolved.getElement(), collectionClass)) {
|
||||
substitutor = TypeConversionUtil.getClassSubstitutor(collectionClass, resolved.getElement(),
|
||||
PsiSubstitutor.EMPTY);
|
||||
PsiSubstitutor.EMPTY);
|
||||
}
|
||||
else {
|
||||
substitutor = PsiSubstitutor.EMPTY;
|
||||
@@ -569,7 +569,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
PsiClass componentClass = ((PsiClassType)componentTypeParameter).resolve();
|
||||
if (componentClass instanceof PsiTypeParameter) {
|
||||
if (collectionClass.getManager().areElementsEquivalent(((PsiTypeParameter)componentClass).getOwner(),
|
||||
resolved.getElement())) {
|
||||
resolved.getElement())) {
|
||||
PsiType componentType = resolved.getSubstitutor().substitute((PsiTypeParameter)componentClass);
|
||||
if (componentType == null) return;
|
||||
String typeName = normalizeTypeName(getTypeName(componentType));
|
||||
@@ -836,7 +836,7 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
if (Character.isLowerCase(c)) return variableNameToPropertyNameInner(name, variableKind);
|
||||
|
||||
buffer.append(Character.toLowerCase(c));
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
if (i < name.length()) {
|
||||
@@ -986,26 +986,27 @@ public class CodeStyleManagerImpl extends CodeStyleManagerEx implements ProjectC
|
||||
if (PsiUtil.isVariableNameUnique(name, place)) {
|
||||
if (scope instanceof PsiCodeBlock) {
|
||||
final String name1 = name;
|
||||
class Cancel extends RuntimeException {}
|
||||
class Cancel extends RuntimeException {
|
||||
}
|
||||
try {
|
||||
scope.accept(new PsiRecursiveElementVisitor() {
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
visitReferenceElement(expression);
|
||||
}
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
visitReferenceElement(expression);
|
||||
}
|
||||
|
||||
public void visitClass(PsiClass aClass) {
|
||||
public void visitClass(PsiClass aClass) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void visitVariable(PsiVariable variable) {
|
||||
if (name1.equals(variable.getName())) {
|
||||
throw new Cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
public void visitVariable(PsiVariable variable) {
|
||||
if (name1.equals(variable.getName())) {
|
||||
throw new Cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Cancel e) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
|
||||
@@ -33,50 +33,50 @@ class ReferenceAdjuster implements Constants {
|
||||
|
||||
public TreeElement process(TreeElement element, boolean addImports, boolean uncompleteCode) {
|
||||
IElementType elementType = element.getElementType();
|
||||
if (elementType == JAVA_CODE_REFERENCE || elementType == REFERENCE_EXPRESSION){
|
||||
if (elementType == JAVA_CODE_REFERENCE || elementType == REFERENCE_EXPRESSION) {
|
||||
if (elementType == JAVA_CODE_REFERENCE || element.getTreeParent().getElementType() == REFERENCE_EXPRESSION || uncompleteCode) {
|
||||
final PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
final PsiTypeElement[] typeParameters = ref.getParameterList().getTypeParameterElements();
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
process(SourceTreeToPsiMap.psiElementToTree(typeParameters[i]), addImports, uncompleteCode);
|
||||
process((TreeElement)SourceTreeToPsiMap.psiElementToTree(typeParameters[i]), addImports, uncompleteCode);
|
||||
}
|
||||
|
||||
|
||||
boolean rightKind = true;
|
||||
if (elementType == JAVA_CODE_REFERENCE){
|
||||
if (elementType == JAVA_CODE_REFERENCE) {
|
||||
int kind = ((PsiJavaCodeReferenceElementImpl)element).getKind();
|
||||
rightKind = kind == PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND ||
|
||||
kind == PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND;
|
||||
rightKind = kind == PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND ||
|
||||
kind == PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND;
|
||||
}
|
||||
|
||||
if (rightKind) {
|
||||
boolean isInsideDocComment = TreeUtil.findParent(element, ElementType.DOC_COMMENT) != null;
|
||||
boolean isShort = !((SourceJavaCodeReference)element).isQualified();
|
||||
if (!makeFQ(isInsideDocComment)){
|
||||
if (!makeFQ(isInsideDocComment)) {
|
||||
if (isShort) return element; // short name already, no need to change
|
||||
}
|
||||
PsiElement refElement;
|
||||
if (!uncompleteCode){
|
||||
if (!uncompleteCode) {
|
||||
refElement = ref.resolve();
|
||||
}
|
||||
else{
|
||||
else {
|
||||
PsiResolveHelper helper = element.getManager().getResolveHelper();
|
||||
refElement = helper.resolveReferencedClass(
|
||||
((SourceJavaCodeReference)element).getClassNameText(),
|
||||
((SourceJavaCodeReference)element).getClassNameText(),
|
||||
SourceTreeToPsiMap.treeElementToPsi(element)
|
||||
);
|
||||
}
|
||||
if (refElement instanceof PsiClass){
|
||||
if (makeFQ(isInsideDocComment)){
|
||||
if (refElement instanceof PsiClass) {
|
||||
if (makeFQ(isInsideDocComment)) {
|
||||
String qName = ((PsiClass)refElement).getQualifiedName();
|
||||
if (qName == null) return element;
|
||||
PsiFile file = SourceTreeToPsiMap.treeElementToPsi(element).getContainingFile();
|
||||
if (ImportHelper.isImplicitlyImported(qName, file)){
|
||||
if (ImportHelper.isImplicitlyImported(qName, file)) {
|
||||
if (isShort) return element;
|
||||
return (TreeElement)makeShortReference((CompositeElement)element, (PsiClass)refElement, addImports, uncompleteCode);
|
||||
}
|
||||
if (file instanceof PsiJavaFile){
|
||||
if (file instanceof PsiJavaFile) {
|
||||
String thisPackageName = ((PsiJavaFile)file).getPackageName();
|
||||
if (ImportHelper.hasPackage(qName, thisPackageName)){
|
||||
if (ImportHelper.hasPackage(qName, thisPackageName)) {
|
||||
if (!isShort) {
|
||||
return (TreeElement)makeShortReference(
|
||||
(CompositeElement)element,
|
||||
@@ -89,7 +89,7 @@ class ReferenceAdjuster implements Constants {
|
||||
}
|
||||
return (TreeElement)replaceReferenceWithFQ(element, (PsiClass)refElement);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return (TreeElement)makeShortReference((CompositeElement)element, (PsiClass)refElement, addImports, uncompleteCode);
|
||||
}
|
||||
}
|
||||
@@ -97,9 +97,9 @@ class ReferenceAdjuster implements Constants {
|
||||
}
|
||||
}
|
||||
|
||||
if (element instanceof CompositeElement){
|
||||
if (element instanceof CompositeElement) {
|
||||
ChameleonTransforming.transformChildren(element);
|
||||
for(TreeElement child = (TreeElement)element.getFirstChildNode(); child != null; child = child.getTreeNext()){
|
||||
for (TreeElement child = (TreeElement)element.getFirstChildNode(); child != null; child = child.getTreeNext()) {
|
||||
child = process(child, addImports, uncompleteCode);
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,8 @@ class ReferenceAdjuster implements Constants {
|
||||
private boolean makeFQ(boolean isInsideDocComment) {
|
||||
if (isInsideDocComment) {
|
||||
return myUseFqClassnamesInJavadoc;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return myUseFqClassNames;
|
||||
}
|
||||
}
|
||||
@@ -118,26 +119,26 @@ class ReferenceAdjuster implements Constants {
|
||||
public void processRange(TreeElement element, int startOffset, int endOffset) {
|
||||
ArrayList<ASTNode> array = new ArrayList<ASTNode>();
|
||||
addReferencesInRange(array, element, startOffset, endOffset);
|
||||
for(int i = 0; i < array.size(); i++){
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
ASTNode ref = array.get(i);
|
||||
if (SourceTreeToPsiMap.treeElementToPsi(ref).isValid()){
|
||||
if (SourceTreeToPsiMap.treeElementToPsi(ref).isValid()) {
|
||||
process((TreeElement)ref, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addReferencesInRange(ArrayList<ASTNode> array, TreeElement parent, int startOffset, int endOffset) {
|
||||
if (parent.getElementType() == ElementType.JAVA_CODE_REFERENCE || parent.getElementType() == ElementType.REFERENCE_EXPRESSION){
|
||||
if (parent.getElementType() == ElementType.JAVA_CODE_REFERENCE || parent.getElementType() == ElementType.REFERENCE_EXPRESSION) {
|
||||
array.add(parent);
|
||||
return;
|
||||
}
|
||||
if (parent instanceof CompositeElement){
|
||||
if (parent instanceof CompositeElement) {
|
||||
ChameleonTransforming.transformChildren(parent);
|
||||
int offset = 0;
|
||||
for(TreeElement child = (TreeElement)parent.getFirstChildNode(); child != null; child = child.getTreeNext()){
|
||||
for (TreeElement child = (TreeElement)parent.getFirstChildNode(); child != null; child = child.getTreeNext()) {
|
||||
int length = child.getTextLength();
|
||||
if (startOffset <= offset + length && offset <= endOffset){
|
||||
if (startOffset <= offset && offset + length <= endOffset){
|
||||
if (startOffset <= offset + length && offset <= endOffset) {
|
||||
if (startOffset <= offset && offset + length <= endOffset) {
|
||||
array.add(child);
|
||||
}
|
||||
addReferencesInRange(array, child, startOffset - offset, endOffset - offset);
|
||||
@@ -153,20 +154,20 @@ class ReferenceAdjuster implements Constants {
|
||||
boolean addImports,
|
||||
boolean uncompleteCode
|
||||
) {
|
||||
if (refClass.getContainingClass() != null){
|
||||
if (refClass.getContainingClass() != null) {
|
||||
PsiClass parentClass = refClass.getContainingClass();
|
||||
PsiJavaCodeReferenceElement psiReference = (PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(reference);
|
||||
PsiManager manager = parentClass.getManager();
|
||||
if (manager.getResolveHelper().isAccessible(refClass, psiReference, null)) {
|
||||
for(ASTNode parent = reference.getTreeParent(); parent != null; parent = parent.getTreeParent()){
|
||||
for (ASTNode parent = reference.getTreeParent(); parent != null; parent = parent.getTreeParent()) {
|
||||
PsiElement parentPsi = SourceTreeToPsiMap.treeElementToPsi(parent);
|
||||
if (parentPsi instanceof PsiClass){
|
||||
if (parentPsi instanceof PsiClass) {
|
||||
PsiClass inner = ((PsiClass)parentPsi).findInnerClassByName(psiReference.getReferenceName(), true);
|
||||
if (inner != null) {
|
||||
if (inner == refClass) return replaceReferenceWithShort(reference);
|
||||
return reference;
|
||||
}
|
||||
if (InheritanceUtil.isInheritorOrSelf((PsiClass)parentPsi, parentClass, true)){
|
||||
if (InheritanceUtil.isInheritorOrSelf((PsiClass)parentPsi, parentClass, true)) {
|
||||
return replaceReferenceWithShort(reference);
|
||||
}
|
||||
}
|
||||
@@ -175,7 +176,7 @@ class ReferenceAdjuster implements Constants {
|
||||
|
||||
if (!mySettings.INSERT_INNER_CLASS_IMPORTS) {
|
||||
final ASTNode qualifier = reference.findChildByRole(ChildRole.QUALIFIER);
|
||||
if (qualifier != null){
|
||||
if (qualifier != null) {
|
||||
|
||||
makeShortReference((CompositeElement)qualifier, parentClass, addImports, uncompleteCode);
|
||||
}
|
||||
@@ -186,42 +187,42 @@ class ReferenceAdjuster implements Constants {
|
||||
PsiFile file = SourceTreeToPsiMap.treeElementToPsi(reference).getContainingFile();
|
||||
PsiManager manager = file.getManager();
|
||||
PsiResolveHelper helper = manager.getResolveHelper();
|
||||
if (addImports){
|
||||
if (!myImportHelper.addImport(file, refClass)){
|
||||
if (addImports) {
|
||||
if (!myImportHelper.addImport(file, refClass)) {
|
||||
return reference;
|
||||
}
|
||||
if (isSafeToShortenReference(reference, refClass, helper)) {
|
||||
reference = replaceReferenceWithShort(reference);
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
PsiClass curRefClass = helper.resolveReferencedClass(
|
||||
refClass.getName(),
|
||||
SourceTreeToPsiMap.treeElementToPsi(reference)
|
||||
);
|
||||
if (manager.areElementsEquivalent(refClass, curRefClass)){
|
||||
if (manager.areElementsEquivalent(refClass, curRefClass)) {
|
||||
reference = replaceReferenceWithShort(reference);
|
||||
}
|
||||
}
|
||||
return reference;
|
||||
}
|
||||
|
||||
private static boolean isSafeToShortenReference (ASTNode reference, PsiClass refClass, PsiResolveHelper helper) {
|
||||
private static boolean isSafeToShortenReference(ASTNode reference, PsiClass refClass, PsiResolveHelper helper) {
|
||||
PsiClass newRefClass = helper.resolveReferencedClass(
|
||||
refClass.getName(),
|
||||
SourceTreeToPsiMap.treeElementToPsi(reference)
|
||||
refClass.getName(),
|
||||
SourceTreeToPsiMap.treeElementToPsi(reference)
|
||||
);
|
||||
return refClass.getManager().areElementsEquivalent(refClass, newRefClass);
|
||||
}
|
||||
|
||||
private static CompositeElement replaceReferenceWithShort(CompositeElement reference) {
|
||||
((SourceJavaCodeReference) reference).dequalify();
|
||||
((SourceJavaCodeReference)reference).dequalify();
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
private static ASTNode replaceReferenceWithFQ(ASTNode reference, PsiClass refClass) {
|
||||
((SourceJavaCodeReference)reference).fullyQualify(refClass);
|
||||
((SourceJavaCodeReference)reference).fullyQualify(refClass);
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ import java.util.Set;
|
||||
public class XmlParsing implements ElementType {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.xml.XmlParser");
|
||||
|
||||
public static final TokenSet XML_WHITE_SPACE_OR_COMMENT_BIT_SET = TokenSet.create(new IElementType[]{XML_WHITE_SPACE, XML_COMMENT_START, XML_COMMENT_CHARACTERS,
|
||||
XML_COMMENT_END, XML_BAD_CHARACTER});
|
||||
public static final TokenSet XML_WHITE_SPACE_OR_COMMENT_BIT_SET =
|
||||
TokenSet.create(new IElementType[]{XML_WHITE_SPACE, XML_COMMENT_START, XML_COMMENT_CHARACTERS,
|
||||
XML_COMMENT_END, XML_BAD_CHARACTER});
|
||||
|
||||
public static final TokenSet XML_COMMENT_BIT_SET = TokenSet.create(new IElementType[]{XML_COMMENT_START, XML_COMMENT_CHARACTERS, XML_COMMENT_END});
|
||||
public static final TokenSet XML_COMMENT_BIT_SET =
|
||||
TokenSet.create(new IElementType[]{XML_COMMENT_START, XML_COMMENT_CHARACTERS, XML_COMMENT_END});
|
||||
|
||||
private ParsingContext myContext;
|
||||
|
||||
@@ -49,7 +51,7 @@ public class XmlParsing implements ElementType {
|
||||
TreeUtil.addChildren(root, parseProlog(lexer));
|
||||
parseGenericXml(lexer, root, new HashSet<String>());
|
||||
|
||||
ParseUtil.insertMissingTokens((CompositeElement)root,
|
||||
ParseUtil.insertMissingTokens(root,
|
||||
originalLexer,
|
||||
startOffset,
|
||||
endOffset,
|
||||
@@ -208,7 +210,7 @@ public class XmlParsing implements ElementType {
|
||||
}
|
||||
|
||||
String openedName = StringFactory.createStringFromConstantArray(lexer.getBuffer(), lexer.getTokenStart(),
|
||||
lexer.getTokenEnd() - lexer.getTokenStart());
|
||||
lexer.getTokenEnd() - lexer.getTokenStart());
|
||||
addToken(tag, lexer);
|
||||
|
||||
parseAttributeList(tag, lexer);
|
||||
@@ -269,7 +271,7 @@ public class XmlParsing implements ElementType {
|
||||
}
|
||||
|
||||
String closingName = StringFactory.createStringFromConstantArray(lexer.getBuffer(), lexer.getTokenStart(),
|
||||
lexer.getTokenEnd() - lexer.getTokenStart());
|
||||
lexer.getTokenEnd() - lexer.getTokenStart());
|
||||
|
||||
if (!closingName.equals(openedName) && names.contains(closingName)) {
|
||||
ParseUtil.restorePosition(lexer, pos);
|
||||
@@ -573,7 +575,7 @@ public class XmlParsing implements ElementType {
|
||||
while (true) {
|
||||
if (lexer.getTokenType() == XML_ENTITY_REF_TOKEN) {
|
||||
TreeUtil.addChildren(enumeratedType, parseEntityRef(lexer));
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.getTokenType() != XML_NAME && lexer.getTokenType() != XML_BAR) break;
|
||||
@@ -606,7 +608,7 @@ public class XmlParsing implements ElementType {
|
||||
while (true) {
|
||||
if (lexer.getTokenType() == XML_ENTITY_REF_TOKEN) {
|
||||
TreeUtil.addChildren(tag, parseEntityRef(lexer));
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.getTokenType() != XML_NAME) {
|
||||
@@ -624,7 +626,7 @@ public class XmlParsing implements ElementType {
|
||||
|
||||
if (lexer.getTokenType() != XML_EQ) {
|
||||
TreeUtil.addChildren(tag, Factory.createErrorElement("'=' expected"));
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
addToken(tag, lexer);
|
||||
@@ -640,10 +642,12 @@ public class XmlParsing implements ElementType {
|
||||
if (lexer.getTokenType() == XML_ATTRIBUTE_VALUE_END_DELIMITER) {
|
||||
lastPosition = lexer.getTokenEnd();
|
||||
addToken(tag, lexer);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
lastPosition = -1;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
lastPosition = -1;
|
||||
}
|
||||
}
|
||||
@@ -699,12 +703,12 @@ public class XmlParsing implements ElementType {
|
||||
CompositeElement markupDecl = Factory.createCompositeElement(XmlElementType.XML_MARKUP_DECL);
|
||||
TreeUtil.addChildren(dummyRoot, markupDecl);
|
||||
parseMarkupContent(lexer, markupDecl);
|
||||
while(lexer.getTokenType() != null){
|
||||
while (lexer.getTokenType() != null) {
|
||||
TreeUtil.addChildren(markupDecl, ParseUtil.createTokenElement(lexer, dummyRoot.getCharTable()));
|
||||
lexer.advance();
|
||||
}
|
||||
originalLexer.start(text, start, end, _OldXmlLexer.DOCTYPE);
|
||||
ParseUtil.insertMissingTokens((CompositeElement)dummyRoot,
|
||||
ParseUtil.insertMissingTokens(dummyRoot,
|
||||
originalLexer,
|
||||
start,
|
||||
end,
|
||||
|
||||
@@ -25,23 +25,23 @@ import com.intellij.util.IncorrectOperationException;
|
||||
public class ChangeUtil implements Constants {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.ChangeUtil");
|
||||
|
||||
private ChangeUtil() {}
|
||||
private ChangeUtil() { }
|
||||
|
||||
public static void addChild(final CompositeElement parent, final TreeElement child, TreeElement anchorBefore) {
|
||||
LOG.assertTrue(anchorBefore == null || anchorBefore.getTreeParent() == parent);
|
||||
|
||||
int childLength = child.getTextLength();
|
||||
int offset = anchorBefore != null
|
||||
? anchorBefore.getStartOffset()
|
||||
: parent.getStartOffset() + parent.getTextLength();
|
||||
? anchorBefore.getStartOffset()
|
||||
: parent.getStartOffset() + parent.getTextLength();
|
||||
|
||||
PsiTreeChangeEventImpl event = null;
|
||||
PsiElement parentPsiElement = SourceTreeToPsiMap.treeElementToPsi(parent);
|
||||
PsiFile file = parentPsiElement.getContainingFile();
|
||||
boolean physical = parentPsiElement.isPhysical();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
if (file != null){
|
||||
if (file != null) {
|
||||
manager.invalidateFile(file);
|
||||
}
|
||||
event = new PsiTreeChangeEventImpl(manager);
|
||||
@@ -52,7 +52,7 @@ public class ChangeUtil implements Constants {
|
||||
manager.beforeChildAddition(event);
|
||||
|
||||
RepositoryManager repositoryManager = manager.getRepositoryManager();
|
||||
if (repositoryManager != null){
|
||||
if (repositoryManager != null) {
|
||||
repositoryManager.beforeChildAddedOrRemoved(file, parent, child);
|
||||
}
|
||||
}
|
||||
@@ -60,12 +60,13 @@ public class ChangeUtil implements Constants {
|
||||
child.setTreeNext(null);
|
||||
final CharTable newCharTab = SharedImplUtil.findCharTableByTree(parent);
|
||||
final CharTable oldCharTab = SharedImplUtil.findCharTableByTree(child);
|
||||
if(newCharTab != oldCharTab)
|
||||
registerLeafsInCharTab(newCharTab, child, oldCharTab);
|
||||
if (anchorBefore != null){
|
||||
if (newCharTab != oldCharTab) {
|
||||
registerLeafsInCharTab(newCharTab, child, oldCharTab);
|
||||
}
|
||||
if (anchorBefore != null) {
|
||||
TreeUtil.insertBefore(anchorBefore, child);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
TreeUtil.addChildren(parent, child);
|
||||
}
|
||||
|
||||
@@ -73,11 +74,11 @@ public class ChangeUtil implements Constants {
|
||||
parent.subtreeChanged();
|
||||
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
event.setChild(SourceTreeToPsiMap.treeElementToPsi(child));
|
||||
manager.childAdded(event);
|
||||
}
|
||||
else if (manager != null){
|
||||
else if (manager != null) {
|
||||
manager.nonPhysicalChange();
|
||||
}
|
||||
|
||||
@@ -94,11 +95,11 @@ public class ChangeUtil implements Constants {
|
||||
}
|
||||
|
||||
private static void registerLeafsInCharTab(CharTable newCharTab, ASTNode child, CharTable oldCharTab) {
|
||||
if(newCharTab == oldCharTab) return;
|
||||
while(child != null){
|
||||
if (newCharTab == oldCharTab) return;
|
||||
while (child != null) {
|
||||
CharTable charTable = child.getUserData(CharTable.CHAR_TABLE_KEY);
|
||||
if (child instanceof LeafElement) {
|
||||
((LeafElement)child).registerInCharTable(newCharTab, oldCharTab);
|
||||
((LeafElement)child).registerInCharTable(newCharTab, oldCharTab);
|
||||
}
|
||||
else {
|
||||
registerLeafsInCharTab(newCharTab, child.getFirstChildNode(), charTable != null ? charTable : oldCharTab);
|
||||
@@ -120,9 +121,9 @@ public class ChangeUtil implements Constants {
|
||||
PsiElement parentPsiElement = SourceTreeToPsiMap.treeElementToPsi(parent);
|
||||
PsiFile file = parentPsiElement.getContainingFile();
|
||||
boolean physical = parentPsiElement.isPhysical();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
if (file != null){
|
||||
if (file != null) {
|
||||
manager.invalidateFile(file);
|
||||
}
|
||||
event = new PsiTreeChangeEventImpl(manager);
|
||||
@@ -134,7 +135,7 @@ public class ChangeUtil implements Constants {
|
||||
manager.beforeChildRemoval(event);
|
||||
|
||||
RepositoryManager repositoryManager = manager.getRepositoryManager();
|
||||
if (repositoryManager != null){
|
||||
if (repositoryManager != null) {
|
||||
repositoryManager.beforeChildAddedOrRemoved(file, parent, child);
|
||||
}
|
||||
}
|
||||
@@ -146,17 +147,17 @@ public class ChangeUtil implements Constants {
|
||||
//updateCachedLengths(parent, -childLength);
|
||||
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
manager.childRemoved(event);
|
||||
}
|
||||
else if (manager != null){
|
||||
else if (manager != null) {
|
||||
manager.nonPhysicalChange();
|
||||
}
|
||||
checkConsistency(file);
|
||||
}
|
||||
|
||||
public static void replaceChild(final CompositeElement parent, final TreeElement oldChild, final TreeElement newChild) {
|
||||
if (oldChild.getTreeParent() != parent){
|
||||
if (oldChild.getTreeParent() != parent) {
|
||||
LOG.assertTrue(oldChild.getTreeParent() == parent);
|
||||
}
|
||||
|
||||
@@ -170,9 +171,9 @@ public class ChangeUtil implements Constants {
|
||||
PsiElement parentPsiElement = SourceTreeToPsiMap.treeElementToPsi(parent);
|
||||
PsiFile file = parentPsiElement.getContainingFile();
|
||||
boolean physical = parentPsiElement.isPhysical();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
if (file != null){
|
||||
if (file != null) {
|
||||
manager.invalidateFile(file);
|
||||
}
|
||||
event = new PsiTreeChangeEventImpl(manager);
|
||||
@@ -184,28 +185,28 @@ public class ChangeUtil implements Constants {
|
||||
manager.beforeChildReplacement(event);
|
||||
|
||||
RepositoryManager repositoryManager = manager.getRepositoryManager();
|
||||
if (repositoryManager != null){
|
||||
if (repositoryManager != null) {
|
||||
repositoryManager.beforeChildAddedOrRemoved(file, parent, oldChild);
|
||||
repositoryManager.beforeChildAddedOrRemoved(file, parent, newChild);
|
||||
}
|
||||
}
|
||||
|
||||
newChild.setTreeNext(null);
|
||||
if(oldCharTable != newCharTable){
|
||||
if (oldCharTable != newCharTable) {
|
||||
registerLeafsInCharTab(newCharTable, newChild, oldCharTable);
|
||||
}
|
||||
oldChild.putUserData(CharTable.CHAR_TABLE_KEY, newCharTable);
|
||||
if(oldChild != newChild) TreeUtil.replace(oldChild, newChild);
|
||||
if (oldChild != newChild) TreeUtil.replace(oldChild, newChild);
|
||||
|
||||
parent.subtreeChanged();
|
||||
//updateCachedLengths(parent, newLength - oldLength);
|
||||
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
event.setNewChild(SourceTreeToPsiMap.treeElementToPsi(newChild));
|
||||
manager.childReplaced(event);
|
||||
}
|
||||
else if (manager != null){
|
||||
else if (manager != null) {
|
||||
manager.nonPhysicalChange();
|
||||
}
|
||||
checkConsistency(file);
|
||||
@@ -222,7 +223,7 @@ public class ChangeUtil implements Constants {
|
||||
PsiFile file = parentPsiElement.getContainingFile();
|
||||
ChameleonTransforming.transformChildren(newChildrenParent);
|
||||
final ASTNode firstChild = newChildrenParent.getFirstChildNode();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
manager.invalidateFile(file);
|
||||
event = new PsiTreeChangeEventImpl(manager);
|
||||
@@ -233,15 +234,15 @@ public class ChangeUtil implements Constants {
|
||||
manager.beforeChildrenChange(event);
|
||||
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
if (vFile != null){
|
||||
if (vFile != null) {
|
||||
RepositoryManager repositoryManager = manager.getRepositoryManager();
|
||||
if (repositoryManager != null){
|
||||
if (repositoryManager != null) {
|
||||
ChameleonTransforming.transformChildren(parent);
|
||||
for(ASTNode child = parent.getFirstChildNode(); child != null; child = child.getTreeNext()){
|
||||
for (ASTNode child = parent.getFirstChildNode(); child != null; child = child.getTreeNext()) {
|
||||
repositoryManager.beforeChildAddedOrRemoved(file, parent, child);
|
||||
}
|
||||
|
||||
for(ASTNode child = firstChild; child != null; child = child.getTreeNext()){
|
||||
for (ASTNode child = firstChild; child != null; child = child.getTreeNext()) {
|
||||
repositoryManager.beforeChildAddedOrRemoved(file, parent, child);
|
||||
}
|
||||
}
|
||||
@@ -249,13 +250,13 @@ public class ChangeUtil implements Constants {
|
||||
}
|
||||
final CharTable newCharTab = SharedImplUtil.findCharTableByTree(parent);
|
||||
ASTNode oldChild = parent.getFirstChildNode();
|
||||
while(oldChild != null){
|
||||
while (oldChild != null) {
|
||||
oldChild.putUserData(CharTable.CHAR_TABLE_KEY, newCharTab);
|
||||
oldChild = oldChild.getTreeNext();
|
||||
}
|
||||
TreeUtil.removeRange((TreeElement)parent.getFirstChildNode(), null);
|
||||
|
||||
if (firstChild != null){
|
||||
if (firstChild != null) {
|
||||
final CharTable oldCharTab = SharedImplUtil.findCharTableByTree(newChildrenParent);
|
||||
registerLeafsInCharTab(newCharTab, firstChild, oldCharTab);
|
||||
TreeUtil.addChildren(parent, (TreeElement)firstChild);
|
||||
@@ -267,10 +268,10 @@ public class ChangeUtil implements Constants {
|
||||
//}
|
||||
|
||||
PsiManagerImpl manager = (PsiManagerImpl)parent.getManager();
|
||||
if (physical){
|
||||
if (physical) {
|
||||
manager.childrenChanged(event);
|
||||
}
|
||||
else if (manager != null){
|
||||
else if (manager != null) {
|
||||
manager.nonPhysicalChange();
|
||||
}
|
||||
checkConsistency(file);
|
||||
@@ -282,9 +283,9 @@ public class ChangeUtil implements Constants {
|
||||
|
||||
private static void encodeInformation(TreeElement element, ASTNode original) {
|
||||
boolean encodeRefTargets = true;
|
||||
if (original.getTreeParent() instanceof DummyHolderElement){
|
||||
if (original.getTreeParent() instanceof DummyHolderElement) {
|
||||
DummyHolder dummyHolder = (DummyHolder)SourceTreeToPsiMap.treeElementToPsi(original.getTreeParent());
|
||||
if (dummyHolder.getContext() == null && !dummyHolder.hasImports()){ // optimization
|
||||
if (dummyHolder.getContext() == null && !dummyHolder.hasImports()) { // optimization
|
||||
encodeRefTargets = false;
|
||||
}
|
||||
}
|
||||
@@ -292,16 +293,17 @@ public class ChangeUtil implements Constants {
|
||||
}
|
||||
|
||||
private static void _encodeInformation(TreeElement element, ASTNode original, boolean encodeRefTargets) {
|
||||
if (original instanceof CompositeElement){
|
||||
if (original.getElementType() == ElementType.JAVA_CODE_REFERENCE || original.getElementType() == ElementType.REFERENCE_EXPRESSION){
|
||||
if (encodeRefTargets){
|
||||
if (original instanceof CompositeElement) {
|
||||
if (original.getElementType() == ElementType.JAVA_CODE_REFERENCE || original.getElementType() == ElementType.REFERENCE_EXPRESSION) {
|
||||
if (encodeRefTargets) {
|
||||
encodeInformationInRef(element, original);
|
||||
}
|
||||
}
|
||||
else if (original.getElementType() == ElementType.MODIFIER_LIST){
|
||||
if ((original.getTreeParent().getElementType() == ElementType.FIELD || original.getTreeParent().getElementType() == ElementType.METHOD)
|
||||
else if (original.getElementType() == ElementType.MODIFIER_LIST) {
|
||||
if ((original.getTreeParent().getElementType() == ElementType.FIELD ||
|
||||
original.getTreeParent().getElementType() == ElementType.METHOD)
|
||||
&& original.getTreeParent().getTreeParent().getElementType() == ElementType.CLASS &&
|
||||
((PsiClass)SourceTreeToPsiMap.treeElementToPsi(original.getTreeParent().getTreeParent())).isInterface()){
|
||||
((PsiClass)SourceTreeToPsiMap.treeElementToPsi(original.getTreeParent().getTreeParent())).isInterface()) {
|
||||
element.putUserData(INTERFACE_MODIFIERS_FLAG_KEY, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
@@ -310,7 +312,7 @@ public class ChangeUtil implements Constants {
|
||||
ChameleonTransforming.transformChildren(original);
|
||||
TreeElement child = (TreeElement)element.getFirstChildNode();
|
||||
ASTNode child1 = original.getFirstChildNode();
|
||||
while(child != null){
|
||||
while (child != null) {
|
||||
_encodeInformation(child, child1, encodeRefTargets);
|
||||
child = child.getTreeNext();
|
||||
child1 = child1.getTreeNext();
|
||||
@@ -319,94 +321,95 @@ public class ChangeUtil implements Constants {
|
||||
}
|
||||
|
||||
private static void encodeInformationInRef(TreeElement ref, ASTNode original) {
|
||||
if (original.getElementType() == REFERENCE_EXPRESSION){
|
||||
if (original.getElementType() == REFERENCE_EXPRESSION) {
|
||||
if (original.getTreeParent().getElementType() != REFERENCE_EXPRESSION) return; // cannot refer to class (optimization)
|
||||
PsiElement target = ((PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(original)).resolve();
|
||||
if (target instanceof PsiClass){
|
||||
if (target instanceof PsiClass) {
|
||||
ref.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass)target);
|
||||
}
|
||||
}
|
||||
else if (original.getElementType() == JAVA_CODE_REFERENCE){
|
||||
switch(((PsiJavaCodeReferenceElementImpl)original).getKind()){
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND:
|
||||
{
|
||||
final PsiElement target = ((PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(original)).resolve();
|
||||
if (target instanceof PsiClass){
|
||||
ref.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass)target);
|
||||
}
|
||||
}
|
||||
break;
|
||||
else if (original.getElementType() == JAVA_CODE_REFERENCE) {
|
||||
switch (((PsiJavaCodeReferenceElementImpl)original).getKind()) {
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND:
|
||||
{
|
||||
final PsiElement target = ((PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(original)).resolve();
|
||||
if (target instanceof PsiClass) {
|
||||
ref.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass)target);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PsiJavaCodeReferenceElementImpl.PACKAGE_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_OR_PACKAGE_NAME_KIND:
|
||||
break;
|
||||
case PsiJavaCodeReferenceElementImpl.PACKAGE_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_OR_PACKAGE_NAME_KIND:
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG.assertTrue(false);
|
||||
default:
|
||||
LOG.assertTrue(false);
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
LOG.assertTrue(false, "Wrong element type: " + original.getElementType());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeElement decodeInformation(TreeElement element) {
|
||||
if (element instanceof CompositeElement){
|
||||
if (element instanceof CompositeElement) {
|
||||
ChameleonTransforming.transformChildren(element);
|
||||
TreeElement child = (TreeElement)element.getFirstChildNode();
|
||||
while(child != null){
|
||||
while (child != null) {
|
||||
child = decodeInformation(child);
|
||||
child = child.getTreeNext();
|
||||
}
|
||||
|
||||
if (element.getElementType() == ElementType.JAVA_CODE_REFERENCE || element.getElementType() == ElementType.REFERENCE_EXPRESSION){
|
||||
if (element.getElementType() == ElementType.JAVA_CODE_REFERENCE || element.getElementType() == ElementType.REFERENCE_EXPRESSION) {
|
||||
PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
final PsiClass refClass = element.getCopyableUserData(REFERENCED_CLASS_KEY);
|
||||
if (refClass != null){
|
||||
if (refClass != null) {
|
||||
element.putCopyableUserData(REFERENCED_CLASS_KEY, null);
|
||||
|
||||
if (refClass.isPhysical() || !ref.isPhysical()){ //?
|
||||
if (refClass.isPhysical() || !ref.isPhysical()) { //?
|
||||
PsiManager manager = refClass.getManager();
|
||||
CodeStyleManagerEx codeStyleManager = (CodeStyleManagerEx)manager.getCodeStyleManager();
|
||||
PsiElement refElement1 = ref.resolve();
|
||||
try{
|
||||
if (refClass != refElement1 && !manager.areElementsEquivalent(refClass, refElement1)){
|
||||
if (((CompositeElement)element).findChildByRole(ChildRole.QUALIFIER) == null){ // can restore only if short (otherwise qualifier should be already restored)
|
||||
try {
|
||||
if (refClass != refElement1 && !manager.areElementsEquivalent(refClass, refElement1)) {
|
||||
if (((CompositeElement)element).findChildByRole(ChildRole.QUALIFIER) ==
|
||||
null) { // can restore only if short (otherwise qualifier should be already restored)
|
||||
ref = (PsiJavaCodeReferenceElement)ref.bindToElement(refClass);
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
// shorten references to the same package and to inner classes that can be accessed by short name
|
||||
ref = (PsiJavaCodeReferenceElement)codeStyleManager.shortenClassReferences(ref, CodeStyleManagerEx.DO_NOT_ADD_IMPORTS);
|
||||
}
|
||||
element = SourceTreeToPsiMap.psiElementToTree(ref);
|
||||
element = (TreeElement)SourceTreeToPsiMap.psiElementToTree(ref);
|
||||
}
|
||||
catch(IncorrectOperationException e){
|
||||
catch (IncorrectOperationException e) {
|
||||
codeStyleManager.addImport(ref.getContainingFile(), refClass); // it may fail for local class, let's try for DummyHolder
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element.getElementType() == ElementType.MODIFIER_LIST){
|
||||
if (element.getUserData(INTERFACE_MODIFIERS_FLAG_KEY) != null){
|
||||
else if (element.getElementType() == ElementType.MODIFIER_LIST) {
|
||||
if (element.getUserData(INTERFACE_MODIFIERS_FLAG_KEY) != null) {
|
||||
element.putUserData(INTERFACE_MODIFIERS_FLAG_KEY, null);
|
||||
try{
|
||||
try {
|
||||
PsiModifierList modifierList = (PsiModifierList)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
if (element.getTreeParent().getElementType() == ElementType.FIELD){
|
||||
if (element.getTreeParent().getElementType() == ElementType.FIELD) {
|
||||
modifierList.setModifierProperty(PsiModifier.PUBLIC, true);
|
||||
modifierList.setModifierProperty(PsiModifier.STATIC, true);
|
||||
modifierList.setModifierProperty(PsiModifier.FINAL, true);
|
||||
}
|
||||
else if (element.getTreeParent().getElementType() == ElementType.METHOD){
|
||||
else if (element.getTreeParent().getElementType() == ElementType.METHOD) {
|
||||
modifierList.setModifierProperty(PsiModifier.PUBLIC, true);
|
||||
modifierList.setModifierProperty(PsiModifier.ABSTRACT, true);
|
||||
}
|
||||
}
|
||||
catch(IncorrectOperationException e){
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
@@ -422,7 +425,7 @@ public class ChangeUtil implements Constants {
|
||||
registerLeafsInCharTab(table, element, charTableByTree);
|
||||
new DummyHolder(manager, element, null, table).getTreeElement();
|
||||
encodeInformation(element, original);
|
||||
// CodeEditUtil.normalizeCloneIndent(element, original, table);
|
||||
// CodeEditUtil.normalizeCloneIndent(element, original, table);
|
||||
CodeEditUtil.unindentSubtree(element, original, table);
|
||||
return element;
|
||||
}
|
||||
@@ -431,59 +434,59 @@ public class ChangeUtil implements Constants {
|
||||
final DummyHolder holder = new DummyHolder(original.getManager(), null);
|
||||
final FileElement holderElement = holder.getTreeElement();
|
||||
final TreeElement treeElement = _copyToElement(original, holderElement.getCharTable());
|
||||
// TreeElement treePrev = treeElement.getTreePrev(); // This is hack to support bug used in formater
|
||||
// TreeElement treePrev = treeElement.getTreePrev(); // This is hack to support bug used in formater
|
||||
TreeUtil.addChildren(holderElement, treeElement);
|
||||
// treeElement.setTreePrev(treePrev);
|
||||
// treeElement.setTreePrev(treePrev);
|
||||
return treeElement;
|
||||
}
|
||||
|
||||
private static TreeElement _copyToElement(PsiElement original, CharTable table) {
|
||||
LOG.assertTrue(original.isValid());
|
||||
if (SourceTreeToPsiMap.hasTreeElement(original)){
|
||||
return copyElement(SourceTreeToPsiMap.psiElementToTree(original), table);
|
||||
if (SourceTreeToPsiMap.hasTreeElement(original)) {
|
||||
return copyElement((TreeElement)SourceTreeToPsiMap.psiElementToTree(original), table);
|
||||
}
|
||||
else if (original instanceof PsiIdentifier){
|
||||
else if (original instanceof PsiIdentifier) {
|
||||
final String text = original.getText();
|
||||
return Factory.createLeafElement(IDENTIFIER, text.toCharArray(), 0, text.length(), -1, table);
|
||||
}
|
||||
else if (original instanceof PsiKeyword){
|
||||
else if (original instanceof PsiKeyword) {
|
||||
final String text = original.getText();
|
||||
return Factory.createLeafElement(((PsiKeyword)original).getTokenType(), text.toCharArray(), 0, text.length(), -1, table);
|
||||
}
|
||||
else if (original instanceof PsiReferenceExpression){
|
||||
else if (original instanceof PsiReferenceExpression) {
|
||||
TreeElement element = createReferenceExpression(original.getManager(), original.getText(), table);
|
||||
PsiElement refElement = ((PsiJavaCodeReferenceElement)original).resolve();
|
||||
if (refElement instanceof PsiClass){
|
||||
if (refElement instanceof PsiClass) {
|
||||
element.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass)refElement);
|
||||
}
|
||||
return element;
|
||||
}
|
||||
else if (original instanceof PsiJavaCodeReferenceElement){
|
||||
else if (original instanceof PsiJavaCodeReferenceElement) {
|
||||
PsiElement refElement = ((PsiJavaCodeReferenceElement)original).resolve();
|
||||
if (refElement instanceof PsiClass){
|
||||
if (refElement instanceof PsiAnonymousClass){
|
||||
if (refElement instanceof PsiClass) {
|
||||
if (refElement instanceof PsiAnonymousClass) {
|
||||
PsiJavaCodeReferenceElement ref = ((PsiAnonymousClass)refElement).getBaseClassReference();
|
||||
original = ref;
|
||||
refElement = ref.resolve();
|
||||
}
|
||||
|
||||
boolean isFQ = false;
|
||||
if (original instanceof PsiJavaCodeReferenceElementImpl){
|
||||
if (original instanceof PsiJavaCodeReferenceElementImpl) {
|
||||
int kind = ((PsiJavaCodeReferenceElementImpl)original).getKind();
|
||||
switch(kind){
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND:
|
||||
isFQ = false;
|
||||
break;
|
||||
switch (kind) {
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND:
|
||||
isFQ = false;
|
||||
break;
|
||||
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_OR_PACKAGE_NAME_KIND:
|
||||
isFQ = true;
|
||||
break;
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND:
|
||||
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_OR_PACKAGE_NAME_KIND:
|
||||
isFQ = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG.assertTrue(false);
|
||||
default:
|
||||
LOG.assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,22 +495,22 @@ public class ChangeUtil implements Constants {
|
||||
element.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass)refElement);
|
||||
return element;
|
||||
}
|
||||
else if (refElement instanceof PsiPackage){
|
||||
else if (refElement instanceof PsiPackage) {
|
||||
return createReference(original.getManager(), original.getText(), table);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return createReference(original.getManager(), original.getText(), table);
|
||||
}
|
||||
}
|
||||
else if (original instanceof PsiCompiledElement){
|
||||
else if (original instanceof PsiCompiledElement) {
|
||||
PsiElement sourceVersion = original.getNavigationElement();
|
||||
if (sourceVersion != original){
|
||||
if (sourceVersion != original) {
|
||||
return _copyToElement(sourceVersion, table);
|
||||
}
|
||||
ASTNode mirror = SourceTreeToPsiMap.psiElementToTree(((PsiCompiledElement)original).getMirror());
|
||||
return _copyToElement(SourceTreeToPsiMap.treeElementToPsi(mirror), table);
|
||||
}
|
||||
else if (original instanceof PsiTypeElement){
|
||||
else if (original instanceof PsiTypeElement) {
|
||||
PsiTypeElement typeElement = (PsiTypeElement)original;
|
||||
PsiType type = typeElement.getType();
|
||||
if (type instanceof PsiEllipsisType) {
|
||||
@@ -521,7 +524,7 @@ public class ChangeUtil implements Constants {
|
||||
TreeUtil.addChildren(element, Factory.createLeafElement(ELLIPSIS, new char[]{'.', '.', '.'}, 0, 3, -1, table));
|
||||
return element;
|
||||
}
|
||||
else if (type instanceof PsiArrayType){
|
||||
else if (type instanceof PsiArrayType) {
|
||||
TreeElement componentTypeCopy = _copyToElement(
|
||||
new LightTypeElement(original.getManager(), ((PsiArrayType)type).getComponentType()),
|
||||
table
|
||||
@@ -533,7 +536,7 @@ public class ChangeUtil implements Constants {
|
||||
TreeUtil.addChildren(element, Factory.createLeafElement(RBRACKET, new char[]{']'}, 0, 1, -1, table));
|
||||
return element;
|
||||
}
|
||||
else if (type instanceof PsiPrimitiveType){
|
||||
else if (type instanceof PsiPrimitiveType) {
|
||||
String text = typeElement.getText();
|
||||
if (text.equals("null")) return null;
|
||||
Lexer lexer = new JavaLexer(LanguageLevel.JDK_1_3);
|
||||
@@ -542,23 +545,26 @@ public class ChangeUtil implements Constants {
|
||||
CompositeElement element = Factory.createCompositeElement(TYPE);
|
||||
TreeUtil.addChildren(element, keyword);
|
||||
return element;
|
||||
} else if (type instanceof PsiWildcardType) {
|
||||
}
|
||||
else if (type instanceof PsiWildcardType) {
|
||||
char[] buffer = original.getText().toCharArray();
|
||||
return DeclarationParsing.parseTypeText(original.getManager(), buffer, 0, buffer.length, table);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
final PsiJavaCodeReferenceElement ref;
|
||||
if (type instanceof PsiClassReferenceType){
|
||||
if (type instanceof PsiClassReferenceType) {
|
||||
PsiClassReferenceType refType = (PsiClassReferenceType)type;
|
||||
ref = refType.getReference();
|
||||
} else if (type instanceof PsiImmediateClassType) {
|
||||
final PsiImmediateClassType classType = (PsiImmediateClassType) type;
|
||||
}
|
||||
else if (type instanceof PsiImmediateClassType) {
|
||||
final PsiImmediateClassType classType = (PsiImmediateClassType)type;
|
||||
final CompositeElement reference = createReference(original.getManager(), classType.getPresentableText(), table);
|
||||
final CompositeElement immediateTypeElement = Factory.createCompositeElement(TYPE);
|
||||
TreeUtil.addChildren(immediateTypeElement, reference);
|
||||
encodeInfoInTypeElement(immediateTypeElement, classType);
|
||||
return immediateTypeElement;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
String text = original.getText();
|
||||
ref = new LightClassReference(original.getManager(), text, type.getCanonicalText(), original);
|
||||
}
|
||||
@@ -567,13 +573,13 @@ public class ChangeUtil implements Constants {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
LOG.error("ChangeUtil.copyToElement() unknown element " + original);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static CompositeElement createReference(PsiManager manager, String text, CharTable table){
|
||||
private static CompositeElement createReference(PsiManager manager, String text, CharTable table) {
|
||||
return Parsing.parseJavaCodeReferenceText(manager, text.toCharArray(), table);
|
||||
}
|
||||
|
||||
@@ -588,7 +594,7 @@ public class ChangeUtil implements Constants {
|
||||
if (type instanceof PsiArrayType) {
|
||||
final ASTNode firstChild = typeElement.getFirstChildNode();
|
||||
LOG.assertTrue(firstChild.getElementType() == TYPE);
|
||||
encodeInfoInTypeElement(firstChild, ((PsiArrayType) type).getComponentType());
|
||||
encodeInfoInTypeElement(firstChild, ((PsiArrayType)type).getComponentType());
|
||||
return;
|
||||
}
|
||||
else if (type instanceof PsiWildcardType) {
|
||||
@@ -611,14 +617,14 @@ public class ChangeUtil implements Constants {
|
||||
}
|
||||
else {
|
||||
LOG.assertTrue(type instanceof PsiClassType);
|
||||
final PsiClassType classType = (PsiClassType) type;
|
||||
final PsiClassType classType = (PsiClassType)type;
|
||||
final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
|
||||
final PsiClass referencedClass = resolveResult.getElement();
|
||||
if (referencedClass == null) return;
|
||||
final ASTNode reference = typeElement.getFirstChildNode();
|
||||
LOG.assertTrue(reference.getElementType() == JAVA_CODE_REFERENCE);
|
||||
|
||||
encodeClassTypeInfoInReference((CompositeElement) reference, resolveResult.getElement(), resolveResult.getSubstitutor());
|
||||
encodeClassTypeInfoInReference((CompositeElement)reference, resolveResult.getElement(), resolveResult.getSubstitutor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,7 +654,7 @@ public class ChangeUtil implements Constants {
|
||||
if (referencedClass.hasModifierProperty(PsiModifier.STATIC)) return;
|
||||
final PsiClass outerClass = referencedClass.getContainingClass();
|
||||
if (outerClass != null) {
|
||||
encodeClassTypeInfoInReference((CompositeElement) qualifier, outerClass, substitutor);
|
||||
encodeClassTypeInfoInReference((CompositeElement)qualifier, outerClass, substitutor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -660,7 +666,7 @@ public class ChangeUtil implements Constants {
|
||||
ASTNode firstChild,
|
||||
final ASTNode lastChild,
|
||||
final ASTNode anchorBefore) {
|
||||
while(firstChild != lastChild){
|
||||
while (firstChild != lastChild) {
|
||||
final ASTNode next = firstChild.getTreeNext();
|
||||
parent.addChild(firstChild, anchorBefore);
|
||||
firstChild = next;
|
||||
@@ -668,9 +674,9 @@ public class ChangeUtil implements Constants {
|
||||
}
|
||||
|
||||
public static void replaceAll(LeafElement[] leafElements, LeafElement merged) {
|
||||
if(leafElements.length == 0) return;
|
||||
if (leafElements.length == 0) return;
|
||||
final CompositeElement parent = leafElements[0].getTreeParent();
|
||||
if(LOG.isDebugEnabled()){
|
||||
if (LOG.isDebugEnabled()) {
|
||||
for (int i = 0; i < leafElements.length; i++) {
|
||||
final ASTNode leafElement = leafElements[i];
|
||||
LOG.assertTrue(leafElement.getTreeParent() == parent);
|
||||
@@ -681,18 +687,18 @@ public class ChangeUtil implements Constants {
|
||||
final PsiFile containingFile = psiParent.getContainingFile();
|
||||
final PsiManagerImpl manager = (PsiManagerImpl)containingFile.getManager();
|
||||
final PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(manager);
|
||||
if(containingFile.isPhysical()){
|
||||
if (containingFile.isPhysical()) {
|
||||
event.setParent(psiParent);
|
||||
event.setFile(containingFile);
|
||||
event.setOffset(parent.getStartOffset());
|
||||
event.setOldLength(parent.getTextLength());
|
||||
manager.beforeChildrenChange(event);
|
||||
}
|
||||
TreeUtil.insertAfter(leafElements[0], merged);
|
||||
for (int i = 0; i < leafElements.length; i++) TreeUtil.remove(leafElements[i]);
|
||||
TreeUtil.insertAfter(leafElements[0], merged);
|
||||
for (int i = 0; i < leafElements.length; i++) TreeUtil.remove(leafElements[i]);
|
||||
|
||||
parent.subtreeChanged();
|
||||
if(containingFile.isPhysical()) manager.childrenChanged(event);
|
||||
if (containingFile.isPhysical()) manager.childrenChanged(event);
|
||||
checkConsistency(containingFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.lang.ASTNode;
|
||||
|
||||
//TODO: rename/regroup?
|
||||
|
||||
public class SharedImplUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.SharedImplUtil");
|
||||
|
||||
@@ -44,12 +45,12 @@ public class SharedImplUtil {
|
||||
|
||||
public static PsiFile getContainingFile(TreeElement thisElement) {
|
||||
TreeElement element;
|
||||
for(element = thisElement; element.getTreeParent() != null; element = element.getTreeParent()){
|
||||
for (element = thisElement; element.getTreeParent() != null; element = element.getTreeParent()) {
|
||||
}
|
||||
|
||||
if (element.getManager() == null) return null; // otherwise treeElementToPsi may crash!
|
||||
PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
if(psiElement instanceof DummyHolder) return psiElement.getContainingFile();
|
||||
if (psiElement instanceof DummyHolder) return psiElement.getContainingFile();
|
||||
if (!(psiElement instanceof PsiFile)) return null;
|
||||
return (PsiFile)psiElement;
|
||||
}
|
||||
@@ -66,18 +67,22 @@ public class SharedImplUtil {
|
||||
return file != null ? file.isWritable() : true;
|
||||
}
|
||||
|
||||
public static CharTable findCharTableByTree(ASTNode tree){
|
||||
while(tree != null){
|
||||
public static CharTable findCharTableByTree(ASTNode tree) {
|
||||
while (tree != null) {
|
||||
final CharTable userData = tree.getUserData(CharTable.CHAR_TABLE_KEY);
|
||||
if(userData != null) return userData;
|
||||
if(tree instanceof FileElement) return ((FileElement)tree).getCharTable();
|
||||
if (userData != null) return userData;
|
||||
if (tree instanceof FileElement) return ((FileElement)tree).getCharTable();
|
||||
tree = tree.getTreeParent();
|
||||
}
|
||||
LOG.assertTrue(false, "Invalid root element");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PsiElement addRange(PsiElement thisElement, PsiElement first, PsiElement last, ASTNode anchor, Boolean before) throws IncorrectOperationException{
|
||||
public static PsiElement addRange(PsiElement thisElement,
|
||||
PsiElement first,
|
||||
PsiElement last,
|
||||
ASTNode anchor,
|
||||
Boolean before) throws IncorrectOperationException {
|
||||
CheckUtil.checkWritable(thisElement);
|
||||
final CharTable table = findCharTableByTree(SourceTreeToPsiMap.psiElementToTree(thisElement));
|
||||
FileType fileType = thisElement.getContainingFile().getFileType();
|
||||
@@ -88,15 +93,17 @@ public class SharedImplUtil {
|
||||
ASTNode copyLast = null;
|
||||
ASTNode next = SourceTreeToPsiMap.psiElementToTree(last).getTreeNext();
|
||||
ASTNode parent = null;
|
||||
for(TreeElement element = SourceTreeToPsiMap.psiElementToTree(first); element != next; element = element.getTreeNext()){
|
||||
TreeElement elementCopy = ChangeUtil.copyElement(element, table);
|
||||
if (element == first){
|
||||
for (ASTNode element = SourceTreeToPsiMap.psiElementToTree(first); element != next; element = element.getTreeNext()) {
|
||||
TreeElement elementCopy = ChangeUtil.copyElement((TreeElement)element, table);
|
||||
if (element == first) {
|
||||
copyFirst = elementCopy;
|
||||
}
|
||||
if (element == last){
|
||||
if (element == last) {
|
||||
copyLast = elementCopy;
|
||||
}
|
||||
if(parent == null) parent = elementCopy.getTreeParent();
|
||||
if (parent == null) {
|
||||
parent = elementCopy.getTreeParent();
|
||||
}
|
||||
else {
|
||||
parent.addChild(elementCopy, null);
|
||||
helper.normalizeIndent(elementCopy);
|
||||
@@ -104,30 +111,30 @@ public class SharedImplUtil {
|
||||
}
|
||||
if (copyFirst == null) return null;
|
||||
copyFirst = ((CompositeElement)SourceTreeToPsiMap.psiElementToTree(thisElement)).addInternal(copyFirst, copyLast, anchor, before);
|
||||
for(TreeElement element = copyFirst; element != null; element = element.getTreeNext()){
|
||||
for (TreeElement element = copyFirst; element != null; element = element.getTreeNext()) {
|
||||
element = ChangeUtil.decodeInformation(element);
|
||||
if (element.getTreePrev() == null){
|
||||
if (element.getTreePrev() == null) {
|
||||
copyFirst = element;
|
||||
}
|
||||
}
|
||||
return SourceTreeToPsiMap.treeElementToPsi(copyFirst);
|
||||
}
|
||||
|
||||
public static PsiType getType(PsiVariable variable){
|
||||
public static PsiType getType(PsiVariable variable) {
|
||||
PsiTypeElement typeElement = variable.getTypeElement();
|
||||
int arrayCount = 0;
|
||||
ASTNode name = SourceTreeToPsiMap.psiElementToTree(variable.getNameIdentifier());
|
||||
Loop:
|
||||
for(ASTNode child = name.getTreeNext(); child != null; child = child.getTreeNext()){
|
||||
Loop:
|
||||
for (ASTNode child = name.getTreeNext(); child != null; child = child.getTreeNext()) {
|
||||
IElementType i = child.getElementType();
|
||||
if (i == ElementType.LBRACKET) {
|
||||
arrayCount++;
|
||||
}
|
||||
else if (i == ElementType.RBRACKET ||
|
||||
i == ElementType.WHITE_SPACE ||
|
||||
i == ElementType.C_STYLE_COMMENT ||
|
||||
i == ElementType.DOC_COMMENT ||
|
||||
i == ElementType.END_OF_LINE_COMMENT) {
|
||||
i == ElementType.WHITE_SPACE ||
|
||||
i == ElementType.C_STYLE_COMMENT ||
|
||||
i == ElementType.DOC_COMMENT ||
|
||||
i == ElementType.END_OF_LINE_COMMENT) {
|
||||
}
|
||||
else {
|
||||
break Loop;
|
||||
@@ -141,13 +148,13 @@ public class SharedImplUtil {
|
||||
type = ((PsiTypeElementImpl)typeElement).getDetachedType(variable);
|
||||
}
|
||||
|
||||
for(int i = 0; i < arrayCount; i++){
|
||||
for (int i = 0; i < arrayCount; i++) {
|
||||
type = type.createArrayType();
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static void normalizeBrackets(PsiVariable variable){
|
||||
public static void normalizeBrackets(PsiVariable variable) {
|
||||
CompositeElement variableElement = (CompositeElement)SourceTreeToPsiMap.psiElementToTree(variable);
|
||||
ASTNode type = variableElement.findChildByRole(ChildRole.TYPE);
|
||||
LOG.assertTrue(type.getTreeParent() == variableElement);
|
||||
@@ -157,7 +164,7 @@ public class SharedImplUtil {
|
||||
ASTNode lastBracket = null;
|
||||
int arrayCount = 0;
|
||||
ASTNode element = name;
|
||||
while(true){
|
||||
while (true) {
|
||||
element = TreeUtil.skipElements(element.getTreeNext(), ElementType.WHITE_SPACE_OR_COMMENT_BIT_SET);
|
||||
if (element == null || element.getElementType() != ElementType.LBRACKET) break;
|
||||
if (firstBracket == null) firstBracket = element;
|
||||
@@ -169,9 +176,9 @@ public class SharedImplUtil {
|
||||
lastBracket = element;
|
||||
}
|
||||
|
||||
if (firstBracket != null){
|
||||
if (firstBracket != null) {
|
||||
element = firstBracket;
|
||||
while(true){
|
||||
while (true) {
|
||||
ASTNode next = element.getTreeNext();
|
||||
variableElement.removeChild(element);
|
||||
if (element == lastBracket) break;
|
||||
@@ -180,7 +187,7 @@ public class SharedImplUtil {
|
||||
|
||||
CompositeElement newType = (CompositeElement)type.clone();
|
||||
final CharTable treeCharTable = SharedImplUtil.findCharTableByTree(type);
|
||||
for(int i = 0; i < arrayCount; i++){
|
||||
for (int i = 0; i < arrayCount; i++) {
|
||||
CompositeElement newType1 = Factory.createCompositeElement(ElementType.TYPE);
|
||||
TreeUtil.addChildren(newType1, newType);
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.intellij.util.CharTable;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.lang.ASTNode;
|
||||
|
||||
|
||||
public class PsiReferenceExpressionImpl extends CompositePsiElement implements PsiReferenceExpression, SourceJavaCodeReference {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl");
|
||||
|
||||
@@ -109,7 +108,7 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
IElementType parentType = _ref.getTreeParent() != null ? _ref.getTreeParent().getElementType() : null;
|
||||
final ResolveResult[] result = _ref._resolve(parentType);
|
||||
|
||||
if (incompleteCode && parentType != REFERENCE_EXPRESSION && result.length == 0){
|
||||
if (incompleteCode && parentType != REFERENCE_EXPRESSION && result.length == 0) {
|
||||
return _ref._resolve(REFERENCE_EXPRESSION);
|
||||
}
|
||||
return result;
|
||||
@@ -117,14 +116,14 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
|
||||
public ResolveResult[] resolve(PsiJavaReference ref, boolean incompleteCode) {
|
||||
final ResolveResult[] result = _resolve(ref, incompleteCode);
|
||||
if (result.length > 0 && result[0].getElement() instanceof PsiClass){
|
||||
if (result.length > 0 && result[0].getElement() instanceof PsiClass) {
|
||||
final PsiType[] parameters = ((PsiJavaCodeReferenceElement)ref).getTypeParameters();
|
||||
final ResolveResult[] newResult = new ResolveResult[result.length];
|
||||
for(int i = 0; i < result.length; i++){
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
final CandidateInfo resolveResult = (CandidateInfo)result[i];
|
||||
newResult[i] = new CandidateInfo(
|
||||
resolveResult,
|
||||
((PsiSubstitutorEx)resolveResult.getSubstitutor()).inplacePutAll((PsiClass)resolveResult.getElement(), parameters)
|
||||
((PsiSubstitutorEx)resolveResult.getSubstitutor()).inplacePutAll((PsiClass)resolveResult.getElement(), parameters)
|
||||
);
|
||||
}
|
||||
return newResult;
|
||||
@@ -134,8 +133,9 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
}
|
||||
|
||||
private ResolveResult[] _resolve(IElementType parentType) {
|
||||
if (parentType == null)
|
||||
if (parentType == null) {
|
||||
parentType = getTreeParent() != null ? getTreeParent().getElementType() : null;
|
||||
}
|
||||
if (parentType == REFERENCE_EXPRESSION) {
|
||||
{
|
||||
{
|
||||
@@ -191,7 +191,8 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
}
|
||||
else if (parentType == SWITCH_LABEL_STATEMENT) {
|
||||
if (!isQualified()) {
|
||||
PsiSwitchStatement switchStatement = ((PsiSwitchLabelStatement)SourceTreeToPsiMap.treeElementToPsi(getTreeParent())).getEnclosingSwitchStatement();
|
||||
PsiSwitchStatement switchStatement =
|
||||
((PsiSwitchLabelStatement)SourceTreeToPsiMap.treeElementToPsi(getTreeParent())).getEnclosingSwitchStatement();
|
||||
if (switchStatement != null) {
|
||||
PsiExpression expression = switchStatement.getExpression();
|
||||
if (expression != null && expression.getType() instanceof PsiClassType) {
|
||||
@@ -230,7 +231,7 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
|
||||
public ResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final PsiManager manager = getManager();
|
||||
if (manager == null){
|
||||
if (manager == null) {
|
||||
LOG.assertTrue(false, "getManager() == null!");
|
||||
return null;
|
||||
}
|
||||
@@ -260,13 +261,13 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
public PsiType getType() {
|
||||
ResolveResult result = advancedResolve(false);
|
||||
PsiElement resolve = result.getElement();
|
||||
if (resolve == null){
|
||||
if (resolve == null) {
|
||||
ASTNode refName = findChildByRole(ChildRole.REFERENCE_NAME);
|
||||
if (refName != null && refName.getText().equals(LENGTH)){
|
||||
if (refName != null && refName.getText().equals(LENGTH)) {
|
||||
ASTNode qualifier = findChildByRole(ChildRole.QUALIFIER);
|
||||
if (qualifier != null && ElementType.EXPRESSION_BIT_SET.isInSet(qualifier.getElementType())){
|
||||
if (qualifier != null && ElementType.EXPRESSION_BIT_SET.isInSet(qualifier.getElementType())) {
|
||||
PsiType type = ((PsiExpression)SourceTreeToPsiMap.treeElementToPsi(qualifier)).getType();
|
||||
if (type != null && type instanceof PsiArrayType){
|
||||
if (type != null && type instanceof PsiArrayType) {
|
||||
return PsiType.INT;
|
||||
}
|
||||
}
|
||||
@@ -275,14 +276,14 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
}
|
||||
|
||||
final PsiType ret;
|
||||
if (resolve instanceof PsiVariable){
|
||||
if (resolve instanceof PsiVariable) {
|
||||
PsiType type = ((PsiVariable)resolve).getType();
|
||||
ret = type instanceof PsiEllipsisType ? ((PsiEllipsisType)type).toArrayType() : type;
|
||||
}
|
||||
else if (resolve instanceof PsiMethod){
|
||||
else if (resolve instanceof PsiMethod) {
|
||||
ret = ((PsiMethod)resolve).getReturnType();
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -344,15 +345,15 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
}
|
||||
|
||||
public PsiReferenceParameterList getParameterList() {
|
||||
return (PsiReferenceParameterList) findChildByRoleAsPsiElement(ChildRole.REFERENCE_PARAMETER_LIST);
|
||||
return (PsiReferenceParameterList)findChildByRoleAsPsiElement(ChildRole.REFERENCE_PARAMETER_LIST);
|
||||
}
|
||||
|
||||
public int getTextOffset() {
|
||||
ASTNode refName = findChildByRole(ChildRole.REFERENCE_NAME);
|
||||
if (refName != null){
|
||||
if (refName != null) {
|
||||
return refName.getStartOffset();
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return super.getTextOffset();
|
||||
}
|
||||
}
|
||||
@@ -366,7 +367,8 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
return renameDirectly(newElementName);
|
||||
}
|
||||
PsiElement currentFileResolveScope = resolveResult.getCurrentFileResolveScope();
|
||||
if (!(currentFileResolveScope instanceof PsiImportStaticStatement)|| ((PsiImportStaticStatement)currentFileResolveScope).isOnDemand()) {
|
||||
if (!(currentFileResolveScope instanceof PsiImportStaticStatement) ||
|
||||
((PsiImportStaticStatement)currentFileResolveScope).isOnDemand()) {
|
||||
return renameDirectly(newElementName);
|
||||
}
|
||||
final PsiImportStaticStatement importStaticStatement = (PsiImportStaticStatement)currentFileResolveScope;
|
||||
@@ -381,13 +383,13 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
final PsiElementFactory factory = getManager().getElementFactory();
|
||||
final PsiReferenceExpression expression = (PsiReferenceExpression)factory.createExpressionFromText("X." + newElementName, this);
|
||||
final PsiReferenceExpression result = ((PsiReferenceExpression)this.replace(expression));
|
||||
((PsiReferenceExpression)result.getQualifierExpression()).bindToElement(psiClass);
|
||||
((PsiReferenceExpression)result.getQualifierExpression()).bindToElement(psiClass);
|
||||
return result;
|
||||
}
|
||||
|
||||
private PsiElement renameDirectly(String newElementName) throws IncorrectOperationException {
|
||||
PsiElement oldIdentifier = findChildByRoleAsPsiElement(ChildRole.REFERENCE_NAME);
|
||||
if (oldIdentifier == null){
|
||||
if (oldIdentifier == null) {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
PsiIdentifier identifier = getManager().getElementFactory().createIdentifier(newElementName);
|
||||
@@ -401,12 +403,12 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
if (isReferenceTo(element)) return this;
|
||||
|
||||
PsiManager manager = getManager();
|
||||
if (element instanceof PsiClass){
|
||||
if (element instanceof PsiClass) {
|
||||
String qName = ((PsiClass)element).getQualifiedName();
|
||||
if (qName == null){
|
||||
if (qName == null) {
|
||||
qName = ((PsiClass)element).getName();
|
||||
final PsiClass psiClass = getManager().getResolveHelper().resolveReferencedClass(qName, this);
|
||||
if(!getManager().areElementsEquivalent(psiClass, element)){
|
||||
if (!getManager().areElementsEquivalent(psiClass, element)) {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
}
|
||||
@@ -420,16 +422,16 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
TreeElement ref = ExpressionParsing.parseExpressionText(manager, qName.toCharArray(), 0, qName.toCharArray().length, table);
|
||||
getTreeParent().replaceChildInternal(this, ref);
|
||||
CodeStyleManagerEx codeStyleManager = (CodeStyleManagerEx)manager.getCodeStyleManager();
|
||||
if (!wasFullyQualified){
|
||||
ref = SourceTreeToPsiMap.psiElementToTree(
|
||||
if (!wasFullyQualified) {
|
||||
ref = (TreeElement)SourceTreeToPsiMap.psiElementToTree(
|
||||
codeStyleManager.shortenClassReferences(SourceTreeToPsiMap.treeElementToPsi(ref), CodeStyleManagerEx.UNCOMPLETE_CODE)
|
||||
);
|
||||
}
|
||||
return SourceTreeToPsiMap.treeElementToPsi(ref);
|
||||
}
|
||||
else if (element instanceof PsiPackage){
|
||||
else if (element instanceof PsiPackage) {
|
||||
String qName = ((PsiPackage)element).getQualifiedName();
|
||||
if (qName.length() == 0){
|
||||
if (qName.length() == 0) {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
final CharTable table = SharedImplUtil.findCharTableByTree(getTreeParent());
|
||||
@@ -437,7 +439,7 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
getTreeParent().replaceChildInternal(this, ref);
|
||||
return SourceTreeToPsiMap.treeElementToPsi(ref);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
}
|
||||
@@ -452,38 +454,38 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
}
|
||||
|
||||
public void deleteChildInternal(ASTNode child) {
|
||||
if (getChildRole(child) == ChildRole.QUALIFIER){
|
||||
if (getChildRole(child) == ChildRole.QUALIFIER) {
|
||||
ASTNode dot = findChildByRole(ChildRole.DOT);
|
||||
super.deleteChildInternal(child);
|
||||
deleteChildInternal(dot);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
super.deleteChildInternal(child);
|
||||
}
|
||||
}
|
||||
|
||||
public ASTNode findChildByRole(int role) {
|
||||
LOG.assertTrue(ChildRole.isUnique(role));
|
||||
switch(role){
|
||||
default:
|
||||
return null;
|
||||
switch (role) {
|
||||
default:
|
||||
return null;
|
||||
|
||||
case ChildRole.REFERENCE_NAME:
|
||||
return getChildRole(getLastChildNode()) == role ? getLastChildNode() : null;
|
||||
case ChildRole.REFERENCE_NAME:
|
||||
return getChildRole(getLastChildNode()) == role ? getLastChildNode() : null;
|
||||
|
||||
case ChildRole.QUALIFIER:
|
||||
if (getChildRole(getFirstChildNode()) == ChildRole.QUALIFIER){
|
||||
return getFirstChildNode();
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
case ChildRole.QUALIFIER:
|
||||
if (getChildRole(getFirstChildNode()) == ChildRole.QUALIFIER) {
|
||||
return getFirstChildNode();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
case ChildRole.REFERENCE_PARAMETER_LIST:
|
||||
return TreeUtil.findChild(this, REFERENCE_PARAMETER_LIST);
|
||||
case ChildRole.REFERENCE_PARAMETER_LIST:
|
||||
return TreeUtil.findChild(this, REFERENCE_PARAMETER_LIST);
|
||||
|
||||
case ChildRole.DOT:
|
||||
return TreeUtil.findChild(this, DOT);
|
||||
case ChildRole.DOT:
|
||||
return TreeUtil.findChild(this, DOT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,7 +532,7 @@ public class PsiReferenceExpressionImpl extends CompositePsiElement implements P
|
||||
PsiTypeElement[] typeElements = parameterList.getTypeParameterElements();
|
||||
|
||||
PsiType[] types = new PsiType[typeElements.length];
|
||||
for(int i = 0; i < types.length; i++){
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
types[i] = typeElements[i].getType();
|
||||
}
|
||||
return types;
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package com.intellij.psi.impl.source.xml;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.impl.meta.MetaRegistry;
|
||||
import com.intellij.psi.impl.source.tree.ChildRole;
|
||||
import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
import com.intellij.psi.meta.PsiMetaData;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.xml.XmlAttributeDecl;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.psi.xml.XmlElement;
|
||||
import com.intellij.psi.xml.XmlEnumeratedType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.lang.ASTNode;
|
||||
|
||||
/**
|
||||
* @author Mike
|
||||
@@ -52,7 +51,7 @@ public class XmlAttributeDeclImpl extends XmlElementImpl implements XmlAttribute
|
||||
}
|
||||
|
||||
public XmlElement getNameElement() {
|
||||
return (XmlElement)findElementByTokenType(XML_NAME);
|
||||
return findElementByTokenType(XML_NAME);
|
||||
}
|
||||
|
||||
public boolean isAttributeRequired() {
|
||||
@@ -77,10 +76,10 @@ public class XmlAttributeDeclImpl extends XmlElementImpl implements XmlAttribute
|
||||
|
||||
public XmlElement[] getEnumeratedValues() {
|
||||
XmlEnumeratedType enumeratedType = (XmlEnumeratedType)findElementByTokenType(XML_ENUMERATED_TYPE);
|
||||
if (enumeratedType != null){
|
||||
if (enumeratedType != null) {
|
||||
return enumeratedType.getEnumeratedValues();
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return XmlElement.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
@@ -88,13 +87,13 @@ public class XmlAttributeDeclImpl extends XmlElementImpl implements XmlAttribute
|
||||
public boolean isIdAttribute() {
|
||||
final PsiElement elementType = findElementType();
|
||||
|
||||
return elementType!=null && elementType.getText().equals("ID");
|
||||
return elementType != null && elementType.getText().equals("ID");
|
||||
}
|
||||
|
||||
private PsiElement findElementType() {
|
||||
final PsiElement elementName = findElementByTokenType(XML_NAME);
|
||||
final PsiElement nextSibling = (elementName!=null)?elementName.getNextSibling():null;
|
||||
final PsiElement elementType = (nextSibling instanceof PsiWhiteSpace)?nextSibling.getNextSibling():nextSibling;
|
||||
final PsiElement nextSibling = (elementName != null) ? elementName.getNextSibling() : null;
|
||||
final PsiElement elementType = (nextSibling instanceof PsiWhiteSpace) ? nextSibling.getNextSibling() : nextSibling;
|
||||
|
||||
return elementType;
|
||||
}
|
||||
@@ -102,7 +101,7 @@ public class XmlAttributeDeclImpl extends XmlElementImpl implements XmlAttribute
|
||||
public boolean isIdRefAttribute() {
|
||||
final PsiElement elementType = findElementType();
|
||||
|
||||
return elementType!=null && elementType.getText().equals("IDREF");
|
||||
return elementType != null && elementType.getText().equals("IDREF");
|
||||
}
|
||||
|
||||
public PsiMetaData getMetaData() {
|
||||
@@ -119,6 +118,6 @@ public class XmlAttributeDeclImpl extends XmlElementImpl implements XmlAttribute
|
||||
|
||||
public String getName() {
|
||||
XmlElement name = getNameElement();
|
||||
return (name != null )? name.getText():null;
|
||||
return (name != null) ? name.getText() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
public class XmlTextImpl extends XmlElementImpl implements XmlText {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.xml.XmlTextImpl");
|
||||
private String myDisplayText = null;
|
||||
|
||||
@@ -45,7 +45,8 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
final XmlText element = getManager().getElementFactory().createDisplayText(text.substring(phyIndex));
|
||||
getParent().addAfter(element, this);
|
||||
return element;
|
||||
} catch (IncorrectOperationException e) {
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return null;
|
||||
@@ -54,35 +55,38 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
private int[] myGaps = null;
|
||||
|
||||
public String getValue() {
|
||||
if(myDisplayText != null) return myDisplayText;
|
||||
if (myDisplayText != null) return myDisplayText;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
ASTNode child = getFirstChildNode();
|
||||
final List<Integer> gaps = new ArrayList<Integer>();
|
||||
while(child != null){
|
||||
while (child != null) {
|
||||
final int start = buffer.length();
|
||||
IElementType elementType = child.getElementType();
|
||||
if(elementType == XmlElementType.XML_CDATA){
|
||||
if (elementType == XmlElementType.XML_CDATA) {
|
||||
final ASTNode cdata = child;
|
||||
child = cdata.getFirstChildNode();
|
||||
}
|
||||
else if(elementType == XmlTokenType.XML_CHAR_ENTITY_REF){
|
||||
else if (elementType == XmlTokenType.XML_CHAR_ENTITY_REF) {
|
||||
buffer.append(getChar(child.getText()));
|
||||
}
|
||||
else if(elementType == XmlTokenType.XML_WHITE_SPACE
|
||||
|| elementType == XmlTokenType.XML_DATA_CHARACTERS
|
||||
|| elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN){
|
||||
else if (elementType == XmlTokenType.XML_WHITE_SPACE
|
||||
|| elementType == XmlTokenType.XML_DATA_CHARACTERS
|
||||
|| elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
|
||||
buffer.append(child.getText());
|
||||
}
|
||||
int end = buffer.length();
|
||||
int originalLength = child.getTextLength();
|
||||
if(end - start != originalLength){
|
||||
if (end - start != originalLength) {
|
||||
gaps.add(new Integer(start));
|
||||
gaps.add(new Integer(originalLength - (end - start)));
|
||||
}
|
||||
final ASTNode next = child.getTreeNext();
|
||||
if(next == null && child.getTreeParent().getElementType() == XmlElementType.XML_CDATA)
|
||||
if (next == null && child.getTreeParent().getElementType() == XmlElementType.XML_CDATA) {
|
||||
child = child.getTreeParent().getTreeNext();
|
||||
else child = next;
|
||||
}
|
||||
else {
|
||||
child = next;
|
||||
}
|
||||
}
|
||||
myGaps = new int[gaps.size()];
|
||||
int index = 0;
|
||||
@@ -97,7 +101,7 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
|
||||
private char getChar(String text) {
|
||||
//LOG.assertTrue(text.startsWith("&#") && text.endsWith(";"));
|
||||
if(text.charAt(1) != '#'){
|
||||
if (text.charAt(1) != '#') {
|
||||
text = text.substring(1, text.length() - 1);
|
||||
return XmlTagTextUtil.getCharacterByEntityName(text).charValue();
|
||||
}
|
||||
@@ -110,18 +114,18 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
else {
|
||||
code = Integer.parseInt(text);
|
||||
}
|
||||
return (char) code;
|
||||
return (char)code;
|
||||
}
|
||||
|
||||
public int physicalToDisplay(int offset) {
|
||||
getValue();
|
||||
if(myGaps.length == 0) return offset;
|
||||
if (myGaps.length == 0) return offset;
|
||||
int gapIndex = 0;
|
||||
int displayIndex = 0;
|
||||
int physicalOffset = 0;
|
||||
|
||||
while(physicalOffset < offset){
|
||||
if(displayIndex == getGapStartOffset(gapIndex)){
|
||||
while (physicalOffset < offset) {
|
||||
if (displayIndex == getGapStartOffset(gapIndex)) {
|
||||
final int gap = getGap(gapIndex);
|
||||
physicalOffset += gap;
|
||||
gapIndex++;
|
||||
@@ -136,136 +140,143 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
|
||||
public int displayToPhysical(int displayIndex) {
|
||||
getValue();
|
||||
if(myGaps.length == 0) return displayIndex;
|
||||
if (myGaps.length == 0) return displayIndex;
|
||||
int gapIndex = 0;
|
||||
int displayOffset = 0;
|
||||
int physicalOffset = 0;
|
||||
while(displayOffset <= displayIndex){
|
||||
if(displayOffset > getGapStartOffset(gapIndex)){
|
||||
while (displayOffset <= displayIndex) {
|
||||
if (displayOffset > getGapStartOffset(gapIndex)) {
|
||||
final int gap = getGap(gapIndex);
|
||||
physicalOffset += gap;
|
||||
gapIndex++;
|
||||
}
|
||||
else if(displayOffset < displayIndex){
|
||||
else if (displayOffset < displayIndex) {
|
||||
physicalOffset++;
|
||||
displayOffset++;
|
||||
}
|
||||
else displayOffset++;
|
||||
else {
|
||||
displayOffset++;
|
||||
}
|
||||
}
|
||||
return physicalOffset;
|
||||
}
|
||||
|
||||
public void setValue(String s) throws IncorrectOperationException{
|
||||
public void setValue(String s) throws IncorrectOperationException {
|
||||
final XmlTextImpl element = (XmlTextImpl)getManager().getElementFactory().createDisplayText(s);
|
||||
replace(element);
|
||||
}
|
||||
|
||||
public XmlElement insertAtOffset(final XmlElement element, int physicalOffset) throws IncorrectOperationException{
|
||||
public XmlElement insertAtOffset(final XmlElement element, int physicalOffset) throws IncorrectOperationException {
|
||||
final PsiElement elementAt = findElementAt(physicalOffset);
|
||||
final int localOffset;
|
||||
if(elementAt != null)
|
||||
if (elementAt != null) {
|
||||
localOffset = physicalOffset - elementAt.getStartOffsetInParent();
|
||||
else
|
||||
}
|
||||
else {
|
||||
localOffset = element.getTextLength();
|
||||
}
|
||||
final PomModel model = getManager().getProject().getModel();
|
||||
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
|
||||
final ASTNode[] retHolder = new ASTNode[1];
|
||||
final TreeElement insertedElement = SourceTreeToPsiMap.psiElementToTree(element);
|
||||
final ASTNode insertedElement = SourceTreeToPsiMap.psiElementToTree(element);
|
||||
final String oldText = getText();
|
||||
final ASTNode second;
|
||||
if(elementAt != null){
|
||||
if (elementAt != null) {
|
||||
final ASTNode treeElement = SourceTreeToPsiMap.psiElementToTree(elementAt);
|
||||
second = split((LeafElement)treeElement, localOffset);
|
||||
}
|
||||
else second = null;
|
||||
else {
|
||||
second = null;
|
||||
}
|
||||
|
||||
|
||||
if(element instanceof XmlTagChild){
|
||||
if (element instanceof XmlTagChild) {
|
||||
final XmlElement parent = getParent();
|
||||
if(second != null){
|
||||
if (second != null) {
|
||||
final XmlText xmlText = getManager().getElementFactory().createTagFromText("<tag> </tag>").getValue().getTextElements()[0];
|
||||
final ASTNode compositeElement = SourceTreeToPsiMap.psiElementToTree(xmlText);
|
||||
TreeUtil.removeRange((TreeElement)compositeElement.getFirstChildNode(), null);
|
||||
model.runTransaction(new PomTransaction() {
|
||||
public PomModelEvent run(){
|
||||
ASTNode current = second;
|
||||
while(current != null){
|
||||
final ASTNode next = current.getTreeNext();
|
||||
removeChild(current);
|
||||
compositeElement.addChild(current, null);
|
||||
current = next;
|
||||
}
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
public PomModelEvent run() {
|
||||
ASTNode current = second;
|
||||
while (current != null) {
|
||||
final ASTNode next = current.getTreeNext();
|
||||
removeChild(current);
|
||||
compositeElement.addChild(current, null);
|
||||
current = next;
|
||||
}
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
|
||||
XmlElement xmlElement = (XmlElement)parent.addAfter(element, this);
|
||||
parent.addAfter(xmlText, xmlElement);
|
||||
return xmlElement;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return (XmlElement)parent.addAfter(element, this);
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
model.runTransaction(new PomTransaction() {
|
||||
public PomModelEvent run() {
|
||||
retHolder[0] = addInternal(insertedElement, insertedElement, retHolder[0], Boolean.TRUE);
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
public PomModelEvent run() {
|
||||
retHolder[0] = addInternal((TreeElement)insertedElement, insertedElement, retHolder[0], Boolean.TRUE);
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
}
|
||||
return (XmlElement)SourceTreeToPsiMap.treeElementToPsi(retHolder[0]);
|
||||
}
|
||||
|
||||
// public XmlElement insertAtOffset(final XmlElement element, int physicalOffset) throws IncorrectOperationException{
|
||||
// final PomModel model = getManager().getProject().getModel();
|
||||
// final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
|
||||
// final int displayOffset = physicalToDisplay(physicalOffset);
|
||||
// final String value = getValue();
|
||||
// final String part1, part2;
|
||||
// if(element instanceof XmlText){
|
||||
// part1 = value.substring(0, displayOffset) + ((XmlText) element).getValue() + value.substring(displayOffset);
|
||||
// part2 = null;
|
||||
// }
|
||||
// else{
|
||||
// part1 = value.substring(0, displayOffset);
|
||||
// part2 = value.substring(displayOffset);
|
||||
// }
|
||||
// if(part2 != null){
|
||||
// if(part1.length() > 0){
|
||||
// setValue(part1);
|
||||
// final PsiElement elementCopy = getParent().addAfter(element, this);
|
||||
// if(part2.length() > 0){
|
||||
// final FileElement treeElement = new DummyHolder(null, null, SharedImplUtil.findCharTableByTree(this)).getTreeElement();
|
||||
// final XmlTextImpl newText = new XmlTextImpl();
|
||||
// TreeUtil.addChildren(treeElement, newText);
|
||||
// TreeUtil.addChildren(newText, createElementsByDisplayText(part2, getPolicy()));
|
||||
// getParent().addAfter(newText, elementCopy);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// getParent().addBefore(element, this);
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// setValue(part1);
|
||||
// }
|
||||
// return this;
|
||||
// }
|
||||
// public XmlElement insertAtOffset(final XmlElement element, int physicalOffset) throws IncorrectOperationException{
|
||||
// final PomModel model = getManager().getProject().getModel();
|
||||
// final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
|
||||
// final int displayOffset = physicalToDisplay(physicalOffset);
|
||||
// final String value = getValue();
|
||||
// final String part1, part2;
|
||||
// if(element instanceof XmlText){
|
||||
// part1 = value.substring(0, displayOffset) + ((XmlText) element).getValue() + value.substring(displayOffset);
|
||||
// part2 = null;
|
||||
// }
|
||||
// else{
|
||||
// part1 = value.substring(0, displayOffset);
|
||||
// part2 = value.substring(displayOffset);
|
||||
// }
|
||||
// if(part2 != null){
|
||||
// if(part1.length() > 0){
|
||||
// setValue(part1);
|
||||
// final PsiElement elementCopy = getParent().addAfter(element, this);
|
||||
// if(part2.length() > 0){
|
||||
// final FileElement treeElement = new DummyHolder(null, null, SharedImplUtil.findCharTableByTree(this)).getTreeElement();
|
||||
// final XmlTextImpl newText = new XmlTextImpl();
|
||||
// TreeUtil.addChildren(treeElement, newText);
|
||||
// TreeUtil.addChildren(newText, createElementsByDisplayText(part2, getPolicy()));
|
||||
// getParent().addAfter(newText, elementCopy);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// getParent().addBefore(element, this);
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// setValue(part1);
|
||||
// }
|
||||
// return this;
|
||||
// }
|
||||
|
||||
private int getPolicy() {
|
||||
return CDATA_ON_TEXT;
|
||||
}
|
||||
|
||||
private static LeafElement split(LeafElement element, int offset) throws IncorrectOperationException{
|
||||
private static LeafElement split(LeafElement element, int offset) throws IncorrectOperationException {
|
||||
final CharTable table = SharedImplUtil.findCharTableByTree(element);
|
||||
int textLength = element.getTextLength(table);
|
||||
if(textLength < offset) throw new ArrayIndexOutOfBoundsException(offset);
|
||||
if(offset == 0 || textLength == offset) return element;
|
||||
if(element.getElementType() != XmlTokenType.XML_DATA_CHARACTERS
|
||||
&& element.getElementType() != XmlTokenType.XML_WHITE_SPACE)
|
||||
if (textLength < offset) throw new ArrayIndexOutOfBoundsException(offset);
|
||||
if (offset == 0 || textLength == offset) return element;
|
||||
if (element.getElementType() != XmlTokenType.XML_DATA_CHARACTERS
|
||||
&& element.getElementType() != XmlTokenType.XML_WHITE_SPACE) {
|
||||
throw new IncorrectOperationException("Element " + element.getElementType() + " can not be split!");
|
||||
}
|
||||
final char[] buffer = new char[textLength];
|
||||
element.copyTo(buffer, 0);
|
||||
final LeafElement firstPart = Factory.createSingleLeafElement(element.getElementType(), buffer, 0, offset, table, null);
|
||||
@@ -276,7 +287,7 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
return secondPart;
|
||||
}
|
||||
|
||||
public void insertText(String text, int displayOffset) throws IncorrectOperationException{
|
||||
public void insertText(String text, int displayOffset) throws IncorrectOperationException {
|
||||
final XmlText displayText = getManager().getElementFactory().createDisplayText(text);
|
||||
final int phyOffset = displayToPhysical(displayOffset);
|
||||
insertAtOffset(displayText, phyOffset);
|
||||
@@ -288,77 +299,83 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
final PomModel model = getProject().getModel();
|
||||
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
|
||||
final CharTable table = SharedImplUtil.findCharTableByTree(this);
|
||||
if(start == end) return;
|
||||
if (start == end) return;
|
||||
|
||||
try {
|
||||
model.runTransaction(new PomTransaction() {
|
||||
public PomModelEvent run() throws IncorrectOperationException {
|
||||
final String oldText = getText();
|
||||
public PomModelEvent run() throws IncorrectOperationException {
|
||||
final String oldText = getText();
|
||||
|
||||
final LeafElement firstAffectedLeaf = findLeafElementAt(start);
|
||||
final LeafElement lastAffectedLeaf;
|
||||
final int lastAffectedLeafOffset;
|
||||
final int startOffsetInStartToken = start - firstAffectedLeaf.getStartOffsetInParent();
|
||||
{
|
||||
// remove elements inside the affected area
|
||||
LeafElement current = firstAffectedLeaf;
|
||||
int endOffset = current.getStartOffsetInParent();
|
||||
final LeafElement firstAffectedLeaf = findLeafElementAt(start);
|
||||
final LeafElement lastAffectedLeaf;
|
||||
final int lastAffectedLeafOffset;
|
||||
final int startOffsetInStartToken = start - firstAffectedLeaf.getStartOffsetInParent();
|
||||
{
|
||||
// remove elements inside the affected area
|
||||
LeafElement current = firstAffectedLeaf;
|
||||
int endOffset = current.getStartOffsetInParent();
|
||||
|
||||
while(current != null && (endOffset += current.getTextLength(table)) <= end){
|
||||
final LeafElement toDelete = current;
|
||||
current = (LeafElement)current.getTreeNext();
|
||||
if(toDelete != firstAffectedLeaf) removeChild(toDelete);
|
||||
}
|
||||
lastAffectedLeaf = current;
|
||||
lastAffectedLeafOffset = endOffset - (current != null ? current.getTextLength(table) : 0);
|
||||
}
|
||||
while (current != null && (endOffset += current.getTextLength(table)) <= end) {
|
||||
final LeafElement toDelete = current;
|
||||
current = (LeafElement)current.getTreeNext();
|
||||
if (toDelete != firstAffectedLeaf) removeChild(toDelete);
|
||||
}
|
||||
lastAffectedLeaf = current;
|
||||
lastAffectedLeafOffset = endOffset - (current != null ? current.getTextLength(table) : 0);
|
||||
}
|
||||
|
||||
LeafElement tokenToChange;
|
||||
int deletedAreaStartOffset = 0;
|
||||
int deletedAreaEndOffset = 0;
|
||||
if(lastAffectedLeafOffset < end && lastAffectedLeaf != firstAffectedLeaf){
|
||||
// merging tokens
|
||||
final LeafElement merged = mergeElements(firstAffectedLeaf, lastAffectedLeaf, table);
|
||||
if(merged == null){
|
||||
removeChild(split(firstAffectedLeaf, startOffsetInStartToken));
|
||||
removeChild(split(lastAffectedLeaf, end - lastAffectedLeafOffset).getTreePrev());
|
||||
}
|
||||
else{
|
||||
ChangeUtil.replaceAll(new LeafElement[]{firstAffectedLeaf, lastAffectedLeaf}, merged);
|
||||
deletedAreaStartOffset = startOffsetInStartToken;
|
||||
deletedAreaEndOffset = end - lastAffectedLeafOffset + firstAffectedLeaf.getTextLength(table) - startOffsetInStartToken;
|
||||
}
|
||||
tokenToChange = merged;
|
||||
}
|
||||
else{
|
||||
// replacing first token
|
||||
tokenToChange = firstAffectedLeaf;
|
||||
final int textLength = firstAffectedLeaf.getTextLength(table);
|
||||
deletedAreaStartOffset = startOffsetInStartToken;
|
||||
deletedAreaEndOffset = Math.min(end - firstAffectedLeaf.getStartOffsetInParent(), textLength);
|
||||
}
|
||||
LeafElement tokenToChange;
|
||||
int deletedAreaStartOffset = 0;
|
||||
int deletedAreaEndOffset = 0;
|
||||
if (lastAffectedLeafOffset < end && lastAffectedLeaf != firstAffectedLeaf) {
|
||||
// merging tokens
|
||||
final LeafElement merged = mergeElements(firstAffectedLeaf, lastAffectedLeaf, table);
|
||||
if (merged == null) {
|
||||
removeChild(split(firstAffectedLeaf, startOffsetInStartToken));
|
||||
removeChild(split(lastAffectedLeaf, end - lastAffectedLeafOffset).getTreePrev());
|
||||
}
|
||||
else {
|
||||
ChangeUtil.replaceAll(new LeafElement[]{firstAffectedLeaf, lastAffectedLeaf}, merged);
|
||||
deletedAreaStartOffset = startOffsetInStartToken;
|
||||
deletedAreaEndOffset = end - lastAffectedLeafOffset + firstAffectedLeaf.getTextLength(table) -
|
||||
startOffsetInStartToken;
|
||||
}
|
||||
tokenToChange = merged;
|
||||
}
|
||||
else {
|
||||
// replacing first token
|
||||
tokenToChange = firstAffectedLeaf;
|
||||
final int textLength = firstAffectedLeaf.getTextLength(table);
|
||||
deletedAreaStartOffset = startOffsetInStartToken;
|
||||
deletedAreaEndOffset = Math.min(end - firstAffectedLeaf.getStartOffsetInParent(), textLength);
|
||||
}
|
||||
|
||||
if(tokenToChange != null){
|
||||
final int textLength = tokenToChange.getTextLength(table);
|
||||
if(deletedAreaStartOffset > 0 || deletedAreaEndOffset < textLength) {
|
||||
String text = tokenToChange.getText(table);
|
||||
text = text.substring(0, deletedAreaStartOffset) + text.substring(deletedAreaEndOffset);
|
||||
final LeafElement newLeaf = Factory.createSingleLeafElement(firstAffectedLeaf.getElementType(),
|
||||
text.toCharArray(), 0, text.length(), table, null);
|
||||
replaceChild(tokenToChange, newLeaf);
|
||||
}
|
||||
else{
|
||||
final ASTNode treeNext = tokenToChange.getTreeNext();
|
||||
final ASTNode treePrev = tokenToChange.getTreePrev();
|
||||
final LeafElement merged = mergeElements((LeafElement)treePrev, (LeafElement)treeNext, table);
|
||||
removeChild(tokenToChange);
|
||||
if(merged != null) ChangeUtil.replaceAll(new LeafElement[]{(LeafElement)treePrev, (LeafElement)treeNext}, merged);
|
||||
}
|
||||
}
|
||||
if (tokenToChange != null) {
|
||||
final int textLength = tokenToChange.getTextLength(table);
|
||||
if (deletedAreaStartOffset > 0 || deletedAreaEndOffset < textLength) {
|
||||
String text = tokenToChange.getText(table);
|
||||
text = text.substring(0, deletedAreaStartOffset) + text.substring(deletedAreaEndOffset);
|
||||
final LeafElement newLeaf = Factory.createSingleLeafElement(firstAffectedLeaf.getElementType(),
|
||||
text.toCharArray(), 0, text.length(), table,
|
||||
null);
|
||||
replaceChild(tokenToChange, newLeaf);
|
||||
}
|
||||
else {
|
||||
final ASTNode treeNext = tokenToChange.getTreeNext();
|
||||
final ASTNode treePrev = tokenToChange.getTreePrev();
|
||||
final LeafElement merged = mergeElements((LeafElement)treePrev, (LeafElement)treeNext, table);
|
||||
removeChild(tokenToChange);
|
||||
if (merged != null) {
|
||||
ChangeUtil.replaceAll(new LeafElement[]{(LeafElement)treePrev,
|
||||
(LeafElement)treeNext},
|
||||
merged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
@@ -369,30 +386,30 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
return (XmlElement)super.getParent();
|
||||
}
|
||||
|
||||
private int getGapStartOffset(int gapIndex){
|
||||
private int getGapStartOffset(int gapIndex) {
|
||||
int index = gapIndex * 2;
|
||||
return index < myGaps.length ? myGaps[index] : Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
private int getGap(int gapIndex){
|
||||
private int getGap(int gapIndex) {
|
||||
return myGaps[gapIndex * 2 + 1];
|
||||
}
|
||||
|
||||
public XmlTag getParentTag() {
|
||||
final XmlElement parent = getParent();
|
||||
if(parent instanceof XmlTag) return (XmlTag)parent;
|
||||
if (parent instanceof XmlTag) return (XmlTag)parent;
|
||||
return null;
|
||||
}
|
||||
|
||||
public XmlTagChild getNextSiblingInTag() {
|
||||
PsiElement nextSibling = getNextSibling();
|
||||
if(nextSibling instanceof XmlTagChild) return (XmlTagChild)nextSibling;
|
||||
if (nextSibling instanceof XmlTagChild) return (XmlTagChild)nextSibling;
|
||||
return null;
|
||||
}
|
||||
|
||||
public XmlTagChild getPrevSiblingInTag() {
|
||||
PsiElement prevSibling = getPrevSibling();
|
||||
if(prevSibling instanceof XmlTagChild) return (XmlTagChild)prevSibling;
|
||||
if (prevSibling instanceof XmlTagChild) return (XmlTagChild)prevSibling;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -400,85 +417,96 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
//ChameleonTransforming.transformChildren(this);
|
||||
TreeElement firstAppended = null;
|
||||
boolean before = beforeB != null ? beforeB.booleanValue() : true;
|
||||
try{
|
||||
try {
|
||||
do {
|
||||
if (firstAppended == null) {
|
||||
firstAppended = addInternal(first, anchor, before);
|
||||
anchor = firstAppended;
|
||||
}
|
||||
else anchor = addInternal(first, anchor, false);
|
||||
else {
|
||||
anchor = addInternal(first, anchor, false);
|
||||
}
|
||||
}
|
||||
while (first != last && (first = first.getTreeNext()) != null);
|
||||
}
|
||||
catch(IncorrectOperationException ioe){}
|
||||
catch (IncorrectOperationException ioe) {
|
||||
}
|
||||
return firstAppended;
|
||||
}
|
||||
|
||||
public TreeElement addInternal(final TreeElement child, final ASTNode anchor, final boolean before) throws IncorrectOperationException{
|
||||
public TreeElement addInternal(final TreeElement child, final ASTNode anchor, final boolean before) throws IncorrectOperationException {
|
||||
final PomModel model = getProject().getModel();
|
||||
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
|
||||
final TreeElement[] retHolder = new TreeElement[1];
|
||||
if (child.getElementType() == XmlElementType.XML_TEXT) {
|
||||
if(child.getTextLength() == 0) return this;
|
||||
if (child.getTextLength() == 0) return this;
|
||||
final XmlTextImpl text = (XmlTextImpl)child;
|
||||
model.runTransaction(new PomTransaction() {
|
||||
public PomModelEvent run(){
|
||||
final String oldText = getText();
|
||||
ASTNode childBefore = (anchor != null ? (before ? anchor.getTreePrev() : anchor) : getLastChildNode());
|
||||
if(childBefore != null && childBefore.getElementType() == text.getFirstChildNode().getElementType()){
|
||||
final LeafElement newText = mergeElements((LeafElement)childBefore, (LeafElement)text.getFirstChildNode(), SharedImplUtil.findCharTableByTree(XmlTextImpl.this));
|
||||
if(newText != null){
|
||||
replaceChildInternal(childBefore, newText);
|
||||
if(text.getLastChildNode() != text.getFirstChildNode()){
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode().getTreeNext(), null, anchor, before);
|
||||
}
|
||||
} else {
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode(), null, anchor, before);
|
||||
}
|
||||
}
|
||||
else{
|
||||
ASTNode childAfter = (anchor != null ? (before ? anchor : anchor.getTreeNext()) : getLastChildNode());
|
||||
if(childAfter != null && childAfter.getElementType() == text.getFirstChildNode().getElementType()){
|
||||
final LeafElement newText = mergeElements((LeafElement)text.getFirstChildNode(), (LeafElement)childAfter, SharedImplUtil.findCharTableByTree(XmlTextImpl.this));
|
||||
if(newText != null){
|
||||
replaceChildInternal(childAfter, newText);
|
||||
if(text.getLastChildNode() != text.getFirstChildNode()){
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode().getTreeNext(), null, anchor, before);
|
||||
}
|
||||
} else {
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode(), null, anchor, before);
|
||||
}
|
||||
}
|
||||
public PomModelEvent run() {
|
||||
final String oldText = getText();
|
||||
ASTNode childBefore = (anchor != null ? (before ? anchor.getTreePrev() : anchor) : getLastChildNode());
|
||||
if (childBefore != null && childBefore.getElementType() == text.getFirstChildNode().getElementType()) {
|
||||
final LeafElement newText =
|
||||
mergeElements((LeafElement)childBefore, (LeafElement)text.getFirstChildNode(),
|
||||
SharedImplUtil.findCharTableByTree(XmlTextImpl.this));
|
||||
if (newText != null) {
|
||||
replaceChildInternal(childBefore, newText);
|
||||
if (text.getLastChildNode() != text.getFirstChildNode()) {
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode().getTreeNext(), null, anchor,
|
||||
before);
|
||||
}
|
||||
}
|
||||
else {
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode(), null, anchor, before);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ASTNode childAfter = (anchor != null ? (before ? anchor : anchor.getTreeNext()) : getLastChildNode());
|
||||
if (childAfter != null && childAfter.getElementType() == text.getFirstChildNode().getElementType()) {
|
||||
final LeafElement newText =
|
||||
mergeElements((LeafElement)text.getFirstChildNode(), (LeafElement)childAfter,
|
||||
SharedImplUtil.findCharTableByTree(XmlTextImpl.this));
|
||||
if (newText != null) {
|
||||
replaceChildInternal(childAfter, newText);
|
||||
if (text.getLastChildNode() != text.getFirstChildNode()) {
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode().getTreeNext(), null, anchor,
|
||||
before);
|
||||
}
|
||||
}
|
||||
else {
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode(), null, anchor, before);
|
||||
}
|
||||
}
|
||||
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode(), null, anchor, before);
|
||||
}
|
||||
addChildren(XmlTextImpl.this, (TreeElement)text.getFirstChildNode(), null, anchor, before);
|
||||
}
|
||||
|
||||
retHolder[0] = XmlTextImpl.this;
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
retHolder[0] = XmlTextImpl.this;
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
model.runTransaction(new PomTransaction() {
|
||||
public PomModelEvent run() {
|
||||
final String oldText = getText();
|
||||
final TreeElement treeElement = addChildren(XmlTextImpl.this, child, child.getTreeNext(), anchor, before);
|
||||
retHolder[0] = treeElement;
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
public PomModelEvent run() {
|
||||
final String oldText = getText();
|
||||
final TreeElement treeElement = addChildren(XmlTextImpl.this, child, child.getTreeNext(), anchor, before);
|
||||
retHolder[0] = treeElement;
|
||||
return XmlTextChanged.createXmlTextChanged(model, XmlTextImpl.this, oldText);
|
||||
}
|
||||
}, aspect);
|
||||
}
|
||||
return retHolder[0];
|
||||
}
|
||||
|
||||
private LeafElement mergeElements(final LeafElement one, LeafElement two, CharTable table) {
|
||||
if(one == null || two == null || one.getElementType() != two.getElementType()) return null;
|
||||
if(one.getElementType() == XmlTokenType.XML_DATA_CHARACTERS){
|
||||
if (one == null || two == null || one.getElementType() != two.getElementType()) return null;
|
||||
if (one.getElementType() == XmlTokenType.XML_DATA_CHARACTERS) {
|
||||
final char[] buffer = new char[one.getTextLength() + two.getTextLength()];
|
||||
two.copyTo(buffer, one.copyTo(buffer, 0));
|
||||
return Factory.createSingleLeafElement(one.getElementType(), buffer, 0, buffer.length, table, null);
|
||||
}
|
||||
else if(one.getElementType() == XmlTokenType.XML_WHITE_SPACE){
|
||||
else if (one.getElementType() == XmlTokenType.XML_WHITE_SPACE) {
|
||||
return (LeafElement)ChangeUtil.copyElement(two, SharedImplUtil.findCharTableByTree(this));
|
||||
//final LeafElement prevLeaf = ParseUtil.prevLeaf(one, null);
|
||||
//final LeafElement nextLeaf = ParseUtil.nextLeaf(two, null);
|
||||
@@ -502,14 +530,14 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
}
|
||||
|
||||
private static TreeElement addChildren(final XmlTextImpl xmlText,
|
||||
final TreeElement firstChild,
|
||||
final ASTNode lastChild,
|
||||
final ASTNode anchor,
|
||||
final boolean isBefore) {
|
||||
if(isBefore){
|
||||
final TreeElement firstChild,
|
||||
final ASTNode lastChild,
|
||||
final ASTNode anchor,
|
||||
final boolean isBefore) {
|
||||
if (isBefore) {
|
||||
xmlText.addChildren(firstChild, lastChild, anchor);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
xmlText.addChildren(firstChild, lastChild, anchor.getTreeNext());
|
||||
}
|
||||
return firstChild;
|
||||
@@ -518,52 +546,54 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
public static final int CDATA_ON_TEXT = 0;
|
||||
public static final int ENCODE_SYMS = 1;
|
||||
|
||||
public static ASTNode createElementsByDisplayText(String displayText, int policy){
|
||||
if(!toCode(displayText))
|
||||
public static ASTNode createElementsByDisplayText(String displayText, int policy) {
|
||||
if (!toCode(displayText)) {
|
||||
return Factory.createSingleLeafElement(
|
||||
XmlTokenType.XML_DATA_CHARACTERS,
|
||||
displayText.toCharArray(),
|
||||
0,
|
||||
displayText.length(),
|
||||
null, null);
|
||||
}
|
||||
final FileElement dummyParent = new DummyHolder(null, null).getTreeElement();
|
||||
if (policy == CDATA_ON_TEXT) {
|
||||
TreeUtil.addChildren(
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_CDATA_START,
|
||||
"<![CDATA[".toCharArray(),
|
||||
0, 9, -1,
|
||||
dummyParent.getCharTable()));
|
||||
TreeUtil.addChildren(
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_DATA_CHARACTERS,
|
||||
displayText.toCharArray(),
|
||||
0,
|
||||
displayText.length(),
|
||||
null, null);
|
||||
final FileElement dummyParent = new DummyHolder(null, null).getTreeElement();
|
||||
if(policy == CDATA_ON_TEXT) {
|
||||
0, displayText.length(), -1,
|
||||
dummyParent.getCharTable()));
|
||||
TreeUtil.addChildren(
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_CDATA_START,
|
||||
"<![CDATA[".toCharArray(),
|
||||
0, 9, -1,
|
||||
dummyParent.getCharTable()));
|
||||
TreeUtil.addChildren(
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_DATA_CHARACTERS,
|
||||
displayText.toCharArray(),
|
||||
0, displayText.length(), -1,
|
||||
dummyParent.getCharTable()));
|
||||
TreeUtil.addChildren(
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_CDATA_END,
|
||||
"]]>".toCharArray(),
|
||||
0, 3, -1,
|
||||
dummyParent.getCharTable()));
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_CDATA_END,
|
||||
"]]>".toCharArray(),
|
||||
0, 3, -1,
|
||||
dummyParent.getCharTable()));
|
||||
}
|
||||
else if(policy == ENCODE_SYMS){
|
||||
else if (policy == ENCODE_SYMS) {
|
||||
int sectionStartOffset = 0;
|
||||
int offset = 0;
|
||||
while(offset < displayText.length()){
|
||||
if(toCode(displayText.charAt(offset))){
|
||||
while (offset < displayText.length()) {
|
||||
if (toCode(displayText.charAt(offset))) {
|
||||
final String plainSection = displayText.substring(sectionStartOffset, offset);
|
||||
if(plainSection.length() > 0)
|
||||
if (plainSection.length() > 0) {
|
||||
TreeUtil.addChildren(
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_DATA_CHARACTERS,
|
||||
plainSection.toCharArray(),
|
||||
0, plainSection.length(), -1,
|
||||
dummyParent.getCharTable()));
|
||||
dummyParent,
|
||||
Factory.createLeafElement(
|
||||
XmlTokenType.XML_DATA_CHARACTERS,
|
||||
plainSection.toCharArray(),
|
||||
0, plainSection.length(), -1,
|
||||
dummyParent.getCharTable()));
|
||||
}
|
||||
TreeUtil.addChildren(dummyParent, createCharEntity(displayText.charAt(offset), dummyParent.getCharTable()));
|
||||
}
|
||||
}
|
||||
@@ -573,38 +603,38 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText{
|
||||
}
|
||||
|
||||
private static TreeElement createCharEntity(char ch, CharTable charTable) {
|
||||
switch(ch){
|
||||
case '<':
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
"<".toCharArray(),
|
||||
0, 4, -1,
|
||||
charTable);
|
||||
case '>':
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
">".toCharArray(),
|
||||
0, 4, -1,
|
||||
charTable);
|
||||
case '&':
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
"&".toCharArray(),
|
||||
0, 5, -1,
|
||||
charTable);
|
||||
default:
|
||||
final String charEncoding = "&#" + (int) ch + ";";
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
charEncoding.toCharArray(),
|
||||
0, charEncoding.length(), -1,
|
||||
charTable);
|
||||
switch (ch) {
|
||||
case '<':
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
"<".toCharArray(),
|
||||
0, 4, -1,
|
||||
charTable);
|
||||
case '>':
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
">".toCharArray(),
|
||||
0, 4, -1,
|
||||
charTable);
|
||||
case '&':
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
"&".toCharArray(),
|
||||
0, 5, -1,
|
||||
charTable);
|
||||
default:
|
||||
final String charEncoding = "&#" + (int)ch + ";";
|
||||
return Factory.createLeafElement(
|
||||
XmlTokenType.XML_CHAR_ENTITY_REF,
|
||||
charEncoding.toCharArray(),
|
||||
0, charEncoding.length(), -1,
|
||||
charTable);
|
||||
}
|
||||
}
|
||||
|
||||
public static final boolean toCode(String str){
|
||||
for(int i = 0; i < str.length(); i++){
|
||||
if(toCode(str.charAt(i))) return true;
|
||||
public static final boolean toCode(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (toCode(str.charAt(i))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user