Changeset 1211

Show
Ignore:
Timestamp:
07/06/08 13:48:28 (2 months ago)
Author:
asterite
Message:

Fixed a bunch of bugs. Now ddoc macro proposals are nicer, you get linked positions for parameters :-)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/internal/codeassist/EvaluationResult.java

    r1198 r1211  
    3131                if (i != 0) { 
    3232                    sb.append(", "); 
     33                    if (results[i].getKind() == IEvaluationResult.ARRAY) { 
     34                        sb.append("\n  "); 
     35                    } 
    3336                } 
    3437                sb.append(results[i]); 
  • trunk/descent.core/src/descent/internal/compiler/lookup/LazyAggregateDeclaration.java

    r1207 r1211  
    4848                } 
    4949                 
    50                 if (result.hasMixinDeclaration || result.hasStaticIf) { 
     50                if (result.hasMixinDeclaration || result.hasStaticIf || result.hasAnon) { 
    5151                    cancelLazyness = true; 
    5252                    lazy.members(new Dsymbols()); 
  • trunk/descent.core/src/descent/internal/compiler/lookup/ModuleBuilder.java

    r1203 r1211  
    806806        public boolean hasStaticIf; 
    807807        public boolean hasMixinDeclaration; 
     808        public boolean hasAnon; 
    808809    } 
    809810     
     
    905906                        // Anonymous: it must be an enum, at the top level there 
    906907                        // isn't a use for an annonymous class, template, etc. 
    907                         IType type = (IType) child; 
    908                         if (type.isEnum()) { 
    909                             Dsymbol sym = fillEnum(lazy.getModule(), symbols, type); 
    910                             sym.addMember(lazy.getSemanticScope(), lazy.asScopeDsymbol(), 0, context); 
    911                             lazy.runMissingSemantic(sym, context); 
    912                             result.hasAnonEnum = true; 
     908                        if (child instanceof IType) { 
     909                            IType type = (IType) child; 
     910                            if (type.isEnum()) { 
     911                                Dsymbol sym = fillEnum(lazy.getModule(), symbols, type); 
     912                                sym.addMember(lazy.getSemanticScope(), lazy.asScopeDsymbol(), 0, context); 
     913                                lazy.runMissingSemantic(sym, context); 
     914                                result.hasAnonEnum = true; 
     915                            } else { 
     916                                result.hasAnon = true; 
     917                            } 
     918                        } else { 
     919                            result.hasAnon = true; 
    913920                        } 
    914921                    } else { 
  • trunk/descent.core/src/descent/internal/compiler/parser/AssignExp.java

    r1201 r1211  
    189189            e = new CallExp(loc, e1, e2); 
    190190            e = e.semantic(sc, context); 
     191             
     192            if (e instanceof CallExp) { 
     193                CallExp callExp = (CallExp) e; 
     194                if (callExp.e1 instanceof DotVarExp) { 
     195                    DotVarExp dve = (DotVarExp) callExp.e1; 
     196                    sourceE1.setResolvedSymbol(dve.var); 
     197                } else if (callExp.e1 instanceof VarExp) { 
     198                    VarExp dve = (VarExp) callExp.e1; 
     199                    sourceE1.setResolvedSymbol(dve.var); 
     200                } 
     201            } 
     202             
    191203            return e; 
    192204        } 
  • trunk/descent.core/src/descent/internal/formatter/CodeFormatterVisitor.java

    r1198 r1211  
    29732973    { 
    29742974        int statementsLength = statements.size(); 
    2975         if (statementsLength == 0) 
     2975        if (statementsLength == 0) { 
     2976            scribe.printComment(); 
    29762977            return; 
     2978        } 
    29772979        else if (statementsLength == 1) { 
    29782980            if (statements.get(0) instanceof BreakStatement && unIndentAtBreak) 
  • trunk/descent.ui/src/descent/internal/ui/text/java/DdocMacroCompletionProposal.java

    r891 r1211  
    11package descent.internal.ui.text.java; 
    22 
     3import org.eclipse.jface.dialogs.MessageDialog; 
     4import org.eclipse.jface.text.BadLocationException; 
    35import org.eclipse.jface.text.DefaultInformationControl; 
     6import org.eclipse.jface.text.IDocument; 
    47import org.eclipse.jface.text.IInformationControl; 
    58import org.eclipse.jface.text.IInformationControlCreator; 
     9import org.eclipse.jface.text.IRegion; 
    610import org.eclipse.jface.text.ITextViewer; 
     11import org.eclipse.jface.text.link.LinkedModeModel; 
     12import org.eclipse.jface.text.link.LinkedModeUI; 
     13import org.eclipse.jface.text.link.LinkedPosition; 
     14import org.eclipse.jface.text.link.LinkedPositionGroup; 
    715import org.eclipse.swt.SWT; 
     16import org.eclipse.swt.graphics.Point; 
    817import org.eclipse.swt.widgets.Shell; 
     18import org.eclipse.ui.IEditorPart; 
     19import org.eclipse.ui.texteditor.link.EditorLinkedModeUI; 
    920 
    1021import descent.core.CompletionProposal; 
     22import descent.internal.ui.JavaPlugin; 
     23import descent.internal.ui.javaeditor.EditorHighlightingSynchronizer; 
     24import descent.internal.ui.javaeditor.JavaEditor; 
    1125import descent.internal.ui.text.TextPresenter; 
    1226import descent.internal.ui.text.java.hover.AbstractReusableInformationControlCreator; 
     
    1428 
    1529public class DdocMacroCompletionProposal extends LazyJavaCompletionProposal { 
     30     
     31    private int fMaxNumberOfParameters; 
     32    private boolean fParametersHasPlus; 
     33    private boolean fParametersHasZero; 
     34    private boolean fParametersComputed; 
     35    private int[] fParameterOffsets; 
     36     
     37    private IRegion fSelectedRegion; // initialized by apply() 
    1638 
    1739    public DdocMacroCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) { 
     
    2042     
    2143    @Override 
     44    public void apply(IDocument document, char trigger, int offset) { 
     45        super.apply(document, trigger, offset); 
     46         
     47        int baseOffset= getReplacementOffset(); 
     48        String replacement= getReplacementString(); 
     49         
     50        if (hasParameters()) { 
     51            try { 
     52                LinkedModeModel model= new LinkedModeModel(); 
     53                for (int i= 0; i != fParameterOffsets.length; i++) { 
     54                    LinkedPositionGroup group= new LinkedPositionGroup(); 
     55                    group.addPosition(new LinkedPosition(document, baseOffset + fParameterOffsets[i], 2, LinkedPositionGroup.NO_STOP)); 
     56                    model.addGroup(group); 
     57                } 
     58 
     59                model.forceInstall(); 
     60                JavaEditor editor= getJavaEditor(); 
     61                if (editor != null) { 
     62                    model.addLinkingListener(new EditorHighlightingSynchronizer(editor)); 
     63                } 
     64 
     65                LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer()); 
     66                ui.setExitPosition(getTextViewer(), baseOffset + replacement.length(), 0, Integer.MAX_VALUE); 
     67                ui.setExitPolicy(new ExitPolicy(')', document)); 
     68                ui.setDoContextInfo(true); 
     69                ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT); 
     70                ui.enter(); 
     71 
     72                fSelectedRegion= ui.getSelectedRegion(); 
     73 
     74            } catch (BadLocationException e) { 
     75                JavaPlugin.log(e); 
     76                openErrorDialog(e); 
     77            } 
     78        } 
     79    } 
     80     
     81    @Override 
    2282    protected String computeReplacementString() { 
     83        String str = super.computeReplacementString(); 
     84        if (str.length() > 0 && str.charAt(0) == '$') { 
     85            computeParameters(); 
     86             
     87            StringBuilder sb = new StringBuilder(); 
     88            sb.append('$'); 
     89            sb.append('('); 
     90            sb.append(str.substring(1)); 
     91             
     92            if (hasParameters()) { 
     93                // If we have parameters, don't care about $0  
     94                if (fMaxNumberOfParameters > 0) { 
     95                    // If it's $1 $+, we want two positions 
     96                    if (fParametersHasPlus && fMaxNumberOfParameters == 1) { 
     97                        fParameterOffsets = new int[2]; 
     98                        sb.append(' '); 
     99                        fParameterOffsets[0] = sb.length(); 
     100                        sb.append('$'); 
     101                        sb.append('1'); 
     102                        sb.append(','); 
     103                        sb.append(' '); 
     104                        fParameterOffsets[1] = sb.length(); 
     105                        sb.append('$'); 
     106                        sb.append('+'); 
     107                    } else { 
     108                        fParameterOffsets = new int[fMaxNumberOfParameters];                 
     109                        sb.append(' '); 
     110                        for (int i = 1; i <= fMaxNumberOfParameters; i++) { 
     111                            if (i != 1) { 
     112                                sb.append(','); 
     113                                sb.append(' '); 
     114                            } 
     115                            fParameterOffsets[i - 1] = sb.length(); 
     116                            sb.append('$'); 
     117                            sb.append(i); 
     118                        } 
     119                    } 
     120                } else { 
     121                    // Just $0 
     122                    fParameterOffsets = new int[1]; 
     123                    sb.append(' '); 
     124                    fParameterOffsets[0] = sb.length(); 
     125                    sb.append('$'); 
     126                    sb.append('0'); 
     127                } 
     128            } 
     129             
     130            sb.append(')'); 
     131            return sb.toString(); 
     132        } 
    23133        return super.computeReplacementString() + "()"; //$NON-NLS-1$ 
    24134    } 
    25135     
     136    private boolean hasParameters() { 
     137        computeParameters(); 
     138        return fMaxNumberOfParameters != 0 || fParametersHasPlus || fParametersHasZero; 
     139    } 
     140     
     141    private void computeParameters() { 
     142        if (fParametersComputed) { 
     143            return; 
     144        } 
     145        fParametersComputed = true; 
     146         
     147        fMaxNumberOfParameters = 0; 
     148        char[] completion = fProposal.getName(); 
     149        for (int i = 0; i < completion.length; i++) { 
     150            char c = completion[i]; 
     151            if (c == '$' && i < completion.length - 1) { 
     152                i++; 
     153                c = completion[i]; 
     154                int val = c - '0'; 
     155                if (val == 0) { 
     156                    fParametersHasZero = true; 
     157                } else if (val > 0 && val <= 9) { 
     158                    if (val > fMaxNumberOfParameters) { 
     159                        fMaxNumberOfParameters = val; 
     160                    } 
     161                } else if (c == '+') { 
     162                    fParametersHasPlus = true; 
     163                } 
     164            } 
     165        } 
     166    } 
     167 
     168    private boolean containsPlaceholders(String completion) { 
     169        return completion.matches(".*\\$(\\d).*"); 
     170    } 
     171 
    26172    @Override 
    27173    public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { 
     
    38184        };  
    39185    } 
     186     
     187    /** 
     188     * Returns the currently active java editor, or <code>null</code> if it 
     189     * cannot be determined. 
     190     * 
     191     * @return  the currently active java editor, or <code>null</code> 
     192     */ 
     193    private JavaEditor getJavaEditor() { 
     194        IEditorPart part= JavaPlugin.getActivePage().getActiveEditor(); 
     195        if (part instanceof JavaEditor) 
     196            return (JavaEditor) part; 
     197        else 
     198            return null; 
     199    } 
     200     
     201    private void openErrorDialog(BadLocationException e) { 
     202        Shell shell= getTextViewer().getTextWidget().getShell(); 
     203        MessageDialog.openError(shell, JavaTextMessages.ExperimentalProposal_error_msg, e.getMessage()); 
     204    } 
     205     
     206    @Override 
     207    public Point getSelection(IDocument document) { 
     208        if (fSelectedRegion == null) 
     209            return new Point(getReplacementOffset(), 0); 
     210 
     211        return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength()); 
     212    } 
    40213 
    41214} 
  • trunk/descent.ui/src/descent/internal/ui/text/java/SmartSemicolonAutoEditStrategy.java

    r210 r1211  
    280280        } else if (character == SEMICHAR) { 
    281281 
    282             if (isForStatement(text, offset)) { 
    283                 insertPos= -1; // don't do anything in for statements, as semis are vital part of these 
     282            if (isForStatement(text, offset) || isForeachStatement(text, offset)) { 
     283                insertPos= -1; // don't do anything in for or foreach statements, as semis are vital part of these 
    284284            } else { 
    285285                int nextPartitionPos= nextPartitionOrLineEnd(document, line, offset, partitioning); 
     
    10041004        return false; 
    10051005    } 
     1006     
     1007    /** 
     1008     * Determines whether the current line contains a for statement. 
     1009     * Algorithm: any "for" word in the line is a positive, "for" contained in a string literal will 
     1010     * produce a false positive. 
     1011     * 
     1012     * @param line the line where the change is being made 
     1013     * @param offset the position of the caret 
     1014     * @return <code>true</code> if <code>line</code> contains <code>for</code>, <code>false</code> otherwise 
     1015     */ 
     1016    private static boolean isForeachStatement(String line, int offset) { 
     1017        /* searching for (^|\s)foreach(\s|$) */ 
     1018        int forPos= line.indexOf("foreach"); //$NON-NLS-1$ 
     1019        if (forPos != -1) { 
     1020            if ((forPos == 0 || !Character.isJavaIdentifierPart(line.charAt(forPos - 1))) && (line.length() == forPos + 7 || !Character.isJavaIdentifierPart(line.charAt(forPos + 7)))) 
     1021                return true; 
     1022        } 
     1023        return false; 
     1024    } 
    10061025 
    10071026    /** 
  • trunk/descent.ui/src/descent/internal/ui/text/template/contentassist/TemplateProposal.java

    r212 r1211  
    249249            fSelectedRegion= fRegion; 
    250250        } 
    251  
     251         
    252252    } 
    253253