mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
[IDEA][xtend] Provided support for brace pairs matching
Change-Id: Icef7d4a31e95ea8094f96fe2c62027a628a21744 Signed-off-by: akosyakov <anton.kosyakov@itemis.de>
This commit is contained in:
parent
8562203200
commit
0325dff423
5 changed files with 124 additions and 0 deletions
|
@ -17,6 +17,13 @@ Export-Package: org.eclipse.xtext.ide;
|
|||
org.eclipse.emf.mwe2.language.ui,
|
||||
org.eclipse.xtext.xtext.ui,
|
||||
org.eclipse.xtend.ide.common",
|
||||
org.eclipse.xtext.ide.editor.bracketmatching;
|
||||
x-friends:="org.eclipse.xtext.ui,
|
||||
org.eclipse.xtext.xbase.ui,
|
||||
org.eclipse.xtend.ide,
|
||||
org.eclipse.emf.mwe2.language.ui,
|
||||
org.eclipse.xtext.xtext.ui,
|
||||
org.eclipse.xtend.ide.common",
|
||||
org.eclipse.xtext.ide.editor.contentassist;
|
||||
x-friends:="org.eclipse.xtext.ui,
|
||||
org.eclipse.xtext.xbase.ui,
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.bracketmatching
|
||||
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
|
||||
/**
|
||||
* Defines a single pair of braces which need to be matched when editing code.
|
||||
*
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@Data
|
||||
class BracePair {
|
||||
/**
|
||||
* The length of a left brace should be one character for Eclipse.
|
||||
*/
|
||||
val String leftBrace
|
||||
/**
|
||||
* The length of a right brace should be one character for Eclipse.
|
||||
*/
|
||||
val String rightBrace
|
||||
/**
|
||||
* True if the brace is structural. Structural braces have higher priority than regular braces:
|
||||
* they are matched with each other even if there are unmatched braces of other types between them,
|
||||
* and an opening non-structural brace is not matched with a closing one if one of them is outside a pair
|
||||
* of matched structural braces and another is outside. In Java code, the curly braces are structural.
|
||||
*
|
||||
* It is ignored by Eclipse.
|
||||
*/
|
||||
val boolean structural
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.bracketmatching
|
||||
|
||||
import java.util.Set
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@Accessors
|
||||
@FinalFieldsConstructor
|
||||
class DefaultBracePairProvider implements IBracePairProvider {
|
||||
|
||||
val Set<BracePair> pairs
|
||||
|
||||
new() {
|
||||
this(#{
|
||||
new BracePair("(", ")", false),
|
||||
new BracePair("{", "}", true),
|
||||
new BracePair("[", "]", false)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.bracketmatching
|
||||
|
||||
import java.util.Set
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Provides a set of definitions for brace pairs that need to be matched when
|
||||
* editing code.
|
||||
* </p>
|
||||
*
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
interface IBracePairProvider {
|
||||
|
||||
/**
|
||||
* Returns a set of definitions for brace pairs that need to be matched when
|
||||
* editing code.
|
||||
*/
|
||||
def Set<BracePair> getPairs()
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.bracketmatching
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
class XtextBracePairProvider extends DefaultBracePairProvider {
|
||||
new() {
|
||||
super(#{
|
||||
new BracePair(":", ";", true),
|
||||
new BracePair("(", ")", false),
|
||||
new BracePair("{", "}", true),
|
||||
new BracePair("[", "]", false)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue